Last active
December 16, 2015 13:28
-
-
Save tehpeh/5441489 to your computer and use it in GitHub Desktop.
Outbound link tracking for Google Analytics using YUI3 (SquareSpace compatible)
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 type="text/javascript"> | |
YUI().use('node', 'io', 'event', function (Y) { | |
// Outbound Link Tracking with Google Analytics | |
// http://wptheming.com/2012/01/tracking-outbound-links-with-google-analytics/ | |
// Modified for YUI3 | |
Y.one(Y.config.doc).delegate('click', function(e) { | |
var url = this.getDOMNode(); | |
if (url.host != window.location.host) { | |
_gaq.push(['_trackEvent', 'Outbound Links', url.host, url.href, 0]); | |
if (e.metaKey || e.ctrlKey || url.target=="_blank" || url.target=="new") { | |
var newtab = true; | |
} | |
if (!newtab) { | |
e.preventDefault(); | |
setTimeout(function() { | |
document.location.href = url.href; | |
}, 100); | |
} | |
} | |
}, 'a'); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment