The Super Easy Way to Track Hubspot Forms in Google Tag Manager and Analytics
When I first tried to track Hubspot forms in Google Tag Manager, it was confusing.
But after spending a few minutes with it, there’s actually a super simple way to track each form uniquely. In order to do this properly, we’re assuming a couple things:
- You’re using Hubspot Forms embedded on your site (not another integration like Gravity forms, etc.)
- You’re using Google Analytics
- Google Analytics is firing from within Google Tag Manager
Now, let’s get started.
Turning on the Variables
First thing, is we need to make sure we have access to the proper variables in Google Tag Manager.
So log into Tag Manager, click the tag you want, then go to “Variables” on the left hand side. Select Configure. Then select all the “click” elements and all the “form” elements.
Hit save.
Enabling the Trigger
Next, you need to create the “trigger” that will actually fire the tag (that we’ve not yet created).
Go to “Triggers” in Google Tag Manager and create a new one.
For the Type, set it to “Form Submission”.
Under the heading “This trigger fires on”, select “Some Forms”.
For the conditions, I recommend setting as follows:
- Click ID
- Contains (although, “exactly matches” can work if you just want to track that form exactly)
- The unique Hubspot form ID
Getting the Click ID from Hubspot
This is the most complicated part of the procedure, but it’s actually quite simple.
First, go to your webpage where the Hubspot form is embedded.
Right click on the form (in Chrome) and select “Inspect”.
Now you’ll see a bunch of code.
Don’t be intimidated.
We’re simply looking for a string that contains “hsForm_xxxxx…”.
This number is actually in 4-5 spots around the page in both the HTML and CSS. Just make sure it starts with “hsForm_” and you should be good to go.
Now find that whole string (including the “hsForm_” intro and all the letters and numbers) and copy that into your Google Tag Manager Trigger.
Note: If you’re trying to track ALL hubspot forms (instead of just a single form) with a single trigger, you can just set the click ID to “contains” and then put only “hsForm_” without any of the following numbers or letters. Then it will fire whenever an hsForm event occurs.
Now save the trigger. It’s finished.
Setting the Tag
Now you need to actually create the Google Analytics Tag.
Create a new tag using “Google Analytics – Universal Analytics” settings.
Here is what needs to be set:
- Track Type: Event
- Category: Whatever you want (this gets put into Google Analytics)
- Action: Submit (or whatever you want)
- Label: Whatever you want
- Google Analytics Settings: Likely this is already set up, so just select past GA settings. Or you’ll need to add your UA code here if not. But just make sure it’s firing to the right Google Analytics account (yours!)
Linking the Tag to the Trigger
Now, you just link the tag to the trigger you previously created.
Testing
There are two ways to test this. I recommend doing both. First, set Google Tag Manager to “Preview” mode. Refresh the page on your website and submit the form.
Under “tags fired” you should see your tag. That means that it’s firing.
If you don’t see it, you likely have a problem with the trigger. Double check the hsForm code and other settings on that page.
If it fires, you’re in good shape.
Now login to Google Analytics. Go to Real Time > Events.
Now, in an incognito window (without any ad or tracking blockers installed), submit the form again.
It should fire as an event and you should see it pop-up within 10 seconds of submitting the form.
If it doesn’t, you likely have an error in your tag settings. Check your UA code and other settings to make sure it’s firing properly.
To get more great tutorials like this one, you should join our Google Analytics course. We do a deep dive into Google Analytics and cover a good bit of Google Tag Manager as well.
Wrap-Up
Now that the event is getting put into your Google Analytics account, you can track Hubspot form submits. If you’re using that as a goal completion, you can go into Goals and set up a new goal based on the event firing.
But now you know when someone submits a Hubspot form within Google Analytics. This will help enrich your Google Analytics data and make better business decisions.
P.S. Get more awesome content like this weekly by subscribing to our blog. We seek to provide massive value and respect you deeply. We won’t spam you.