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
With the transition from Universal Analytics to Google Analytics 4, there may be some issues you need to resolve. One of these issues is “unassigned” traffic. Dimensions appearing as “unassigned” / (not set) in reports negatively impact your ability to analyze and optimize. We will discuss the causes of “unassigned” traffic in your GA4 reports […]
Read More
Beginner Level Web/App AnalyticsEarlier this year, Google Cloud announced that BigQuery data warehouse supports automatic data transfer from Facebook Ads. In its preview stage, this feature offers an alternative way to enhance analysis and insights by allowing the scheduling of data loading tasks. With this integration, the need for third-party tools or manual code execution is eliminated. This […]
Read More
Mid Level Web/App AnalyticsBy combining the app and web data in Google Analytics 4, app analysis has become more easily trackable. Firebase Analytics allows you to easily track your iOS or Android app with GA4. With numerous different tools available for mobile app tracking, being able to see both web and app data within the same property is […]
Read More
Mid Level Web/App AnalyticsBusinesses want to use as much data as possible from analytics and marketing cookies. However, in order to collect and use this data, they need to comply with laws such as KVKK/GDPR. By enabling Cookie Mode, Google helps to use cookies according to the level of consent. In other words, with Cookie Mode, users’ privacy […]
Read More
Mid Level Web/App Analytics