When using Microsoft Clarity in a region where users need to opt in to placing cookies in their browser, you must call the Microsoft Clarity Consent API to indicate that the user has given permission to be tracked using cookies.
Starting October 31, 2025, Clarity begins enforcing 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 to ensure full functionality of Clarity features for users in these regions.
To ensure compliance, you can pass the consent state from Termly CMP to Microsoft Clarity. This ensures that Clarity properly respects the user’s consent preferences and continues to function as intended.
The example below demonstrates how you can send the user's consent state on any page to Clarity.
Usage
<script>
function onTermlyLoaded() {
Termly.on("consent", (data) => {
console.log("Termly Consent Data:", data);
const state = data?.consentState;
const ad_Storage = state?.advertising ? "granted" : "denied";
const analytics_Storage = state?.analytics ? "granted" : "denied";
// Enable this comment for Checking
// console.log(`Ad Storage: ${ad_Storage}`);
// console.log(`Analytics Storage: ${analytics_Storage}`);
if (state) {
window.clarity("consentv2", {
ad_Storage: ad_Storage,
analytics_Storage: analytics_Storage,
});
} else {
console.log("Clarity tracking disabled due to missing consent.");
window.clarity("consentv2", {
ad_Storage: "denied",
analytics_Storage: "denied",
});
}
});
}
</script>
<script
type="text/javascript"
src="https://app.termly.io/resource-blocker/{UUID}?autoBlock=on"
onload="onTermlyLoaded()"
></script>The function inside the first <script> tag executes once the Termly Consent Banner script has loaded. It listens for the "consent" event and checks whether the user has granted permission for analytics and advertising cookies before enabling Microsoft Clarity tracking.
- If advertising cookies are accepted, window.clarity("consentv2") is called and ad_Storage is granted
- If analytics cookies are accepted, window.clarity("consentv2") is called and analytics_Storage is granted
You can modify this logic by inspecting the data object returned by the function to check for other consent categories before allowing Clarity tracking.
Related Resources
Cookie Consent API - ConsentV2
Getting Consent State and Handling Consent Changes with Termly