Working with HubSpot in Webflow

How to configure HubSpot on a Webflow site through GTM, with consent mode, custom behavioral events and form tracking.

  • Load HubSpot on Webflow through Google Tag Manager (GTM), not by pasting the tracking code into Webflow's custom code, so tracking, events and forms all follow the same consent mode categories.
  • Your cookie banner decides what's allowed and GTM enforces it. This requires the banner to pass visitor choices to Consent Mode V2, and you should turn off HubSpot's own cookie banner to avoid showing two.
  • For the tracking script, create a Custom HTML tag with your Hub ID, require analytics_storage consent (add ad_storage if you use HubSpot's ads tools), and trigger it on All Pages plus your banner's consent event, set to fire once per page.
  • Verify the setup in a private window: no request to js.hs-scripts.com should appear in the Network tab until the visitor accepts in the banner.
  • Custom behavioral events (like pricing clicks or video plays) are sent from a second Custom HTML tag with the same consent settings. Create the event in HubSpot first and check that your plan supports custom events.
  • Add HubSpot forms directly in a Webflow Code Embed, not through GTM, so forms still work when a visitor declines analytics.
  • Track form submissions with a single GTM listener tag that handles both new and legacy HubSpot embeds, pushes a hubspot_form_submit event to the dataLayer, and triggers a consent-aware GA4 generate_lead event, so the form always works and tracking fires only when allowed.

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 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

  1. In HubSpot, copy your tracking code. The only part you need is your Hub ID.
  2. In GTM, create a Custom HTML tag with the script below.
  3. Under Advanced Settings > Consent Settings, choose Require additional consent for tag to fire and add analytics_storage. Add ad_storage as well if you use HubSpot’s ads tools.
  4. Add two triggers: All Pages and the custom event your banner sends when a visitor makes a choice (c15t_consent in my setup).
  5. 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:

  1. Create a Data Layer Variable for hs_form_id.
  2. Create a Custom Event trigger for hubspot_form_submit.
  3. Add a GA4 Event tag named generate_lead on 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.