javascript - Google Analytics Event Not Working - file download click event added dynamically -


i have added jquery snippet attaches event hrefs open pdf. can see firing event never tracked in analytics

$( document ).ready(function() { //attach event dispatcher links pdf files //register event in analtyics     $('a[href*=".pdf"]').click(function(e) {        ga('send', 'event', 'pdf', 'download', 'digital content', $(this).attr('href'));        console.log($(this).attr('href'));     //console log working each time link clicked    }); }); 

analytics code added in head such

  <script type="text/javascript">     (function(i,s,o,g,r,a,m){i['googleanalyticsobject']=r;i[r]=i[r]||function(){     (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new date();a=s.createelement(o),     m=s.getelementsbytagname(o)[0];a.async=1;a.src=g;m.parentnode.insertbefore(a,m)     })(window,document,'script','//www.google-analytics.com/analytics.js','ga');      ga('create', 'ua-xxxxxx-yy');     ga('send', 'pageview'); </script> 

pdf docs linked:

<a href="http://website.com/50025h966.pdf" target="_blank" class="body_link_11"> http://website.com/50025h966.pdf<span class="icon_11 ui-icon-extlink"></span></a> 

tag manager not option dont control part of site, can add js

one thing notice sending in non-integer value event value (the 6th parameter in ga function). should integer

ga('send', 'event', 'pdf', 'download', 'digital content', 1); 

(cf. https://developers.google.com/analytics/devguides/collection/analyticsjs/events#implementation)


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -