Last Updated:
December 4, 2023

How to integrate HubSpot and Google Tag Manager the right way

A step-by-step explanation for setting up HubSpot and Google Tag Manager so that your form data tracking is accurate and reliable.

How to integrate HubSpot and Google Tag Manager the right way

Do you use HubSpot for marketing automation and Google Tag Manager (GTM) to integrate tools like Google Ads and Analytics? If yes, keep reading.

Here, we'll explain the steps to set up HubSpot and GTM so that your data tracking is both accurate and reliable, right from our internal documentation here at Revstac. When you're ready, automatically generate the code you'll need with the HubSpot Tag Builder.

Let's start with a brief overview of these tools:

  • HubSpot is (among other things) a marketing automation platform. One of its core features is forms. This guide focuses forms — and how they talk to other tools.
  • Google Tag Manager is a tag management system. It's basically the bridge between your website and digital marketing tools such as Google Ads, Analytics, and Instagram Ads. This guide focuses on collecting form data from HubSpot and passing it to these other tools by way of Google Tag Manager.

Step 1: Install the HubSpot tracking code

If you're already using HubSpot, you've probably already done this. The HubSpot tracking code is essential for sending website traffic data to HubSpot. You can install this code in various ways, including through Google Tag Manager. Follow the steps provided in this HubSpot support document for guidance.

Step 2: Track form submissions

First, set up a tag that "listens" for form submissions in GTM. This lonely chunk of code sits in the background of every page, waiting to jump into action when a user submits a HubSpot form.

Create a tag named “HubSpot Form Listener”. Set the Tag Type to Custom HTML and paste the following code:

See the Pen Untitled by Daniel Wheeler (@Daniel-Wheeler-the-decoder) on CodePen.

Set the Firing Triggers to 'All Pages', the default option

Screenshot of the "HubSpot Form Listener" tag
Screenshot of the "HubSpot Form Listener" tag

Okay, great. Next, create a form submission trigger. When somebody submits a form, this trigger will fire. All your other tools that need to know about form submissions — like Google Ads and Meta Ads — will reference this trigger.

Add a trigger named “HubSpot Form Submission”. In Trigger Configuration, select Custom Event and set Event Name to hbsptFormSubmit. Set it to fire on all custom events.

Screenshot of the "HubSpot Form Submission" trigger

Step 3: Passing form field data to other tools

In cases where specific form field data needs to be sent to GTM (e.g., a “Number of Employees” field influencing a Google Ads Conversion), follow these steps:

First, you'll need to update the code in your HubSpot Form Listener Tag (see step 2) with the fields you'd like to track. Add each field's internal name in HubSpot. In this case, we've added numemployees, the internal name for our “Number of Employees” field.

Screenshot of the updated "HubSpot Form Listener" Tag

No need to fret about getting this code exactly right. We built a free tool to generate it for you.

Next, you'll create a new variable for each field.

To do this, add a new User-Defined Variable, like “Number of Employees”. Set Variable Configuration to Data Layer Variable and link it to the corresponding internal property name in HubSpot.

Screenshot of a form field variable for a "Number of Employees" field

Now, this variable can used in Tags and Triggers. For instance, you can create a trigger for form submissions where “Number of Employees” is over a certain threshold, and link this to a Google Ads Conversion tag.

These steps form the basic framework for integrating HubSpot with GTM, enabling consistent tracking across various marketing tools.

Get in touch

Want to learn more? Let's get in touch.