Error tracking inbound links when opening a link in a new window in Google Analytics?
First of all, I apologize if he thinks bad etiquette is exposed to cross-posting on stack sites, but this seems to be the case for both the webmaster site and it as it is a common problem for the webmaster but can be solved with coders, Anyway, here goes ...
OK, so this seems like a really simple problem, but I have yet to find a solution that does the following:
- Opens a link in a new window
- Tracks an event in GA when using asynchronous code
- Doesn't launch popup blockers (uses target = "_blank" instead of window.open)
Most of the code I've seen, including Google, doesn't account for the case of opening in a new window - they just use window location.href.
Even GAAddons (http://gaaddons.com/), which charges for commercial use, seems to fail to open properly in new windows.
Perhaps I missed something simple - I would be glad if it were, and would thank me for whoever pointed it out to me!
If no one can provide an example, I will post some of the test cases I created to illustrate the problem.
Thank.
[EDIT] I've checked the GAAddons code more since then and found it to work. My guess is that the issue previously reported by a client using Chrome 7 on Windows was more a configuration issue than something related to the GAAddons library itself.
source to share
The method I found to satisfy all the requirements I mentioned is the one found here: http://cutfromthenorth.com/add-external-link-tracking-with-jquery-and-google-analytics/
It's actually quite simple, which made me think there was a different reason why the other code didn't work in earlier tests.
However, I can confirm that the method mentioned in the comments on this Google page - http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55527 - does not meet the above requirements (new window launches pop-up warning in Chrome and IE).
Google code works to keep track of external links not open in a new window.
here's a snippet:
$('a[target=_blank]').click(function(){
try{
_gaq.push(['_trackEvent', 'External Links', 'Click', $(this).attr('href')]);
} catch(err) {}
return true;
});
I tested the following browsers: PC: IE 6 - 9 Firefox 3.6, 4.0 Chrome 9, 10 Safari 5 Opera 11
Mac: Safari 5 Chrome 10 Firefox 3.6, 4.0
Also tested on iPhone 4 and native Android browser on Gingerbread
source to share