简体   繁体   English

Google Analytics 事件未触发

[英]Google Analytics event not firing

My Google Analytics event isn't firing on my webpage.我的 Google Analytics 事件没有在我的网页上触发。 Below is my code.下面是我的代码。 It opens the url in a new tab just fine, and there are no errors in the console.它在新选项卡中打开 url 就好了,并且控制台中没有错误。 But when I go to Google Analytics -> Real-Time -> Events my goal has no activity.但是当我转到 Google Analytics -> Real-Time -> Events 时,我的目标没有任何活动。 It's using Universal Analytics because when I view page source I see analytics.js.它使用 Universal Analytics,因为当我查看页面源时,我看到了 analytics.js。

<a href="https://myurl.com" onclick="ga('send', 'MyEvent', 'Click');" target="_blank">under construction </a></p>

If it helps, my Goal setup is:如果有帮助,我的目标设置是:

Category - MyEvent
Action - Click

Use the Event value as the Goal Value for the conversion - Yes

New version of analytics has a different syntax: Replace this line新版本的分析有不同的语法:替换这一行

ga('send', 'MyEvent', 'Click');

With

gtag('event', 'click', {'event_category' : 'MyEvent', 'event_action' : 'Click', 'event_label' : 'Label is optional'});"

you are missing the hit type property.您缺少命中类型属性。

ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);

Full documentation is here完整文档在这里

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

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