: External link tracking when opening the link in a new window in Google Analytics? OK, so this seems like a really simply problem, but I have yet to find a solution that accomplishes the following:
OK, so this seems like a really simply problem, but I have yet to find a solution that accomplishes the following:
Opens the link in a new window
Tracks the event in GA (obviously)
Doesn't trigger pop-up blockers (uses target="_blank" instead of window.open)
Most of the code I've seen, including Google's, doesn't take into account the case of opening in a new window - they just window location.href.
Even GAAddons (http://gaaddons.com/), which charges for commercial use, doesn't seem to work for me.
Perhaps, I'm missing something simple - I'd be relieved if so and would thank profusely whoever points it out to me!
If no one is able to provide an example, I'll post some of the test cases I've created to illustrate the problem.
Thanks.
More posts by @Jamie184
3 Comments
Sorted by latest first Latest Oldest Best
This is my favourite script for tracking outgoing links and opening in a new window. This is for the async version of GA.
It uses jQuery for convenience, and has a few 'not' classes that you can use as overrides.
<script type="text/javascript">
$(document).ready(function(){
$('a:not(.popupwindow)').filter(function() {
var theHref = this;
if (theHref.hostname && theHref.hostname !== location.hostname) {
$(theHref).not(".noAutoIcon").addClass("offSite");
$(theHref).not(".noAutoLink").attr('target','_blank').bind('click keypress', function(event) {
var code=event.charCode || event.keyCode;
if (!code || (code && code == 13)) {
var fixedLink = this.href;
fixedLink = fixedLink.replace(/https?://(.*)/,"");
fixedLink = '/outgoing/' + fixedLink;
_gaq.push(['_trackPageview', fixedLink]);
};
});
};
});
});
</script>
Originally from here, I think:
iso-100.com/blog/post/updated-script-for-tracking-outbound-links-in-google-analytics-with-jquery/
you can track events with google code.
put this code in your head
<script>
function recordOutboundLink(link, category, action) {
_gat._getTrackerByName()._trackEvent(category, action);
}
</script>
then you could do as Hissohathair says above and put the onClick in every link
`<a href="/path/to/page" target="_blank" onClick="javascript: recordOutboundLink(this, 'entercategoryname', 'enternameofaction');">`
then in your google analytics goto "content > Event tracking"
you can also use javascript to add this automatically instead of adding to each link
(I wrote a wordpress plugin that had this feature)
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.