Posted on 06/11/2025 11:09:55
Hi Ferri
Here is some documentation for Clarity: https://www.youtube.com/watch?v=43U87jaDTLk
Consent mode in Clarity: https://learn.microsoft.com/en-us/clarity/setup-and-installation/consent-mode - this outlines how to signal that consent has been given.
You’re correct that Microsoft Clarity now requires explicit consent signals for users in the EEA, UK, and Switzerland. In the Swift v2 setup, this should be handled similarly to how Google Tag Manager and Consent Mode V2 are already implemented.
1. Where and how to implement
The Swift v2 cookie management logic lives in
/Files/Templates/CookieWarning/Cookies.cshtml.
This template is responsible for the full consent workflow: banner, modal, and consent category management. It already contains JavaScript functions such as setOptInCookie(), acceptCustomSetup(), and helper methods like consentGrantedAnalyticsStorage() and consentGrantedMarketing() that fire Google consent updates through gtag('consent', 'update', …) when a user accepts cookies Files/Templates/CookieWarning/C…
To integrate Microsoft Clarity, you can use the same pattern by adding a Clarity initialization call inside the appropriate consent handler:
function consentGrantedAnalyticsStorage() { if (!window.dataLayer) return; gtag('consent', 'update', { 'analytics_storage': 'granted' }); if (typeof clarity === 'function') clarity('consent'); }
or, if Clarity is loaded through its snippet:
if (typeof clarity === 'function') { clarity('consent', true); }
This ensures that the Clarity tag only activates when consent for analytics (or marketing) is granted.
2. Which template(s) to modify
-
Primary file:
/Files/Templates/CookieWarning/Cookies.cshtml – this is where the user’s opt-in level and consent logic are handled.
-
Optional inclusion point:
If your setup uses Swift-v2_Master.cshtml for analytics scripts (as it does for Google Tag Manager), ensure your Clarity script snippet is wrapped in a consent-check condition there too.
Example:
3. Best-practice pattern for Swift v2
-
Use the existing cookie categories (“Statistical”, “Marketing”) to determine when Clarity is allowed.
-
Keep the logic centralized in Cookies.cshtml for maintainability.
-
Signal Clarity consent inside consentGrantedAnalyticsStorage() (for heatmaps and session recordings).
-
Optionally, use Dynamicweb’s CookieOptInHelper if you want server-side template control in master pages.