javascript - google analytics code working on firefox but not on chrome -
i m new google analytics, bind click event google analytics on click of tag call ga(create ) , ga(send).
but code work in on firefox, not on chrome?
when use same site on firefox gave me result in analytics on chrome not showing result.
thanks in advance. :)
without more information, see hard know issue, things should consider:
1) append click event on document load. prevent errors if element not loaded.
2) create analytics instances after instead of doing on click. creating instance not send data tracked , ensure it's ready when send click event.
3) ensure there no other scripts causing issues. if 1 script faulty execution paused. check console errors.
this seems work me. try code ua , check realtime section on analytics.
// load analytics. (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','https://www.google-analytics.com/analytics.js','ga'); // initialise analytics. ga('create', 'ua-123456789'); // append click options on load. $(document).ready(function(){ $(".dropdownexpansiondiv a.topevent").on("click", function(e) { var nameofevent = $(this).text(); ga('send', 'event', nameofevent, 'click', 'visitor looked ' + nameofevent); console.log('send', 'event', nameofevent, 'click', 'visitor looked ' + nameofevent); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="dropdownexpansiondiv"> <a class="topevent">test</a> </div>
Comments
Post a Comment