I was looking for various Javascript snippets to track Google Analytics events. I am using Google Tag Manager. This question is also similar to some questions I posted recently, so I apologize for the smaller pool of users who follow the google analytics tag and see the same thing.
I am currently working with this snippet:
<script type="text/javascript"> $(document).ready(function(){ $('.app-cta a').onClick=_gaq.push(['_trackEvent', 'App', 'Click', 'iOS']); }); </script>
Inside httpfox, all event parameters (App, Click, iOS) are displayed. But not in Google Analytics.
I am told that a fairly common practice is to add a delay to the link, somewhere between 5 and 500 milliseconds. This is because, as I was told, sometimes the browser gets to a new site before it can transfer analytics parameters.
There may be alternative ways to fix this, but for my own curiosity, find out how to use Javascript for analytics, how do I integrate setTimeout into the above code?
I tried this:
<script type="text/javascript"> $(document).ready(function(){ setTimeout(function(){ $('.app-cta a').onClick=_gaq.push(['_trackEvent', 'App', 'Click', 'iOS']); }); },500); </script>
But does this delay the Google Analytics tag from transmitting data, and not delay the click? I checked and this did not solve my problem.