简体   繁体   中英

Event tracking on google analytics not working?

I put the snippet received from google in my head html:

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-52364389-1', 'auto');
  ga('send', 'pageview');
</script>

Then I put this

onclick="_gaq.push(['_trackEvent', 'Click', 'Button', '/thankyoubutton.html']);"

on a clickable text/button as follows:

<a href="button.html" onclick="_gaq.push(['_trackEvent', 'Click', 'Button', 
'/button.html']);"><short>get yours today</short>< /a>

However, I am only receiving data for the homepage hits but nothing about this click on the button. I have tried waiting for a couple of days and tested around too. The event tracking does not seem to be working. Please help. Thanks a lot.

You are using the new universal tracking but trying to add the event using the old analytics code. To track an event using universal tracking, you need to use the ga function with the send command.

eg

ga('send', 'event', 'button', 'click', 'nav buttons', 4);

https://developers.google.com/analytics/devguides/collection/analyticsjs/events

Looks like you're using the Universal Analytics page script, but event tracking with the classic code. You're going to want to use the new method of tracking which is detailed at:

https://developers.google.com/analytics/devguides/collection/analyticsjs/events

As for your example, try:

onclick="ga('send', 'event', 'Click', 'Button', '/thankyoubutton.html');"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM