GA Event Tracking + onClick="document.location.href='

﹥>﹥吖頭↗ 提交于 2019-12-25 11:25:14

问题


The developer who made a site we're working on has buttons linking to PDF downloads using:

<button onClick="document.location.href='doc.pdf'"> Doc Name </button>

However, we also need to track events for these (we don't want to inflate pageviews with PDF downloads), using:

<button onClick="_gaq.push(['_trackEvent', 'PDFs', 'Download', 'Doc Name']);""> Doc Name </button>

So, the issue is, how can I do GA event tracking without having the two requisite 'onClick's conflicting?

I was thinking about triggering the GA Event with 'onMouseDown,' but this would be less accurate, no?

Many thanks in advance.


回答1:


<button class="download-pdf" onclick="document.location.href='doc.pdf';_gaq.push(['_trackEvent', 'PDFs', 'Download', 'Doc Name']);"> Doc Name </button>


来源:https://stackoverflow.com/questions/17458785/ga-event-tracking-onclick-document-location-href

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