If you lack access to the iframe source site, it is quite impossible to track iframe form submit event with Google Tag Manager. However, a solution to this problem is available through the following code snippet.
- In Google Tag Manager, create a new tag as a custom HTML tag.
- Inside the tag, paste the entire code from the
script.js
file provided in this repository. Don't forget to wrap the code with<script>
tag. - Set the trigger to fire on All Pages page views.
Once you've configured this setup, you'll begin receiving Google Tag Manager dataLayer events:
- iframe_from_start: This event will be triggered when a visitor first interacts with the form within the iframe.
- iframe_from_submit: You'll receive this event when the form is successfully submitted.
Recommendations: Keep in mind that your web page may contain multiple iframes. Therefore, it is highly recommended to adjust the iframe selector to target the correct iframe in line no: 12 of the code. You can utilize CSS class selectors or ID selectors for this purpose.
Md Hasanuzzaman
Email: [email protected]
Linkedin: https://linkedin.com/md-h