Mobile app version of vmapp.org
Login or Join
Jamie184

: 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:

@Jamie184

Posted in: #GoogleAnalytics

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.

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Jamie184

3 Comments

Sorted by latest first Latest Oldest Best

 

@Cooney921

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/

10% popularity Vote Up Vote Down


 

@Annie201

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)

10% popularity Vote Up Vote Down


 

@Cofer257

I might have misunderstood... does this not work?

<a href="/path/to/page" target="_blank" onClick="javascript: pageTracker._trackPageview('/path/to/page');">

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme