I have the following code. The core of the tracking is just the 4 lines with the _paq. However, I have found that I have had to wrap it with the Matomo.initialized setInterval check for it to track.
This seems counter to the docs that suggest you can push things into _paq and it will just send them when the Tag Manager has loaded the tracking code.
Any ideas how to debug this, or what is going on here?
So for clarity, this on its own does not work:
<script type="text/javascript" id="datalayer">
var _paq = window._paq = window._paq || [];
_paq.push(["addEcommerceItem","PID3","Name",["Group"],"99.99",1]);
_paq.push(["trackEcommerceOrder","1435370443","99.99","99.99","0",0,true]);
_paq.push(["trackEvent","User","CustomerType","existing"]);
</script>
Wrapping it with the check for Matomo being ready and it sends the requests as you would expect:
<script type="text/javascript" id="datalayer">
var mt = setInterval(function () {
if (Matomo.initialized) {
clearInterval(mt);
window.console.log('running tracking additions', Matomo.initialized);
var _paq = window._paq = window._paq || [];
_paq.push(["addEcommerceItem","PID3","Name",["Group"],"99.99",1]);
_paq.push(["trackEcommerceOrder","1435370443","99.99","99.99","0",0,true]);
_paq.push(["trackEvent","User","CustomerType","existing"]);
}
}, 250);
</script>
1 post - 1 participant