Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
GTM code to open external links in a new tab. Learn more at http://rickrduncan.com/pro/analytics/open-external-links-new-tab-gtm.
<script>
var links = document.links;
for (var i = 0, linksLength = links.length; i < linksLength; i++) {
if (links[i].hostname != window.location.hostname) {
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