Skip to main content

Integrate the Microsoft Clarity Consent API

Written by Alexandre Dias Da Silva

Microsoft Clarity is a powerful tool for analyzing user behavior. However, due to regulatory changes, it is crucial to adapt its implementation to ensure compliance.

In December 2024, Microsoft shared an important update regarding Clarity. By early 2025, websites using Clarity in the EEA, United Kingdom, and Switzerland will need to obtain explicit user consent before placing cookies.

By following the procedure below, you will:

  • configure Clarity to not collect user data by default.

  • add additional code to enable control of Clarity tracking based on the consent choices expressed by the visitor through your cookie banner.

Step 0: Prerequisites

Before continuing, make sure Microsoft Clarity is listed in your Axeptio cookie banner.

If not, consult our guide here to fix it: How do I add a cookie to my widget?

Step 1: Disable cookies in Clarity

By default in Clarity, visitor tracking via cookie placement is enabled.

To disable cookies, go to Settings > Configuration > Advanced Settings, then uncheck Cookies.

Step 2: Add code to your site

Our example code below allows you to link the choices made by your visitors in your Axeptio cookie banner to Clarity's consent API:

<script>  void 0 === window._axcb && (window._axcb = []); // Axeptio initialization  window._axcb.push(function (axeptio) {          // Retrieving cookie choices    axeptio.on("cookies:complete", function (choices) { // Triggered after user choices      if (choices.clarity) {                      // If Clarity is accepted        window.clarity('consent');               // Start Clarity tracking      } else {                                   // Otherwise        window.clarity('consent', false);        // Disable tracking      }    });  });</script>

You can add this code in several ways, such as:

  • hardcoded in the <head> of your site.

  • via Google Tag Manager, in a custom HTML tag: use the "Consent Initialization - All Pages" trigger to ensure this script is executed before any other service.

Step 3: Test

Follow the steps below to confirm that Clarity is not placing cookies on your visitors' browsers:

  1. Clear the cookies from your website.

  2. Access your website.

  3. Reject cookies via your Axeptio banner.

  4. Make sure Clarity has been loaded properly (check the calls to /collect).

  5. Check the cookies in your browser and confirm there are no entries for _clck or _clsk.


By following these steps, your site will be compliant with the new regulatory requirements, while continuing to benefit from the advanced features of Microsoft Clarity.

For more information, consult the official Microsoft Clarity documentation:

Did this answer your question?