If you use the dataLayer.push
method in Google Tag Manager to add data to your datalayer, you’ll want to include a Google Tag Manager Data Layer Event as well. Using a datalayer event, you can then fire a Custom Event Trigger. Using this setup will allow you fire any necessary tags to read any newly pushed data. Here’s how you set it up.
Add An Event To dataLayer.push
Once your code has completed, you’ll want to fire the final datalayer event, so that Tag Manager can intercept the event in the next step. It’s important to fire any events that need the data as quickly as possible, rather than stacking them. Here’s what we will change:
dataLayer.push({ 'var1':'value' });
To become this. Notice the addition of the comma on the previous line!
dataLayer.push({ 'var1':'value', 'event':'sendUpdate' });
Set Up A Trigger To Fire
Now that we have our event taken care of in the code, we’ll want to create a new Trigger to listen for this event to fire. To create this trigger, select “Custom Event” as the type, and give the Event Name the same value and case as we programmed above.
Update Tag To Use The New Trigger
Now we can update our tag to use the newly created trigger to fire. Select “More” from the “Fire On” step, and select our trigger
In this way, we can ensure that our Data Layer handles the data, and any tags that are needed can be fired as quickly as possible.
Hi, great post!
Once I’ve set up the trigger like you’ve done, what should I do in the Tag configuration?
I understand that I need to pick my trigger in the “Fire on” section, but what should I pick in the Configure Tag section? Is it pageview or event or transaction or what?
Confused here :-)
Hi Martin!
Well, that entirely depends on what you are firing the event for! Most of the time I use data layer push to fire Events into Google Analytics. You may have a different setup or need – what is it you’re trying to do?
Hello Greg, Thank you for the wonderful post. I was looking for this only. I have a query – once this is done, how can we pass this custom event in GA so that I can check data in Top Events report?
Hello Nik,
Great question! Once you’ve gotten your event to fire, you’ll then want to add a Trigger to Google Tag Manager to listen for that custom event. Once your Trigger is set, then create a Google Analytics Event, and have it fire from the Trigger. So, the order of operations are: custom event fires the trigger, and the trigger fires the tag. Thanks!