Google Analytics tracking code doesn't record downloads in RealTime

﹥>﹥吖頭↗ 提交于 2021-02-11 12:34:49

问题


I have added a snippet of javascript to my pdf download links in order to track downloads. When I watch RealTime Events from the GA dashboard, I don't see any activity when I click on a download link. My links have the following code:

<a class='non-html' href='pdf/XXXX_2017_meeting_program.pdf' onclick=”var that=this;_gaq.push([‘_trackEvent’,’Download’,’PDF’,this.href]);setTimeout(function(){location.href=that.href;},200);return false;”>2017: 18th Annual Symposium, Chicago, IL, USA</a>

Is the link properly formed and am I looking in the correct place to observe event activity in real time?

Follow-Up: OK, I've kept it simple, just the command "event" and 1 parameter, "Download". I still don't see any activity. I have the most current gtag:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src='https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXX-XX'></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-XXXXXXX--XX');
</script>`

and the link codes is as follows:

<a class='non-html' href='pdf/XXXX_2017_meeting_program.pdf'  onclick = 'gtag ('event', 'Download');' >2017: 18th Annual Symposium, Chicago, IL, USA</a>

Do I need to do anything else?


回答1:


Depending on which library you use - analytics.js or gtag.js, correct your code:

onclick ="ga('send', 'event', <category>, <action>, <label>, <value>);"

or

 onclick = "gtag('event', <action>, {'event_category': <category>,'event_label': <label>,'value': <value>});" 

To see event in real time use report Real Time - Events.



来源:https://stackoverflow.com/questions/52048136/google-analytics-tracking-code-doesnt-record-downloads-in-realtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!