I couldn't find anywhere how to use hitCallback
parameter with google analytics ecommerce:send
. In docs its only example is with send,pageview
.
Here is the code I tried:
ga('ecommerce:send',
{'hitCallback': function() {window.location.href="/test.php";}}
);
but it didn't work although the tracking worked.
As mentioned, hitCallback doesn't work for ecommerce:send. Craziness.
However, what I found (today at least) is that it does work for ecommerce:addTransaction and ecommerce:addItem (for when they are finally sent). Therefor you just have to make sure that all your hitCallbacks from those calls have been hit and then you're safe.
I ran in to the same problem and, having looked at the source code, there's no clean way to do it.
The thing about ga('ecommerce:send')
is that internally it calls -
ga('send', 'transaction', {...})
once for your transaction, thenga('send', 'item', {...})
once for each itemIf you have to wait for your ecommerce:send
to complete you could do one of the following:
ecommerce.js
that allows you to pass in a hitCallback
function, or<img/>
tags to send data if it's less than 2KB. So, you could check every <img/>
tag that is created by JavaScript, and if the src
attribute contains www.google-analytics.com then wait for it to load.I've actually used #2 successfully (see http://jsfiddle.net/zkQXX/), but it really is a hack.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With