google analytics - GA event tracking on link only fires when href='#' -


this ga code:

    <script type="text/javascript">    var _gaq = _gaq || [];   _gaq.push(['_setaccount', 'ua-xxxxxxxx-x']);   _gaq.push(['_trackpageview']);    (function() {     var ga = document.createelement('script'); ga.type = 'text/javascript'; ga.async = true;     ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';     var s = document.getelementsbytagname('script')[0]; s.parentnode.insertbefore(ga, s);   })();  </script> 

this code reports ga event tracking:

<li><a href="#" onclick="_gaq.push(['_trackevent', 'siteqa2', 'click', 'analytics click']);" class="button button-style4 button-big">get started</a></li> 

but code doesn't:

<li><a href="./page2.php?id=5" onclick="_gaq.push(['_trackevent', 'siteqa2', 'click', 'analytics click']);" class="button button-style4 button-big">get started</a></li> 

any idea i'm doing wrong?

it's not ga tracking isn't firing, data isn't being recorded.

_trackevent records data requesting tracking pixel analytics servers. because link visits new page right after _trackevent call, tracking pixel request can canceled, resulting in no data being recorded.

the common pattern add slight delay (150ms works) before following link new page. search "_trackevent delay"


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -