On this page
What this issue is
Some checkouts, booking tools and payment pages are shown inside an <iframe> on your own site. The iframe loads a page from another origin (a different domain or subdomain), such as a hosted checkout or a funnel tool.
Browsers keep that frame separate from the parent page. The parent's GA4, Google Ads or Meta tags cannot read the frame's content or its data layer. The frame's own tags, if any, may run with a different client ID and no knowledge of the ad click that brought the visitor.
The result is that the purchase or generate_lead event is missing, is sent with the wrong session, or shows up as direct traffic.
Why it costs you leads or sales
The sale still happens, but your ad platforms do not hear about it. Smart bidding in Google Ads and Meta's delivery learn from conversions. If they see fewer than really occurred, they optimise on weak data and your cost per result looks worse than it is.
Reports also mislead you. Paid campaigns look like they sell nothing, while revenue piles up under direct or referral traffic. You may cut budget from the channels that actually work.
- Ad clickVisitor lands with gclid and UTMs
- Parent pageTags fire, page_view recorded
- Iframe checkoutSeparate origin, no link to the parent session
- Purchase eventNot sent, or sent without the ad source
- Ad platformConversion never credited
The parent page tracks the visit, but the purchase inside the iframe never reaches it.
Example: 100 real purchases a week. With the iframe unlinked, only some are reported, and fewer still carry the ad source.
How to check if your site has it
- Open the checkout page and look in the browser's developer tools (Elements tab) for an
<iframe>whose src is another domain. - Complete a test order and watch the Network tab for GA4 (
collect) and ad platform requests. Note which come from the parent and which from the iframe. - In GA4 Realtime or DebugView, check whether the purchase appears and which source and medium it shows.
- Compare orders in your store or payment tool with purchases in GA4 and Google Ads for the same days.
- Check whether the client ID (
_gacookie) on the parent matches the one used in the iframe requests. - Look at your referral list in GA4 for the checkout domain. If it appears, sessions are being split.
How to fix it
There are two routes. Best is to have the iframe send a message to the parent, which then fires the tags with the parent's full session. The second is to track inside the iframe and link its session to the parent. You need control of the iframe's code or settings for either one. If the provider is a hosted tool, check its documentation for a supported event or parameter option.
Decide who owns the tags
Prefer firing conversion tags on the parent, where the ad click data and consent state already live.
Send a message from the iframe
On the order confirmation view inside the iframe, call window.parent.postMessage with the event name, order ID, value and currency. Always set the parent's exact origin, never '*'.
Listen on the parent
Add a message listener on the parent page. Check event.origin against the checkout domain, then push the data to the data layer.
Fire tags from the data layer event
Create a trigger for your custom event and attach the GA4 purchase, Google Ads conversion and Meta tags to it.
Prevent double counting
Turn off duplicate purchase tags inside the iframe, or pass the same transaction ID so platforms can deduplicate.
window.parent.postMessage({
type: 'checkout_complete',
transaction_id: 'ORDER-12345',
value: 59.00,
currency: 'USD'
}, 'https://www.yourstore.com');window.dataLayer = window.dataLayer || [];
window.addEventListener('message', function (event) {
if (event.origin !== 'https://checkout.example.com') return;
var d = event.data;
if (!d || d.type !== 'checkout_complete') return;
window.dataLayer.push({
event: 'purchase_from_iframe',
ecommerce: {
transaction_id: d.transaction_id,
value: d.value,
currency: d.currency
}
});
});Add the listener
Create a Custom HTML tag with the parent listener code, triggered on All Pages (or the checkout page only).
Create a Custom Event trigger
Set the event name to purchase_from_iframe.
Read the values
Create Data Layer Variables for ecommerce.transaction_id, ecommerce.value and ecommerce.currency, then use them in your GA4 event, Ads conversion and Meta tags.
Test in Preview
Run a test order in Tag Assistant and confirm the tags fire once on the parent.
Place the listener
Add the script to the checkout page through your tag manager, or a header and footer scripts plugin limited to that page.
Avoid theme edits that updates overwrite
Use a child theme or a plugin rather than editing the parent theme files.
Add page custom code
In Page settings, paste the listener into Before </body> tag on the page holding the iframe.
Publish
Custom code only goes live after you publish the site.
Add custom code
Go to Settings, Custom Code, add the listener to the page with the embed and set it to load in the Body end. A premium plan is needed for custom code.
Use Code Injection
Add the listener in Settings, Advanced, Code Injection (Footer), or in a Code block on the page. Code injection needs a plan that supports it.
Add tracking code to the funnel step
In the funnel step settings, open Tracking Code and add the listener to the Body code section of the page with the embedded checkout. Then publish the step.
Add the listener
Load the message listener on the parent page before the iframe finishes. Keep origin checks strict.
Use a linker if tracking inside the iframe
If the iframe domain runs its own GA4 tag, add it to cross-domain settings in GA4 (Admin, Data streams, Configure tag settings, Configure your domains), so the client ID is shared via the _gl parameter.
How to confirm it's fixed
Run a test purchase
Use the provider's test mode or a low-value order you can refund. Enter the site from a tagged link such as ?utm_source=test&utm_medium=check.
Watch the data layer
In GTM Preview or the console, confirm the purchase_from_iframe event arrives on the parent once.
Check GA4 DebugView
The purchase should show the transaction ID, value and the test source and medium, not direct.
Check ad platforms
Look in Google Ads conversion diagnostics and Meta Events Manager for the event within the expected delay.
Broken
- Purchase happens in the iframe only
- Parent tags never hear about it
- Orders show as direct or are missing
Fixed
- Iframe posts a message on confirmation
- Parent fires tags with the full session
- Orders carry the right source and value
How to prevent it happening again
- Document who owns the iframe code and the parent listener.
- Re-test a full order after any change to the checkout provider, theme, tag manager container or consent banner.
- Keep the message format (event name and field names) fixed and versioned.
- Compare store orders with GA4 purchases weekly and investigate gaps.
- Add the checkout domain to GA4 unwanted referrals or cross-domain settings if it appears as a referrer.
- Schedule an automated test of the whole journey so a break is noticed within a day.
How FunnelGuard handles this
FunnelGuard detects this issue only partly. A robot visitor runs your checkout journey on a schedule, from the EU or the US, and checks the steps and the tracking hits sent to GA4, Google Ads, Meta and other platforms. If the expected hit does not arrive, the failure is re-checked from a second region and you get one alert with a screenshot and a likely cause.
Questions people ask
Why is my iframe checkout not tracking purchases in GA4?
The iframe is a separate page context from a different origin, so tags on your parent page cannot see inside it. If the iframe has no GA4 tag, or one with a different client ID, the purchase is missing or split from the original session. Send the event to the parent with postMessage, or link the sessions with cross-domain settings.
Can Google Tag Manager on the parent page track events inside an iframe?
No. GTM on the parent cannot read the iframe's clicks, DOM or data layer when it is on another origin. The iframe has to send the data out, usually with postMessage, or run its own tags.
How do I send a purchase event from an iframe to the parent page?
Call window.parent.postMessage with the order details and the parent's exact origin from the iframe confirmation view. On the parent, add a message listener, verify event.origin, and push the data to the data layer to trigger your tags.
Why do iframe checkout sales show as direct traffic?
The iframe session starts without the parent's cookies or the ad click parameters, so GA4 sees a fresh visit. Fire the purchase on the parent, or add the checkout domain to GA4 cross-domain settings so the client ID carries across.
Is it safe to use postMessage with a wildcard origin?
No. A '*' target lets any page that embeds the frame read the message, which may include order values or identifiers. Use the exact parent origin when sending, and check event.origin when receiving.
Will I count purchases twice if both the iframe and the parent have tags?
Yes, it can happen. Keep purchase tags in one place, or send the same transaction ID from both so GA4 and the ad platforms can deduplicate. Test with one order and check that it appears once.
Can FunnelGuard check my iframe checkout tracking?
Partly. It runs your checkout journey on a schedule and checks tracking hits to ad and analytics platforms, alerting you when expected hits are missing. It does not verify your postMessage design or whether real purchases are credited to the right campaign, so keep doing manual test orders.
Related issues
- TRK-392Headless checkout loses tracking from main siteFix guide
- TRK-402Typeform/Jotform embed conversions not tracked on parent siteFix guide
- TRK-403Calendly embed events not listened forFix guide
- TRK-400Tracking only in site header, funnel pages use blank templateFix guide
- TRK-389SPA route change sends no page_viewFix guide
- TRK-390SPA sends page_view twice per routeFix guide