Last active
April 25, 2019 09:12
-
-
Save rickrduncan/0958eaf3bda1d2e4afd1ce0202fdf09e to your computer and use it in GitHub Desktop.
GTM code to open external links in a new tab. Learn more at http://rickrduncan.com/pro/analytics/open-external-links-new-tab-gtm.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var links = document.links; | |
for (var i = 0, linksLength = links.length; i < linksLength; i++) { | |
if (links[i].hostname != window.location.hostname && links[i].protocol != 'tel:' && links[i].protocol != 'mailto:' ) { | |
links[i].target = '_blank'; | |
links[i].rel = 'noopener noreferrer'; | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment