Microsoft Clarity Consent API (ConsentV2)

Microsoft Clarity records sessions and heatmaps of your visitors. If your Clarity project requires cookie consent, Clarity needs a consent signal from your site to set its cookies. Microsoft requires this signal for visits from the European Economic Area, the UK and Switzerland.

With the Premium add-on, Beautiful Cookie Banner sends this signal through the Clarity Consent API. Since add-on version 5.0.0 it uses ConsentV2, the version Microsoft recommends; the older API is being phased out.

ConsentV2 has two values, each granted or denied:

window.clarity("consentv2", {
  ad_Storage: "granted",
  analytics_Storage: "granted"
});
  • Granted: Clarity sets its cookies and connects page views across a session.
  • Denied: Clarity runs without cookies and treats each page view on its own. When a visitor withdraws consent, Clarity deletes its cookies.

Beautiful Cookie Banner sends the call in the <head> on every page with the stored choice, and again straight away when the visitor changes the choice in the banner. If both values are denied, it also sends window.clarity("consent", false), so cookies set earlier are removed.

Go to Settings > Cookie Consent Banner > Consent APIs > Microsoft Consent Mode and check Enable Claritiy Cookie Consent API.

Microsoft Clarity Configurartion
Consent APIs > Microsoft Consent Mode with the per-category option.

In Microsoft Clarity allowed for, pick the banner categories that allow Clarity. Clarity gets granted as soon as the visitor allows one of them.

If you want different categories for ad_Storage and analytics_Storage, check Microsoft Clarity: Configure per category and fill in Microsoft Clarity: Ads allowed for and Microsoft Clarity: Analytics allowed for. Without this option, both values use the same list.

The categories you can choose depend on your compliance type and your cookie categories. In the examples below, the Compliance & Behaviour tab looks like this:

Compliance & Behaviour tab of Banner 1: compliance type 'Differentiated Consent - 2 Buttons with save' and the cookie types Technical (default checked, always enabled), Marketing and Ads.

Configuration examples

The examples use the field Microsoft Clarity allowed for (one list for both values).

Example 1: technical category, always on

Compliance settings

Compliance type 'Differentiated Consent - 2 Buttons with save' with the cookie types Technical (default checked, always enabled), Marketing and Ads.

Clarity settings

Microsoft Clarity allowed for: tech.

Result

Clarity is always allowed: “tech” is “default checked” and “always enabled”, so the visitor can never switch it off.

Example 2: marketing or ads

Compliance settings

Compliance type 'Differentiated Consent - 2 Buttons with save' with the cookie types Technical, Marketing and Ads.

Clarity settings

Microsoft Clarity allowed for: marketing or ads.

Result

On the first page load Clarity is not allowed, because neither “marketing” nor “ads” is “default checked”. Clarity is allowed as soon as the visitor accepts ads or marketing cookies.

Example 3: Banner 2

Compliance settings

Banner 2 categories: Necessary (default checked, always enabled), Functionality (default checked), Analytics and Marketing.

Clarity settings

Microsoft Clarity allowed for: Functionality or Analytics.

Result

On the first page load Clarity is allowed, because “Functionality” is “default checked”. It stays allowed as long as the visitor allows “Functionality” or “Analytics”.

Example 4: Banner 1, compliance type opt-in

Compliance settings

Banner 1 with the compliance type 'Ask user to Opt-in'.

Clarity settings

Microsoft Clarity allowed for: opt-in.

Result

On the first page load Clarity is not allowed. It is allowed only after the visitor opts in.

Example 5: Banner 1, compliance type opt-out

Compare this carefully with example 4: the important difference is the compliance type.

Compliance settings

Banner 1 with the compliance type 'Ask user to Opt-out'.

Clarity settings

Microsoft Clarity allowed for: opt-in/default.

Result

On the first page load Clarity is allowed, because with the compliance type “opt-out” every visitor counts as opted in until they opt out. Clarity stays allowed until the visitor opts out.

How to test

Open your site in a private browser window. Every time the Clarity consent is set, the plugin also pushes an event to the Google dataLayer. Type this in the browser console:

dataLayer

and look for the entry with event: "clarity_consent_update". Its value clarityAllowed is true or false.

Browser console showing the dataLayer entry with the event clarity_consent_update.

You can also look at the queue that the Clarity script reads:

window.clarity.q

It contains the consentv2 call with the current ad_Storage and analytics_Storage values (once the Clarity script has loaded, it processes the queue).