How to track custom events when Google Analytics is managed by Google Tag Manager?

Google Tag Manager (GTM) by default uses a random name for each tracker, generated for each Universal Analytics tag. AS GTM creates only named trackers, therefore no default (t0) tracker will be created. As no default tracker is created, you must provide a tracker name yourself. Therefore, you would need to now the tracker names, or somehow query and reference them, in order this to work, only by using ga() call directly from JavaScript.

There is a possibility to use fixed name for trackers, which is highly discouraged.

I have a recommended workaround for this. You still need to make a few GTM settings, but you can create a Google Analytics general event dispatcher tag, which you can later use to send any Analytics event calls from JavaScript.

Your tag setting will look something like this, where you can reference your Analytics settings, and all the event related variables from dataLayer:

enter image description here

Your event tracking code will look like this:

dataLayer.push({
  'event': 'GAEvent',
  'eventCategory': 'Videos',
  'eventAction': 'play',
  'eventLabel': 'Fall campaign', 
  'eventValue': undefined,
  'eventNI': true 
});

Please note, that it is recommended to always set all the relevant event values in dataLayer, even if no string or value should be tracked, so that no earlier dataLayer values would be inherited during the push merge. Also, you should update the non-interaction flag, as needed in your case. Your trigger should match the value of the event key.


I created a new "custom html" tag in Tag Manager. Then I added the analytics.js code below and set the tag to fire on page load. This allowed me to use the existing ga calls in my code to fire custom events rather than re-writing all of my events to work with Universal Analytics through the dataLayer as the other answer suggested.

<!-- Google Analytics -->
<script>
    window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
    ga('create', 'UA-XXXXXXXXX-Y', 'auto');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->