Iframes
Tracking user submissions from forms embedded in iframes can be implemented using the Dreamdata analytics script. However, note that this script may not work with all iframe types due to variations in how forms are rendered within them.
For example, Marketo forms embedded in iframes require a specific script different from the general one provided here.
Setting Up Iframe Tracking
- Script v3
- Script v2
With script v3, iframe forms are tracked as soon as form tracking is on in your main application. Form tracking covers every supported form type, so there is no separate option to enable:
<script>... formTracking: true, ...</script>
To track only some form types, see Choosing which forms are tracked.
By default the script accepts submissions from any iframe embedded directly in the page. To accept them only from your own form pages, list their addresses:
<script>
...
formTracking: {
iframe: {
allowedOrigins: ["https://forms.your-website.com"],
},
},
...
</script>
To enable tracking for general iframe forms, include the following script in your main application:
<script id="init-dreamdata">
...
formTracking: {
iframe: true,
},
...
</script>
Embedding the Iframe Script
- Script v3
- Script v2
Additionally, insert this script inside the iframe to ensure form submissions are properly identified and tracked:
<script
charset="utf-8"
id="dreamdata-iframe"
type="text/javascript"
src="https://cdn.dreamdata.cloud/scripts/analytics/v3/iframe-identify-form.min.js"
parent-origin="https://www.your-website.com"
></script>
Set parent-origin to the address of the page that contains the iframe, without
a path. It is needed when that page does not send a referrer to the iframe:
without a referrer and without parent-origin, the iframe script sends nothing.
The script also tracks forms that are added to the iframe after it has loaded.
Additionally, insert this script inside the iframe to ensure form submissions are properly identified and tracked:
<script
charset="utf-8"
id="dreamdata-iframe"
type="text/javascript"
src="https://cdn.dreamdata.cloud/scripts/analytics/next/iframe-identify-form.js"
></script>
It is possible to set a custom event name by adding the
form-name="My Event Name" attribute to the script above.
Communication between an Iframe and a Parent Page
This diagram illustrates the process activated by including the scripts mentioned above. In simple terms, we monitor for a message from the form inside the IFrame, which is sent to the Parent Page. We then relay this event to our Analytics server.