19.07.2023
iFrame, first of all, needs to be clarified for this question.
iFrame is an HTML tag that allows us to embed and display a different web page within another web page. By using the iFrame element, we can seamlessly integrate another website into our own website or display a specific page from a different website within our site.
To track user interactions within the iFrame, you need developer access to the web page inside the iFrame. Otherwise, tracking will not be possible.
You can monitor iFrame interactions by sending a JavaScript call named ‘postMessage’ from the iFrame to the parent frame. This ‘postMessage’ JavaScript call can be added for each interaction to be tracked by using code snippets within the iFrame (requested from the iFrame’s developer) or implemented through Google Tag Manager (GTM) within the iFrame.
We will proceed using Google Tag Manager. Even if you have GTM installed on your website,, it won’t be able to collect user interactions occurring within the iFrame. Therefore, GTM must also be installed within the iFrame.
You will need to decide which user actions you want to track within the iFrame. We will explain our example based on form submissions.
First, we need to set up our trigger so that it fires when the Form ID is equal to “submit”. Here, we want the trigger to always fire when the user performs the action we want to track, but not when the user interacts with the iFrame in other ways.
Now it’s time to proceed with sending the iFrame data to the parent frame, and for this purpose, we are creating a new tag. We will use the postMessage method, which transmits tracking data to the parent frame, to send the data to our parent frame through Google Tag Manager.
We will use the custom HTML tag and select the trigger as “form – submit”.
Our iFrame will send tracking data to the parent frame, so we need to listen for this data in the parent frame. Therefore, we want this listening tag to fire on the form submission page.
We set our trigger as “Page View” and select the form submission (get-offer) page.
We create a new tag for listening to iFrame data. This tag retrieves the information from postMessage and sends it to the Data Layer.
Now that what we want to track is present in our parent frame’s Data Layer, we can send the iFrame data to the desired tools.
We write the event name used in the postMessage sending process into the Custom Event field, which we selected as the trigger.
And now the GA4 Event:
You can now send the data received from the iFrame to the desired tools. You can control the incoming data also from the dataLayer.
I hope this article has been helpful. Feel free to get in contact with us for any feedback or comments.
Perfist Blog
Similar Articles
Regularly monitoring the destination URLs of your Google Ads campaigns is one of the most effective ways to protect your ad budget. Broken or misdirected pages waste paid clicks, lower your Quality Score, and hurt your conversion rates. In this article we’ll walk you step-by-step through building an automation system that exports Google Ads destination […]
Read More
Senior Level Performance MarketingIn this guide, we will explain what a session is in Google Analytics 4 (GA4), why session duration matters, which session metrics are available, and how to configure these settings. What is a Session in GA4? A session represents the group of interactions a user has with your website or mobile app within a given […]
Read More
Beginner Level Web/App AnalyticsWhat is GEO (Generative Engine Optimization)? GEO is a new generation optimization method that ensures content stands out in AI-supported search systems. It aims to produce content that can provide quick and clear answers to user questions. In addition to traditional SEO, a simple and understandable language that appeals to artificial intelligence is used. Why […]
Read More
Mid Level SEOGEO is an optimization method developed to ensure that content is better understood and recommended by AI-powered search engines. Previously, when writing content, the goal was solely to rank high on Google. Now, however, AI systems read these contents and present summaries to users. This is exactly where GEO steps in. It ensures that content […]
Read More
Mid Level Content Marketing