开发者

Tracking clicks using google analytics

I am using Google analytic on my web site.I have the following script in the head section of my page -

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-17301453-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

i am using the following method to track the number of clicks -

<a href="http://buzzr.in" onClick="_gaq.push(['_trackPageview', '/testbrand1/testcamp2/http://buzzr.in']);">Grab This Deal</a>

But the google anayltics website does not seem to be reporting any events/cl开发者_如何转开发icks. Please help.


When debugging you may like to either use the Firefox Live HTTP Headers plug-in or Wireshark. These will tell you about requests to Google Analytics.

Depending on the browser and the way the site loads it may be worth using the onload handler of the page to call the Google Anayltics code (with async set to false in the GA snippet) and dynamically assign the onclick event (an id on the tag will help find it). This will ensure the code can run at the appropriate time.

The link may be processed before the tracking event is sent to Google Analytics as you do not return false to the onclick event. AFAIK there is no callback on GA events to let you know when to proceed with the next page.

In short this looks like a race condition between an async GA request and the browser finding the linked site.

The only way to have this functionality would be to use an iframe or new window for the link's target.


does it work if you do this?

<a href="#" onClick="_gaq.push(['_trackPageview', '/testbrand1/testcamp2/http://buzzr.in']);">Grab This Deal</a>

If so, you may need to put something in to wait for the google tracking code to complete before allowing the browser to navigate away.


have you tried adding return true; to the end..

<a href="http://buzzr.in" onClick="_gaq.push(['_trackPageview','/testbrand1/testcamp2/http://buzzr.in']);return true;">Grab This Deal</a>

Dunno if it will help, just a suggestion.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