Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait for dataLayer.push() with Google Tag Manager

I have to send a google tag manager event when a user press a button in a web. On fact, this button is inside an iframe and after that click, this iframe is closed and another one comes up...

I'm setting this event data on the click event from javascript and then I call dataLayer.push to send that info to google analytics.

I can see this request from firebug but it gets cancelled before it arrives to google as soon as the iframe closes...

Is there any way to wait for this call before closing my iframe? Is there any other way to "push" this data?

Thanks in advance.

like image 298
zapico Avatar asked May 27 '13 08:05

zapico


People also ask

How do I get the dataLayer variable in Google Tag Manager?

Set up the data layer variableClick Variables. Under User-Defined Variables, click New. Click Variable Configuration and select Data Layer Variable as the variable type. In the Data Layer Variable Name field, enter the key exactly as it was written in the code (e.g. bookTitle, not book title.)

How do I push an event into dataLayer?

The syntax for sending an event with dataLayer.push() is as follows: dataLayer.push({'event': 'event_name'});

What does the dataLayer push () command return?

The return value, assuming you are referring to when you pasted the code into the console, indicates whether a GTM tag fired in response to the push. "true" means that no tags fired, and "false" means that a tag fired.

How do I delay tag firing in GTM?

Create GTM Timer Trigger The field Interval determines how long the timer will wait after trigger to fire a Tag. To achieve a five-second delay on our Facebook Pixel Tag, enter 5000 milliseconds in the Interval field. If no Limit is placed on this trigger, then it will fire a Tag every consecutive interval.


2 Answers

To make this question more useful for current readers: by now you would create an event listener tag in Google Tag Manager and check the "wait for tags that depend on this event" checkbox (event listener tags did not exist in GTM when this was asked).

(And of course the technical background is a bit different that stated in the question - for one thing datalayer.push does not send data to Google Analytics).

like image 155
Eike Pierstorff Avatar answered Sep 29 '22 00:09

Eike Pierstorff


Found here http://www.simoahava.com/gtm-tips/hitcallback-eventcallback/ the event 'eventCallback'. I didn't tested it yet but hope it will work, and as I can see gtm.js contains this event.

like image 43
user1239646 Avatar answered Sep 29 '22 00:09

user1239646