简体   繁体   English

Google Analytics(分析)上的事件跟踪不起作用?

[英]Event tracking on google analytics not working?

I put the snippet received from google in my head html: 我把从Google收到的代码片段放在我的头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. 要使用通用跟踪来跟踪事件,您需要将ga函数与send命令一起使用。

eg 例如

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

https://developers.google.com/analytics/devguides/collection/analyticsjs/events 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. 看起来您正在使用Universal Analytics页面脚本,但是使用经典代码进行事件跟踪。 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 https://developers.google.com/analytics/devguides/collection/analyticsjs/events

As for your example, try: 对于您的示例,请尝试:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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