MicrosoftFrameworkMicrosoft Clarity consent integration

Microsoft Clarity Consent API v2

Keep session recordings, heatmaps and user behaviour tracking in Microsoft Clarity running — fully consent-aware, with CookieHub as your CMP.

Built-in CookieHub support · HTML and GTM compatible
Consent stateregion: euapi: consentv2state: updatedVisitor choiceanalytics acceptedCookieHubcategory → parameterMicrosoft Clarityclarity consentv2analytics_Storagegrantedad_Storagedenied
Type
Consent API
Works with
Microsoft Clarity
Parameters
analytics_Storage and ad_Storage
Required in
EEA, UK and Switzerland
CookieHub support
Built in, from 2.8.12
Overview

What the Clarity Consent API v2 actually does.

The Clarity Consent API v2 lets a website tell Microsoft Clarity what the visitor has agreed to — a necessity in privacy-first environments. Clarity reads two consent states, one for analytics storage and one for advertising storage, and adjusts its tracking to match.

Without valid consent, Clarity disables cookie-based tracking, session linking and cookie persistence for visitors in the EEA, the UK and Switzerland. With consent granted, full session tracking, heatmaps, funnels and analytics resume — so Clarity follows the visitor’s consent choices and you keep your insight into user behaviour.

CookieHub collects the visitor’s choice and passes it to Clarity from the CMP layer, so you don’t handle the logic or timing yourself.

Page lifecyclewindow.clarity
  1. 01Page loadsclarity tag
  2. 02Clarity starts in no-consent modedenied by default
  3. 03Visitor makes a choicebanner
  4. 04CookieHub calls consentv2consent update
  5. 05Clarity sets cookies or stays cookielesstracking mode
Signal flow

From visitor choice to Microsoft Clarity.

Pick a visitor state to see the consent states CookieHub passes to Clarity.

Visitor state
Visitor choiceNo choice yet

The visitor has arrived and the banner is showing. Clarity waits in no-consent mode.

CookieHubLeaves Clarity on its defaultconsent mode: onregion: eustored: no
Microsoft Claritydefaultanalytics_Storagedeniedad_Storagedenied
Visitor choiceAnalytics accepted

The visitor accepted analytics but not marketing.

CookieHubCalls consentv2call: consentv2category: analyticsstored: yes
Microsoft Clarityupdatedanalytics_Storagegrantedad_Storagedenied
Visitor choiceAll cookies accepted

The visitor accepted both analytics and marketing.

CookieHubCalls consentv2call: consentv2category: allstored: yes
Microsoft Clarityupdatedanalytics_Storagegrantedad_Storagegranted
Visitor choiceAll declined

The visitor declined, or withdrew an earlier choice.

CookieHubKeeps both states deniedcall: consentv2category: nonestored: yes
Microsoft Clarityupdatedanalytics_Storagedeniedad_Storagedenied

Illustrative signal behaviour for one configuration. Actual behaviour depends on the site’s consent configuration and the visitor’s region.

Consent parameters

The two states Clarity listens for.

Every consentv2 call carries both parameters. CookieHub fills each one from a cookie category.

ParameterPurposeCookieHub categoryExample state
analytics_StorageAnalytics storage: Clarity’s cookies, session linking and returning-visitor recognition.Analyticsgranted
ad_StorageAdvertising storage: whether Clarity shares data with Microsoft Ads.Marketingdenied
Preferences isn’t used by Clarity, and Necessary is always allowed. The example states show a visitor who accepted analytics but not marketing.
Consent states

What Clarity does in each state.

analytics_Storage decides whether Clarity can use cookies — the signal that keeps recordings, heatmaps and funnels connected.

analytics_Storage
  • granted

    Full session tracking

    • Clarity sets its cookies, such as _clck and _clsk.
    • Page views are linked into sessions and returning visitors are recognised.
    • Session recordings, heatmaps and funnels work as configured.
    analytics_Storage: granted
  • denied

    No-consent mode

    • Clarity sets no cookies.
    • Each page view gets its own ID, so sessions aren’t linked.
    • Recordings, funnels and other cookie-based features may be limited.
    analytics_Storage: denied

