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 setting cookies.

By following the procedure below, you will:

  • configure Clarity to not collect user data by default.

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

Step 0: Prerequisites

Before proceeding, ensure that Microsoft Clarity is included in your Axeptio cookie banner.

If not, please consult our guide here to fix this: 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 website

Our code example 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) {          // Retrieve 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:

  • directly in the <head> of your website.

  • 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 does not set cookies on your visitors' browsers:

  1. Clear cookies from your website.

  2. Access your website.

  3. Refuse cookies via your Axeptio banner.

  4. Ensure that Clarity has been loaded (check calls to /collect).

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


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

For more information, see the official Microsoft Clarity documentation:

Did this answer your question?