envigoPublishedMay 22, 2025
An iframe (short for inline frame) is an HTML element that allows one webpage to be embedded inside another. It’s commonly used when you want to display third-party content—like videos, forms, or apps—without fully integrating that content into your site’s codebase.
Common Examples of iFrame Use:
In our case, the chatbot was served via an iframe hosted on a different domain.
We were unable to track chatbot events (such as form submissions) because the chatbot was loaded in an iframe. Our initial solution—placing GTM within the iframe—wasn’t successful due to cross-domain problems. The solution? Using `postMessage` to send data from the iframe to the parent page, then pushing it to the dataLayer.
We needed to monitor significant interactions from our embedded chatbot—form submissions and message types, for example. Under normal circumstances, with Google Tag Manager (GTM), monitoring is relatively easy.
But this chatbot resided within an **iframe**, and that made all the difference.
We thought – Why not simply include GTM within the iframe and trigger events from there?
So we did just that:
But… nothing appeared in the parent GTM.
It turns out, it was a cross-domain communication issue.
Browsers are designed to isolate iframes from their parent windows, especially when they’re hosted on different domains. This is a security feature known as the same-origin policy, and it exists to prevent malicious scripts from one site accessing sensitive information on another.
In our case, that meant the parent page couldn’t directly access or listen to the dataLayer inside the iframe. Even though both pages were working together functionally, from the browser’s perspective, they were treated as completely separate and untrusted.
This isolation is crucial for protecting users’ data—but it also means that traditional tracking methods (like GTM inside the iframe) don’t work across domains. Without a secure way to bridge the communication gap, key user interactions inside the iframe remain invisible to the analytics tools running on the parent page.
That’s why our first approach failed—and why we needed a more robust, browser-approved way to pass data between the two.
So our solution was broken from the beginning.
We changed to utilising **postMessage**, a browser API for securely communicating between windows—incidentally including iframes and parent pages.
1. Send a message from the iframe
/code/
2. Listen for the message on the parent page
/code/
3. Capture it in GTM
Create a Custom Event Trigger for chatFormSubmitted, and use GTM variables like messageType, name, or email as needed in your tags.
4. The kind of reports to create for chatbot tracking
Once we had tracking in place using postMessage and GTM, we were able to unlock a range of valuable insights from chatbot interactions. Here are some of the key reports you can create to better understand user behaviour and the chatbot’s impact:
Track how many users submitted forms through the chatbot. You can break this down further by:
Understand how users are interacting with the chatbot:
Identify what users are coming to the chatbot for:
If your chatbot collects names or emails, you can report on:
⚠️ Important Note: While it may be technically possible to capture personal data like names or email addresses, doing so directly in tools like Google Analytics is against Google’s policies and may violate data privacy laws (such as GDPR or CCPA).
Always ensure that personal data is either anonymised or handled through compliant, secure systems—never sent directly to GA4 or stored in the dataLayer in plain text.
Visualise the full user journey:
Analyse where and how users are engaging:
These reports can be set up in GA4, Looker Studio, or any other analytics tool you’re using—depending on your tech stack and reporting needs.
If you’re putting a chatbot (or any third-party app) inside an iframe, tracking is tricky—but completely possible with proper setup.
Take your next step with a free SEO audit and consultation with industry experts.
Google Analytics 4 (GA4) has always been our go-to tool for deciphering marketing data, and now, it’s gotten even better. With its recent update, GA4 introduces a host of new features designe.....
We often overlook a subtle yet formidable adversary: SEO spambots. While operating silently, these automated programs can significantly impact your website’s performance and reputation. Our j.....
Event tracking in Google Analytics 4 (GA4) is a powerful tool that helps businesses understand user behaviour, optimise user experience, and make informed decisions to improve digital marketing str.....