ad_Storage works alongside it: granted lets Clarity share data with Microsoft Ads, denied shares none. If a visitor withdraws consent, Clarity deletes its cookies, ends the session and continues in no-consent mode.

CookieHub + Clarity

Your Clarity consent solution, built in.

User-friendly and future-ready: CookieHub maps every choice to Clarity’s parameters across CMSs, Google Tag Manager or custom environments.

See how consent management works
01Configure once
  • Clarity integration

    settings → integrations

    Turn on Clarity Consent API v2 under Integrations in your domain settings.

  • Category mapping

    category → parameter

    Analytics feeds analytics_Storage, Marketing feeds ad_Storage.

  • Region-aware banner

    region rules

    Show the banner where consent is required, such as the EEA, the UK and Switzerland.

02CookieHub manages the state
Default stateno consentVisitor choicereceivedconsentv2 callsent
  • Real-time updates

    consent update

    Signal Clarity again when the visitor changes or withdraws a choice.

  • Scanning and blocking

    scan · block

    Scanning finds cookies on your site; supported services can be blocked automatically, others may need manual configuration. Don’t use automatic blocking with GTM.

  • Consent records

    consent log

    Keep an audit log of consent decisions once consent records are enabled. Availability depends on your CookieHub plan.

03Clarity receives the right state
Clarity consent stateexampleanalytics_Storagegrantedad_Storagedenied
  • HTML or GTM

    html · gtm

    Works with the CookieHub script in the page head or the CookieHub CMP template in GTM.

The Clarity consent state shown is an example of one configuration.
Implementation

Set up the Clarity Consent API v2.

Three phases, from adding CookieHub to confirming the consent state Clarity holds.

  1. 01

    Connect

    Add CookieHub to the site, directly or through Google Tag Manager.

    1. 01Add the CookieHub script to the page head, or the CookieHub CMP template in GTM.
    2. 02Use CookieHub 2.8.12 or later.
  2. 02

    Configure

    Turn on consent in Clarity and the integration in CookieHub.

    1. 03Set your Clarity project to require cookie consent.
    2. 04Turn on Clarity Consent API v2 under Integrations in the Settings tab.
    3. 05Categorise Clarity’s cookies as analytics, not necessary.
    4. 06Save and publish.
  3. 03

    Verify

    Confirm that Clarity receives the expected state.

    1. 07Run Clarity’s consent check in the browser console.
    2. 08Decline, then confirm no _clck or _clsk cookie is set.
    3. 09Accept, then confirm analytics_Storage is granted.
    verifiedRecheck when tags or consent settings change.
Google Tag Manager

Running Clarity through GTM?

Load CookieHub with its community template, and Clarity receives the consent state before it starts tracking.

  • Add the CookieHub CMP tag from the Community Template Gallery.
  • Enter your CookieHub domain code.
  • Set the trigger to Consent Initialization – All Pages.
  • Turn on Clarity Consent API v2 in CookieHub, then save and publish.
Container viewconceptualGTM containergtm-xxxxxxCookieHub CMP templateconsent initialization
  • Clarity trackinganalytics_Storage
  • Microsoft Ads sharingad_Storage
  • Other consent-aware tagsconsent state
Verify your setup

Is the Clarity Consent API working on your site?

Check the consent state Clarity holds before and after the visitor chooses. Microsoft documents these checks for Clarity.

  1. 01

    Console check

    clarity('metadata', …)

    In the browser console, run clarity('metadata', (d, upgrade, consent) => { console.log('consentStatus:', consent); }, false, true, true) and read consentStatus before and after the visitor chooses.

  2. 02

    Cookie check

    _clck · _clsk

    Clear cookies, decline on the banner and confirm Clarity still runs but sets no _clck or _clsk cookie.

  3. 03

    Project setting

    clarity settings

    Confirm your Clarity project requires cookie consent — the Consent API only takes effect when it does.

Compatibility

Works with Clarity and the tools around it.

CookieHub passes the consent state Clarity reads, on its own or alongside your Microsoft and Google tags.

  • Microsoft Clarityconsentv2
  • Microsoft Advertisingad_Storage
  • Microsoft UETuet consent mode
  • Google Tag Managercookiehub template

Listed by Microsoft as a supported CMP.

Microsoft’s Clarity documentation lists CookieHub among the consent management platforms that pass consent to Clarity automatically. CookieHub supports the Clarity Consent API v2 from version 2.8.12 and maintains compatibility as Clarity and privacy rules evolve.

FAQ

FAQ about the Clarity Consent API v2.

The Clarity Consent API v2 is Microsoft’s JavaScript consent interface for Clarity. It replaces the older window.clarity('consent') API and passes separate consent states for advertising and analytics — ad_Storage and analytics_Storage — through window.clarity('consentv2', …).

Since 31 October 2025, Clarity enforces consent signals for traffic from the EEA, the UK and Switzerland. Without a valid consentv2 signal, Clarity runs without cookies for those visitors, and features such as session linking, funnels and recordings may be limited.

Clarity listens for the window.clarity('consentv2', …) call with the visitor’s consent states. CookieHub makes that call when the visitor interacts with the banner, and Clarity adjusts its tracking: it either enables cookies, session linking and full analytics, or keeps them off.

Any website that uses Microsoft Clarity and reaches visitors in the EEA, the UK or Switzerland needs it to keep full Clarity functionality. Without it, Clarity still runs, but session linking and advanced features degrade.

It preserves session continuity, heatmaps, funnels and detailed user journeys for visitors who consent, in a privacy-aware way. The two states are separate, so analytics can still run when a visitor withholds advertising consent.

Mainly the EEA, the UK and Switzerland, where explicit prior consent is required for non-essential cookies such as analytics and advertising storage. Clarity has enforced this there since 31 October 2025. Elsewhere, a consent-aware setup still improves transparency and future-proofs your analytics.

No. The Clarity Consent API v2 aligns Clarity’s behaviour with consent signals, but compliance depends on your overall consent strategy, records, legal notices and user choices. CookieHub provides the infrastructure — banner, scanning, blocking and, depending on your plan, consent records — while you manage policy, disclosures and governance.

Clarity sets no cookies and gives each page view its own ID, so page views aren’t linked into sessions. If a visitor withdraws earlier consent, Clarity deletes its existing cookies, ends the session and continues in no-consent mode.

Yes, from version 2.8.12. Turn on Clarity Consent API v2 under Integrations in your domain settings and CookieHub sends the signals automatically, mapping Analytics to analytics_Storage and Marketing to ad_Storage. Versions 2.8.8 to 2.8.11 support only Clarity’s original consent API.

Run clarity('metadata', …) in the browser console with the callback Microsoft documents to log consentStatus before and after a choice, and check that no _clck or _clsk cookie is set after a visitor declines. Your Clarity project must also be set to require cookie consent.

If you use Microsoft Clarity for visitors in regions with privacy laws, such as the EEA, the UK and Switzerland, yes — to keep full tracking features. If you don’t have visitors from those regions, a consent-aware approach is still recommended.

Legal note

Disclaimer

This page describes how consent signals are passed to Microsoft Clarity. It is technical guidance, not legal advice, and it does not describe every possible configuration — which consent model applies to your visitors depends on the regulations relevant to your site.

Microsoft Clarity Consent API

Clear insights that respect consent.

Connect CookieHub to Microsoft Clarity to respect user consent while keeping powerful behaviour insights — see how visitors use your site within the limits of the consent they give.

  • 14-day trial
  • No card required