开发者

Bug in external link tracking when opening the link in a new window in Google Analytics?

开发者 https://www.devze.com 2023-02-04 01:20 出处:网络
First off, I apologize if it\'s considered poor etiquette to cross-post on stackexchange sites, but this seemed appropriate for both the webmasters site and here, as it\'s a common issue for webmaster

First off, I apologize if it's considered poor etiquette to cross-post on stackexchange sites, but this seemed appropriate for both the webmasters site and here, as it's a common issue for webmaster, but may be able to be solved by coders. In any case, here goes...

OK, so this seems like a really simple problem, but I have yet to find a solution that accom开发者_开发知识库plishes the following:

  • Opens the link in a new window
  • Tracks the event in GA when using the asynchronous code
  • 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 use window location.href.

Even GAAddons (http://gaaddons.com/), which charges for commercial use, seems to not manage opening in new windows properly.

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.

[EDIT] I've since tested the GAAddons code more throughly and have found it to work. I'm guessing the problem that was being reported earlier by a client using Chrome 7 on Windows was more likely a configuration issue than something related to the GAAddons library itself.


You put it in the link's onclick attribute:

<a href="somePage.html" target="_blank" onclick="pageTracker._trackPageview(this.href);">some link</a>


The method I've found to satisfy all the requirements I've mentioned is the one found here: http://cutfromthenorth.com/add-external-link-tracking-with-jquery-and-google-analytics/

It's actually quite simple, leading me to think that there was some other reason why other code wasn't working in earlier tests.

However, I can confirm that the method that's 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 windows trigger popup warning on Chrome and IE).

The Google code does work for tracking external links not opened in a new window.

here's the snippet:

$('a[target=_blank]').click(function(){
try{
    _gaq.push(['_trackEvent', 'External Links', 'Click', $(this).attr('href')]);
} catch(err) {}
return true;
});

I've tested on 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 the native Android browser on Gingerbread

0

精彩评论

暂无评论...
验证码 换一张
取 消