How to add Google Tag Manager code to a form?



Is there a way to add embedded code directly to the Form submissions so that we can keep track of how many visitors submitted the form.

Currently, the submission tracking code is added to the Landing page which includes the form. But because the form is embedded using an Iframe, it is not properly recording submissions.

The code is coming from a Google Tag Manager which has been added to the section of the landing page, but is not working.

How would I go about tracking that submission itself using the form?


Welcome, @goldlilys!

We usually recommend adding conversion tracking snippets to the onFormSubmit or onFormSubmitted form events with jQuery, as listed in this documentation. For a more specific example, check out this article.

Is this feasible in your situation? If you're not sure, pleas send me a link to your landing page and point out where your code is currently located.


The code that needs to be added is something like below:

It says it needs to be added on the and section of the page ... in this case this landing page for the Thank You page at

I added it to the Additional Code Snippets on Header HTML and Footer HTML. Is this the right area to add these code to?

I do not see at where those code should go to. Where are the
onFormSubmit or onFormSubmitted at in Hubspot?


Thank you for clarifying, @goldlilys.

The way you have installed the Google Tag Manager scripts in the Head HTML and Footer HTML on this page is fine!

(If you wanted it on all of your site pages, though, you would follow these steps and place the code in the Site header HTML and Site footer HTML sections here.)

I see the GTM-PHLC2LB script running on the thank you page. To track conversions, just put your desired tracking tag into your Google Tag Manager and it will fire wherever you have installed the Tag Manager script (like on this page).


Thanks, issue resolved.