Created
March 27, 2013 13:00
-
-
Save anova/5253988 to your computer and use it in GitHub Desktop.
From stackoverflow subject : http://stackoverflow.com/questions/12302300/track-all-outbound-links-in-google-analytics/14787172#14787172
Editing for new analytics _gaq variable.
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
(function($) { | |
$(function(){ | |
$("a").on('click',function(e){ | |
var url = $(this).attr("href"); | |
if (e.currentTarget.host != window.location.host) { | |
if(typeof _gaq != 'undefined') { | |
//var track_label = e.currentTarget.host.replace(':80','') + url; | |
var track_label = url; | |
if($(this).attr('rel') && $(this).attr('rel').length > 0) { | |
track_label += '(' + $(this).attr('rel') + ')'; | |
} | |
_gaq.push(['_trackEvent','Reklam', track_label]); | |
} | |
if (e.metaKey || e.ctrlKey || ($(this).attr('target') && '_blank' === $(this).attr('target'))) { | |
var newtab = true; | |
} | |
if (!newtab) { | |
e.preventDefault(); | |
setTimeout('document.location = "' + url + '"', 100); | |
} | |
} | |
}); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment