# How to add Google Tag Manager code to a form?

**URL:** <https://community.hubspot.com/t/how-to-add-google-tag-manager-code-to-a-form/11628>\
**Category:** APIs & Integrations\
**Tags:** forms\
**Created:** [November 16, 2018, 11:23pm UTC](https://community.hubspot.com/t/how-to-add-google-tag-manager-code-to-a-form/11628 "2018-11-16T23:23:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [November 16, 2018, 11:23pm UTC](https://community.hubspot.com/t/how-to-add-google-tag-manager-code-to-a-form/11628/1 "2018-11-16T23:23:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [November 19, 2018, 8:11pm UTC](https://community.hubspot.com/t/how-to-add-google-tag-manager-code-to-a-form/11628/2 "2018-11-19T20:11:12Z")

</div>

Welcome, [@goldlilys](https://community.hubspot.com/u/goldlilys)!

We usually recommend adding conversion tracking snippets to the `onFormSubmit` or `onFormSubmitted` form events with jQuery, as listed in [this documentation](https://developers.hubspot.com/global-form-events). For a more specific example, check out [this article](https://growth.org/discuss/adding-custom-google-analytics-code-to-forms-in-hubspot).

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.

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [November 20, 2018, 8:47am UTC](https://community.hubspot.com/t/how-to-add-google-tag-manager-code-to-a-form/11628/3 "2018-11-20T08:47:13Z")

</div>

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

![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/2/e/2e93a07a6c221f2404653b67c23f2e7c4d75e884.png) [Google Developers](https://developers.google.com/tag-manager/quickstart)

 ![0225468a5d62cffe7966eb053415eb3e946fbd7e.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/0/2/0225468a5d62cffe7966eb053415eb3e946fbd7e.png)

### [Quick Start Guide | Google Tag Manager for Web Tracking

| Google…]([1. Create an account and container - Tag Manager Help](https://developers.google.com/tag-manager/quickstart))

Covers the Google Tag Manager container snippet (JavaScript and non-JavaScript) to insert into your web pages.

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 [https://pages.sequenom.com/maternit-million-thank-you-sign-up](https://pages.sequenom.com/maternit-million-thank-you-sign-up).

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 [Accounts Dashboard | HubSpot](https://developers.hubspot.com/global-form-events) where those code should go to. Where are the  
`onFormSubmit` or `onFormSubmitted` at in Hubspot?

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [November 20, 2018, 8:29pm UTC](https://community.hubspot.com/t/how-to-add-google-tag-manager-code-to-a-form/11628/4 "2018-11-20T20:29:28Z")

</div>

Thank you for clarifying, [@goldlilys](https://community.hubspot.com/u/goldlilys).

The way you have installed the Google Tag Manager scripts in the _Head HTML_ and _Footer HTML_ on [this page](https://app.hubspot.com/content/382060/edit/6565220156/settings) is fine!

(If you wanted it on _all_ of your site pages, though, you would follow [these steps](https://knowledge.hubspot.com/articles/kcs_article/cos-general/how-do-i-add-the-google-tag-manager-code-to-my-hubspot-pages) and place the code in the _Site header HTML_ and _Site footer HTML_ sections [here](https://app.hubspot.com/settings/382060/website/pages/all-domains/page-templates).)

I see the `GTM-PHLC2LB` script running on [the thank you page](https://pages.sequenom.com/maternit-million-thank-you-sign-up). To track conversions, just put your desired [tracking tag](https://support.google.com/tagmanager/answer/3281060) into your Google Tag Manager and it will fire wherever you have installed the Tag Manager script (like on this page).

---

<div class="post-metadata">

**Author:** ![Keithh](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/keithh/32/2401_2.png) [@Keithh](https://community.hubspot.com/u/Keithh)\
**Post date:** [December 18, 2019, 10:07pm UTC](https://community.hubspot.com/t/how-to-add-google-tag-manager-code-to-a-form/11628/5 "2019-12-18T22:07:05Z")

</div>

4 replies and nothing useable.
