javascript - Does this attach a click even to an anchor tag? -
i need add click event anchor google analytics event tracking. have main event tracking code in head section. i've done in head section:
<script type='text/javascript'> window.onload=function() { document.getelementbyid("btn_2_3a4z711fbd39d2fc9634f0yt66b45ht9").addeventlistener("click", "_gaq.push(['_trackevent', 'webinar', 'register', 'webinar-july-15']);"); } </script>
when inspect anchor tag, don't see event there. i'm going off of example: http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_element_addeventlistener. event doesn't show in example either when inspect it.
i don't see event coming through in ga. tried modifying code testing don't see alert:
.addeventlistener("click", "_gaq.push(['_trackevent', 'webinar', 'register', 'webinar-july-15']);alert('popup');");
any ideas i'm doing wrong?
any ideas i'm doing wrong?
yep, you're passing string second argument addeventlistener
when should function.
replace
document.getelementbyid("btn_2_3a4z711fbd39d2fc9634f0yt66b45ht9").addeventlistener("click", "_gaq.push(['_trackevent', 'webinar', 'register', 'webinar-july-15']);");
by
document.getelementbyid("btn_2_3a4z711fbd39d2fc9634f0yt66b45ht9").addeventlistener("click", function() { _gaq.push(['_trackevent', 'webinar', 'register', 'webinar-july-15']); });
Comments
Post a Comment