HubSpot on Webflow should be loaded through GTM, where tracking, events and forms all follow the same consent mode categories.
If you want HubSpot on a Webflow site, don’t paste the tracking code into the site’s custom code. Here’s how I set it up in GTM instead.
The Cookie Banner’s Role
The banner decides what’s allowed, and GTM enforces it. HubSpot’s tracking code sets cookies, so it should only load once a visitor has agreed to the right categories.
That only works when your banner passes its choices to Consent Mode. I cover that setup in GTM Consent Mode V2 for Webflow, and the rest of this post assumes it’s in place. Turn off HubSpot’s own cookie banner for the domain so visitors don’t see two.
Load Tracking
- In HubSpot, copy your tracking code. The only part you need is your Hub ID.
- In GTM, create a Custom HTML tag with the script below.
- Under Advanced Settings > Consent Settings, choose Require additional consent for tag to fire and add
analytics_storage. Addad_storageas well if you use HubSpot’s ads tools. - Add two triggers: All Pages and the custom event your banner sends when a visitor makes a choice (
c15t_consentin my setup). - Set Tag firing options to Once per page.
<script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/YOUR_HUB_ID.js"></script>
To test it, open the site in a private window. No request to js.hs-scripts.com should appear in the Network tab until you accept in the banner.
Track Custom Behavioral Events
Custom behavioral events record site actions on the contact’s timeline in HubSpot, like a pricing page click or a video play. Create the event in HubSpot first, copy its internal name, then send it from a second Custom HTML tag:
<script>
var _hsq = window._hsq = window._hsq || [];
_hsq.push(['trackCustomBehavioralEvent', {
name: 'pe12345678_pricing_click',
properties: {
plan: '{{Click Text}}'
}
}]);
</script>
Give this tag the same consent settings as the tracking tag, and trigger it on the action you want to record. Custom events aren’t included in every HubSpot plan, so check yours before you build on them.
Add HubSpot Forms & Track Submissions
Forms are the exception: add them directly to the page in a Webflow Code Embed element, not through GTM. A form a visitor chooses to fill out shouldn’t disappear because they declined analytics.
<script src="https://js.hsforms.net/forms/embed/YOUR_HUB_ID.js" defer></script>
<div class="hs-form-frame" data-region="na1" data-form-id="YOUR_FORM_ID" data-portal-id="YOUR_HUB_ID"></div>
Older forms use the legacy hbspt.forms.create() embed. Both work in a Code Embed, but they report submissions differently, so the listener below handles both.
Add this as a Custom HTML tag in GTM on All Pages:
<script>
(function(){
window.dataLayer = window.dataLayer || [];
function push(id){
dataLayer.push({ event: 'hubspot_form_submit', hs_form_id: id });
}
// New forms
window.addEventListener('hs-form-event:on-submission:success', function(e){
push(e.detail && e.detail.formId);
});
// Legacy forms
window.addEventListener('message', function(e){
if (e.data && e.data.type === 'hsFormCallback' && e.data.eventName === 'onFormSubmitted') {
push(e.data.id);
}
});
})();
</script>
Then in GTM:
- Create a Data Layer Variable for
hs_form_id. - Create a Custom Event trigger for
hubspot_form_submit. - Add a GA4 Event tag named
generate_leadon that trigger, with the form ID as a parameter.
The GA4 tag still follows consent, so the form always works and the tracking only fires when it’s allowed.
For more on the listener approach, see HubSpot form tracking in Google Tag Manager. If your HubSpot reports look wrong after adding a cookie banner, I covered why in HubSpot consent mode attribution.