I'm trying to track custom events and pageviews in Google Analytics. When including the GA tracking code (Universal Analytics) directly into my pages, events fire normally. However when including the code using Google Tag Manager, nothing is fired except for the initial pageview.
This is the code for firing custom events:
ga('send', 'event', 'test', 'test');
I tested using the console and in both cases ga
is defined, and the above code doesn't throw any errors.
I also tried to find some configuration option in GTM that's blocking my events, but couldn't find anything useful.
Any ideas what's preventing the custom events from being fired?
You can't use the same code to track events using Universal Analytics and GTM. When you switch to GTM, you have to push events to the dataLayer and then fire tags based on rules. You can not fire tags directly using analytics.js.
you should migrate your code to use the dataLayer instead. Something like this:
javascript">
window.onload = function() {
if (window.dataLayer) {
dataLayer.push({'virtualPageView': {
category: 'Virtual Page View',
event: '/buy.html',
label: '10 Koowong Avenue',
}});
}
}
</script
>
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