We are using a CTA element holding a Hubspot form to display it on a Hubspot landing page. This works perfectly fine, but is loaded as an iFrame on the website.
As the Hubspot landing page holds our Google Tag Manager container we are looking for a way to send data from the iFrame to the parent page and look for a solution to send a postMessage call from the CTA/form element whenever the form is sucessfully submitted.
Is there any way to implement this? We cannot find options or elements to use custom JavaScript in CTA/forms, but we are aware of using global HTML/JS embeds and are wondering if this can help us here.
Hi @MTrykar and welcome, we are thrilled to have you here!
I’d love to ask some clarifying questions so that the Community can help you in the best way!
- Are the form and landing page on the same domain and protocol?
- Have you tested if any postMessage events are received by the parent page?
- Is the form added as a native HubSpot CTA or through an external embed/code snippet?
I’d love to put you in touch with our Top Experts: Hi @Anton, @TomM2 and @evaldas do you have suggestions to help @MTrykar, please?
Thanks so much and have a lovely weekend!
Bérangère
Hello and thanks for your help! We are using this for global forms on the website, but cannot use it for Hubspot landing pages as the forms there are implemented as iFrame.
For me this works on a HubSpot landing page and successfully logs submission details in the console.
The intial “if” statement is just for quick testing, to reduce the noise and filter messages coming from hubspot domains (i.e. hs-sites-eu1.com). You can adjust accordingly or simply remove it if you opt not to use any guardrails.
For me submitting a form there does not send any messages to the console. Or did you test this in the iFrame itself? If so, my question is how I can add code to the iFrame in Hubspot?
Looks like you may have changed the form on that page? Either way, I tested the new form submission on your page and was able to capture that form submission in the console.
We may need to simplify the code a bit and add some preliminary checks to make sure it is properly running:
Thank you so much and this script works perfectly fine. One question: Why don’t you put in the <head> section of the landing page instead of the <body>?
And maybe you can help me with the final version of the script as I also want to track theonCallToActionReady event, but somehow the msg variable does not hold the same information as it does with the onCallToActionFormSubmitted event:
Hi Manuel, glad to hear the form submission is working for you now.
Regarding your other questions, the reason to put this in the footer instead of <head> is to help prevent render blocking requests, which is something Google measures as a website performance metric. Since this script is not critical for page load and it will take a while for a user to submit the form, it does not need to load that soon.
As for tracking the “ready” state - two issues there:
1) I do not see “onCallToActionReady” being available in this case
2) Even if it was, you can’t pass submission values to a “ready” state because the submission has not happened on that event
What you could do is track the CTA open event with “onCallToActionViewed” and pass the ID of that event, but user visitor information will not be captured at this point.