Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Tag Manager dataLayer within iframes

I'm wondering if it's possible to 'sync' the dataLayer between an iframe and it's parent page.

The situation:

  1. I have a parent page with a GTM container and a hardcoded dataLayer.
  2. In that parent page I have an iframe with the same GTM container.

What I want to do is read the dataLayer in the parent from the iframe, ideally through the Tag Manager (Macros). The variable can be updated from the parent page, but the iframe should only read the data.

Is this possible? Google is pretty hazy about the issue and I can't really find a decent answer.

like image 445
David Halford Avatar asked Mar 21 '23 06:03

David Halford


1 Answers

Tracking across IFRAMEs with Google Tag Manager

I would suggest a different solution:

  1. parent page with GTM container
  2. datalayer events inside the IFRAME page
  3. only one GTM container per page

for pushing use the parent method:

parent.dataLayer.push({'event':'EVENT_NAME', 'var2':'ANOTHER_VARIABLE'});

Let me know if it worked for you.

like image 137
user3537921 Avatar answered Apr 06 '23 09:04

user3537921