How to Track Google Ads Conversions in an Iframe Using Google Tag Manager?

Question from Reddit user:

Bit of a tricky one here. I want to be able to track downloads of one-sheeters on my website within Google Ads.

Users are prompted to download the document(s) on my landing pages and once they click download, a form pops open in an iframe asking them for typical lead/contact type information. There is then a button to submit this form.

Once submitted, users are not taken to a thank-you page but rather the form popup/iframe changes to some text thanking the user for their information.

So long story short, I am using Google Tag Manager across my site to track other conversions in Google Ads.

I want to be able to track these one-sheeter downloads using GTM but I am stuck on how to do so given that the form and thank you message both live within an iframe and I am not utilizing a thank-you page. So in order to track these conversions I will have to somehow figure out button click tracking within an iframe using Google Tag Manager….I think.

Anyone have any thoughts? I know it would be a huge undertaken but if someone does know how to properly track conversions in Google Ads in a case like this could you please walk me through the process step by step?

I’ve been doing SEM for like 8 years but my coding knowledge is very limited and I’ve never run into this button click/iframe situation. Apparently this is the only way my developer is able to set up the pages/document downloads so please hold off on any suggestions involving simplifying the conversion setup.

Thanks in advance!

Answer from Nabil:

The short answer is:

How to track Google Ads conversions in an iFrame using Google Tag Manager?

You are correct that this is a tricky situation.

Since the conversion happens entirely within an iframe and without a URL change, standard GTM click and page view triggers on the main page cannot see the button click or the success message inside the iframe.

The immediate, developer-friendly solution is to have your developer add a small piece of code inside the iframe’s success handler that uses JavaScript to send a custom message or event to the parent window, which your main GTM container can listen for and use as the trigger to fire your Google Ads conversion tag.

A more robust and future-proof solution is to use the Google Ads API and a server-side solution to bypass the iframe issue entirely.

The long answer is:

Since simplifying the conversion setup is not an option, you must bridge the communication gap between the iframe and the main window where your Google Tag Manager container lives.

GTM on the main page is isolated from content within an iframe for security reasons, so it cannot directly “see” the button click or the success text inside.

The developer-friendly way to solve this client-side is by using the postMessage() JavaScript method.

You would ask your developer to insert a single line of JavaScript code into the function that executes when the user successfully submits the form inside the iframe and sees the thank you text.

This code, placed inside the iframe, would use window.parent.postMessage('form-submission-success', '*') to send a message to the main window.

Your GTM container on the main page can then be configured to listen for this specific message.

You would create a custom event trigger in GTM that fires when it receives the form-submission-success message, and then use that custom event trigger to fire your Google Ads conversion tag.

However, a much more resilient, reliable, and privacy-compliant solution that avoids all client-side rendering and communication issues is to implement server-side tracking using the Google Ads API and a platform like Stape or Google Cloud Platform.

The key is to shift the responsibility of tracking the conversion from the user’s browser (where the iframe is causing problems) to your secure server.

Here is the step-by-step API solution:

First, you must ensure that when the user arrives on your landing page from a Google Ad, the Google Click ID (gclid) is captured and persisted.

GTM can do this on the main page by reading the URL parameter and storing it in a first-party cookie.

Second, when the user clicks the submit button inside the iframe, instead of firing the Google Ads tag, the form submission should be configured by your developer to send all the lead data directly to your secure server or to your server-side GTM container endpoint, hosted on Stape or GCP.

This data must include the persisted gclid.

Third, the server-side container or a custom webhook hosted on GCP would receive this data.

Instead of relying on the client-side Google Ads tag, this server environment then uses the Google Ads API to instantly send an offline conversion back to Google Ads, passing the original gclid as the key identifier, along with the conversion name (e.g., One-Sheeter-Download).

This method guarantees the conversion is tracked accurately, completely bypasses the iframe isolation and any potential ad-blockers, and is a more robust way to track the most critical conversion event for your paid media campaigns.

About The Author