0

I am successfully using the following snippet to add a delay to my Google Analytics event tracking...

<script type="text/javascript">
function trackOutboundLink(form, category, action, label) {
try {
_gaq.push(['_trackEvent', category , action, label]);
} catch(err){}
  setTimeout(function() {
    form.submit();
  }, 100);
}
</script>

This has solved the problems I was experiencing with certain events only tracking randomly. I am know facing similar issue but with my e-commerce analytics.

Is there a similar snippet I can use to add a delay to that as well?

fightstarr20
  • 11,682
  • 40
  • 154
  • 278

1 Answers1

1

You should really use Google Analytics hitCallback function.

So, for example:

<script type="text/javascript">
function trackOutboundLink(form, category, action, label) {
    try {
        _gaq.push(['_set', 'hitCallback', function(){
            form.submit();
        }]);

        _gaq.push(['_trackEvent', category , action, label]);
    } catch(e){} 
}
</script>

*This code is untested, but you should get the idea.

Community
  • 1
  • 1
Blexy
  • 9,573
  • 6
  • 42
  • 55