Track Web Forms in iFrames
If your web form is displayed inside an iFrame, additional setup may be required for WhatConverts to track submissions correctly. The setup process depends on whether your form is hosted on the same domain as your website or through an external third-party provider.
Before you start, see What is Web Form Tracking? for an overview of form tracking.
Determine Your iFrame Setup
Before adding tracking code, identify which scenario applies to your website:
Option 1: Same Domain
- Your form and website are on the same domain (e.g., both on yourwebsite.com).
- No additional scripting is required beyond the standard tracking script.
Option 2: Third-Party Provider (External Domain)
- Your form is hosted by an external provider (e.g., GoHighLevel, Pardot, Typeform).
- Additional scripts are required to link both domains.
Note: Browser security measures like same-origin policy prevent WhatConverts from automatically reading data from external iFrames. If your form is hosted on a different domain, you'll need to add linking scripts to both pages.
Option 1: Track Forms on the Same Domain
If your form is hosted on the same domain as your website, tracking is straightforward.
To track same-domain iFrame forms:
- Confirm your WhatConverts tracking script is installed on the page that contains the iFrame.
- Submit a test form to verify leads are being tracked in WhatConverts.
That's it, no additional scripting is required for same-domain iFrames
Option 2: Track Forms Hosted by Third-Party Providers
If your form is hosted by a third-party provider on an external domain (such as GoHighLevel, Pardot, JotForm, or another form builder), follow these steps to link both domains:
Step 1: Add the Parent Domain Script
First, add this script to the page where your form is hosted (the third-party provider domain).
Script for the provider page:
javascript
<script type="text/javascript">
wc_frame_parent = 'https://YourURL.com/';
</script>
Customize this script:
- Replace https://YourURL.com/ with the URL of your main website (the page where the iFrame is embedded).
- Example: If your website is example.com/contact, use 'https://example.com/contact'.
Placement: Add this script above your WhatConverts tracking script on the provider page.
Note: This script tells WhatConverts where the parent page is located so it can link the two domains together.
Step 2: Add the Target iFrame Script
Next, add a targeting script to the page on your main site (the parent domain that contains the iFrame).
Choose the script that matches how your iFrame is identified in your HTML. Your iFrame can be identified by its name, ID, class, or role attribute.
By iFrame Name:
javascript
<script type="text/javascript">
wc_frame_target = '[name=iframe_test]';
</script>
Replace iframe_test with your iFrame's actual name attribute.
By iFrame ID:
javascript
<script type="text/javascript">
wc_frame_target = '#iframe_test';
</script>
Replace iframe_test with your iFrame's actual ID attribute.
By iFrame Class:
javascript
<script type="text/javascript">
wc_frame_target = '.iframe_test';
</script>
Replace iframe_test with your iFrame's actual class attribute.
By iFrame Role:
javascript
<script type="text/javascript">
wc_frame_target = '[role=iframe_test]';
</script>
Replace iframe_test with your iFrame's actual role attribute.
Placement: Add this script above or before your WhatConverts tracking script on the parent page.
Tip: Not sure which attribute your iFrame uses? Right-click on the iFrame, select "Inspect Element," and look at the HTML code to see if it has a name, ID, class, or role attribute.
Step 3: Test Your Setup
After adding both scripts:
- Submit a test form through the iFrame.
- Check your WhatConverts Lead Manager to confirm the lead appears.
- Verify that form field data (name, email, etc.) is captured correctly.
Note: If you're using the WhatConverts WordPress plugin, you'll need to deactivate it and manually place your WhatConverts tracking script below the target iFrame script on your parent page.
How iFrame Tracking Works
Here's what happens when you track forms in iFrames:
- User visits your page: The parent page loads with both your WhatConverts tracking script and the iFrame containing the form.
- User submits the form: The form data is submitted on the third-party provider's domain.
- Scripts communicate: The linking scripts allow WhatConverts to read the form submission data across domains.
- Lead is created: WhatConverts captures the form data and attributes it to the correct marketing source from your parent page.
Alternative Setup for Advanced Users
If you've already confirmed that your WhatConverts tracking script has been added to the source of your iFrame (for example, using a code injector or custom code element in your form builder), you can contact WhatConverts Support for assistance.
Our team can help deploy the additional iFrame linking scripts directly within your tracking scripts, eliminating the need to manually add separate scripts to both pages.
Related Topics
Get a FREE presentation of WhatConverts
One of our marketing experts will give you a full presentation of how WhatConverts can help you grow your business.
Schedule a Demo