How to integrate Microsoft Clarity Consent with HubSpot cookie banner + GTM

Hi community,
Microsoft Clarity will start requiring explicit consent signals (EEA, UK, Switzerland) by October 31, 2025.

On my site, I already have a HubSpot cookie banner connected with Google Tag Manager.
What I need is: when a user accepts/rejects cookies from that banner, the consent signal should also be passed to Clarity (via Google Consent Mode or the Clarity Consent API).

Has anyone implemented this integration directly in HubSpot + GTM?

Thanks for any guidance or code snippet

Hi @jerequis,
Thank you for posting to the Community!
I understand that you want to know how to pass user consent decisions from a HubSpot cookie banner, integrated via Google Tag Manager, to Microsoft Clarity using either Google Consent Mode or the Clarity Consent API.
I’d like to tag in some of our Top Contributors to see if they have any suggestions.
Hi @Josh @Phil_Vallender @RomyFuchs1 @HFisher7 Do any of you have ideas on @jerequis’s inquiry?
Thank you!
Cassie, Community Manager

Hi @jerequis ,
Have you managed to implement this integration? I’m hoping to do the same for our website and could use some guidance :slightly_smiling_face:
Thanks so much!

Hi! I was working with my friend Claude on this, and I also asked it to write this so it’s clear, but I’m the human in the loop, just assisted by AI, so please don’t ban this post :).

Important note, I’m still testing this, but so far I can see that it’s not activating when I reject cookies, or only accept necessary ones.

I just implemented exactly this setup. Here’s the full solution:

The setup: HubSpot cookie banner + GTM (via native HubSpot integration) + Microsoft Clarity.


Step 1 — Consent Default tag (fires first)

Create a Custom HTML tag with trigger Consent Initialization - All Pages and set priority to 10 in Advanced Settings so it fires before everything else:

<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('consent', 'default', {
 analytics_storage: 'denied',
 ad_storage: 'denied',
 functionality_storage: 'denied',
 personalization_storage: 'denied',
 wait_for_update: 500
});
</script>

``

Step 2 — HubSpot Consent Listener tag

Create a Custom HTML tag with trigger Initialization - All Pages. This listens to HubSpot's banner decision and pushes the result to the dataLayer:

<script>
var _hsp = window._hsp = window._hsp || [];
_hsp.push(["addPrivacyConsentListener", function(consent) {
 var cat = consent && consent.categories;

 var hasAnalytics = cat && cat.analytics;
 var hasAds = cat && cat.advertisement;
 var hasFunctionality = cat && cat.functionality;

 window.dataLayer = window.dataLayer || [];
 dataLayer.push({
 event: 'cookie_consent_update',
 analytics_storage: hasAnalytics ? 'granted' : 'denied',
 ad_storage: hasAds ? 'granted' : 'denied',
 functionality_storage: hasFunctionality ? 'granted' : 'denied',
 personalization_storage: hasFunctionality ? 'granted' : 'denied'
 });
}]);
</script>

Important: avoid using consent.allowed in this listener — it doesn't exist in HubSpot's API and can cause incorrect consent signals being sent regardless of what the user chose.


``

Step 3 — DataLayer Variables

Create two DataLayer Variables in GTM:

  • Name: DLV – ad_storage → DataLayer variable name: ad_storage

  • Name: DLV – analytics_storage → DataLayer variable name: analytics_storage


    ``

    Step 4 — Triggers

    Create two custom event triggers:

    • Name: EV – cookie_consent_update – ads granted

      • Event name: cookie_consent_update

      • Condition: DLV – ad_storage equals granted

      • Name: EV – cookie_consent_update – analytics granted

        • Event name: cookie_consent_update

        • Condition: DLV – analytics_storage equals granted

                  ---
          
                  ``
          
                  **Step 5 — Microsoft Clarity tag**
          
                  Use the official Microsoft Clarity template from the GTM gallery. Configure it with:
          
          • Trigger: EV – cookie_consent_update – ads granted

                            This ensures Clarity only fires when the user explicitly accepts advertising cookies. The native **Consent Settings (BETA) checkbox inside the tag is an optional extra layer of protection — if your GTM version shows it, enable it and select `ad_storage. But the trigger alone is sufficient.`**
            
                            ---
            
                            **``**
            
                            **HubSpot cookie categories → Google Consent Mode mapping:**
            
          •                 **Testing:**
                            The simplest way to validate the setup:
            
                            Open your site in an incognito window, accept all cookies → go to GA4 Real-Time report, you should appear as an active visitor
                            Open another incognito window, reject cookies → you should NOT appear in GA4 Real-Time
            
                            If step 1 shows you and step 2 doesn't, your consent implementation is working correctly.
                            **Note on Tag Assistant**: when cookies are rejected, Tag Assistant will show a connection error ("no Google tags found"). This is expected and correct — it happens because Tag Assistant needs an active Google tag to establish its debug channel, and when consent is denied, no Google tags fire. It is not a sign that something is broken.
            
                            Hope this helps!
            
                             ``
            

``