Created
April 3, 2012 06:04
-
-
Save kythin/2289668 to your computer and use it in GitHub Desktop.
Google Analytics - Track link click as action and then open in new window
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
/*********************************************** | |
* JS Google Track and New Window | |
* by Kythin | |
* www.kythin.com | |
* Useage: Simply add an "action" to a link to track it in google analytics. | |
* E.g. <a href='http://www.kythin.com/' action='clicked-kythin'>link</a> | |
* | |
* Requires JQuery | |
***********************************************/ | |
function recordOutboundLink(tlink, category, action) { | |
_gat._getTrackerByName()._trackEvent(category, action); | |
setTimeout(window.open(tlink), 150); | |
} | |
$(document).ready(function(){ | |
$('a').click(function(e){ | |
if ($(this).attr('action')) { | |
e.preventDefault(); | |
recordOutboundLink($(this).attr('href'), 'Click', $(this).attr('action')); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment