Microsoft Clarity Consent Mode Integration with UniConsent CMP

Microsoft Clarity is a free behavioral analytics tool that uses heatmaps and session recordings to help you understand how users interact with your website. Clarity Consent Mode lets you adjust Clarity's behavior based on individual user consent preferences, ensuring compliance with data protection regulations such as the GDPR.

Clarity does not set cookies until it receives a valid consent signal. When consent is granted, Clarity sets first-party and third-party cookies to track users across sessions. When consent is not received, Clarity operates in cookieless mode with limited features.

Important: Starting October 31, 2025, Clarity enforces consent signal requirements for page visits originating from the European Economic Area (EEA), United Kingdom (UK), and Switzerland (CH). A valid consent signal is required for full functionality of Clarity features for users from these regions. Consent Mode is enabled by default for these users.

How it works

Clarity Consent Mode uses two independent consent types:

PermissionData Use
analytics_StorageAnalytics-related data (user behavior, usage, and interaction patterns).
ad_StorageAds-related data (retargeting, conversions, and campaign performance).

Each permission can be set to granted or denied. The permissions are independent of each other, and Clarity operates correctly with any combination of consent values.

The keys ad_Storage and analytics_Storage are case sensitive. Accepted values are granted or denied in lowercase.

The following cookies are written only when the corresponding permission is granted:

analytics_Storage=grantedad_Storage=granted
_clck (first-party)MUID
_clsk (first-party)

To integrate Microsoft Clarity with UniConsent CMP, follow these steps to ensure compliance with user consent preferences:

In your Clarity dashboard, select the project and go to Settings → Setup, then turn off the option to set cookies by default. This ensures Clarity waits for a valid consent signal before setting any cookies. (Consent Mode is already enabled by default for EEA, UK, and Switzerland traffic.)

2. Load the Clarity script

The Clarity script should be loaded as early as possible during page load, regardless of consent status. Clarity functions correctly across all Consent Mode configurations and automatically adapts its behavior based on the consent signals it receives.

We recommend placing the consent script in your <head> tags so that the consent mode is set by default and updated when a user changes their consent settings. Calls are added to a queue in case the Clarity script has not yet loaded.

// Clarity tag is added here
// You can set default consent mode right after the Clarity tag
<script>
window.clarity = window.clarity || function () {
    (window.clarity.q = window.clarity.q || []).push(arguments);
};
window.clarity('consentv2', {
    'ad_Storage': 'denied',
    'analytics_Storage': 'denied'
});
</script>

4. Set Up UniConsent CMP on your site

UniConsent CMP automatically sends consent signals to Microsoft Clarity using the Consent API V2 (consentv2), ensuring compliance with user privacy preferences. It maps analytics or statistics purposes to analytics_Storage and marketing or advertising purposes to ad_Storage, updating Clarity's consent state whenever a user accepts, rejects, or makes granular choices.

5. Verify your implementation

To confirm consent is being passed correctly, open your browser developer tools, go to the Console tab, and run:

clarity('metadata', (d, upgrade, consent) => {
    console.log('consentStatus:', consent);
}, false, true, true);

Before a user accepts cookies, you should see both permissions denied:

{
    analytics_storage: "DENIED",
    ad_storage: "DENIED"
}

After the user accepts in the UniConsent CMP banner, the values update accordingly (for example, both "GRANTED"). You can also confirm that no _clck or _clsk cookie is written while consent is denied.

References: