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