问题
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