Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
postMessage not pushing into the dataLayer

I have a script inside a child google tag manager account which is firing on submission of an iframe form that is generated via javascript, this should be picked up via the parent google tag manager account through the dataLayer. I am following this tutorial: https://measureschool.com/iframe-tracking/

However it's not going into the dataLayer on the parent - hence the tag isn't firing. Can anyone help?

To confirm

Child tag manager account fires at: https://new.bokuntest.com/ - the iframe form URL

Parent tag manager account fires at: https://bokun.io/

URL of page with embedded iframe form: https://bokun.io/copy-of-free-trial

postMessage tag firing in child:

<script>
  try {
      var postObject = JSON.stringify({
        event: 'iframeFormSubmit', 
        form: 'Registration'
      });
      parent.postMessage(postObject, 'https://new.bokuntest.com');
} catch(e) {
  window.console && window.console.log(e);
}
  </script>

Listener tag on parent (trigger = fire on all pages):

<script type="text/javascript">
(function(window) {

    addEvent(window, 'message', function(message) {
      try{
      var data = JSON.parse(message.data);
      var dataLayer = window.dataLayer || (window.dataLayer = []);
      if (data.event) {
        dataLayer.push({
          'event': data.event,
          'postMessageData': data
        });
      }
      }catch(e){}
    });

    // Cross-browser event listener
    function addEvent(el, evt, fn) {
      if (el.addEventListener) {
        el.addEventListener(evt, fn);
      } else if (el.attachEvent) {
        el.attachEvent('on' + evt, function(evt) {
          fn.call(el, evt);
        });
      } else if (typeof el['on' + evt] === 'undefined' || el['on' + evt] === null) {
        el['on' + evt] = function(evt) {
          fn.call(el, evt);
        };
      }
    }

  })(window);
</script>

Trigger on parent (it's this that doesn't seem to be happening):

enter image description here

Form submission tag on parent:

enter image description here

Can anyone figure out what I've missed?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

window.parent.postMessage(postObject, 'https://new.bokuntest.com');
      try {
          var postObject = JSON.stringify({
            event: 'iframeFormSubmit', 
            form: 'Registration'
          });
          window.parent.postMessage(postObject, 'https://new.bokuntest.com');
    } catch(e) {
      window.console && window.console.log(e);
    }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!