Analytics
Microsoft Clarity
Configure Microsoft Clarity
Copy the project ID from your Clarity tracking code, where it follows
https://www.clarity.ms/tag/. The helper builds the loader URL from it.
Register the scripts
Complete your framework quickstart first. Keep its Inth endpoint, policy, styles and consent UI. Remove the vendor's original script, SDK initializer or tag-manager entry, so the vendor loads only through c15t.
The vendor pages put the helper in src/consent-scripts.ts. If your framework
quickstart already has a scripts array, such as the one in c15t.config.ts
in the Next.js guide, add the helper to that array instead of creating a
second file.
The scripts export is a configuration, not an initializer. Add it to the c15t provider you already have, at the registration
point for your framework below. These are edits to that provider, not a second
provider.
Add the configuration to scripts in c15t.config.ts, next to
next.config.ts:
Keep the rest of your config, such as mode and routePrefix, in the
same call. ConsentRoot reads the config in the browser, so the layout
keeps passing only state. App Router, Pages Router and static export all
read the same file. See
Next.js scripts and embeds.
Options
| Option | Default | Behavior |
|---|---|---|
id | Required | Clarity project ID. Surrounding whitespace is trimmed. Unless you set scriptUrl, an empty ID logs an error and the script does not load. |
defaultConsent | c15t state | Consent V2 value queued once, before the loader. true or false sets both channels. An object sets ad_Storage or analytics_Storage, also accepted as marketing and measurement; channels you leave out follow c15t. Later updates always follow c15t. true grants ad storage even while marketing is denied. |
scriptUrl | https://www.clarity.ms/tag/<id> | Loader URL override. |
Loading and revocation
clarity uses the measurement category, so Clarity loads only while
measurement is allowed. Before the loader runs, the helper queues
clarity('consentv2', ...) with analytics_Storage taken from measurement and
ad_Storage taken from marketing. While Clarity is on the page, every
permission change sends a new consentv2 call, so allowing marketing later
grants ad_Storage without reloading Clarity.
On measurement revocation the helper keeps the Clarity script and sends
consentv2 with analytics_Storage set to denied. If the visitor allows
measurement again before the page reloads, it sends granted. A visitor who
turns off the microsoft-clarity vendor gets both channels denied. Denied
storage limits what Clarity stores; it does not mean Clarity sends no requests.
See Microsoft's
Consent V2 API.
Verify Microsoft Clarity
Allow only marketing first. Clarity does not load, because it waits for
measurement. Then allow measurement. The request to
www.clarity.ms/tag/<id> appears without a page reload.
Test in a private window with an opt-in policy. Open DevTools Network, disable the cache and filter by the vendor's domain:
- Load the page. No request goes to the vendor before you choose.
- Click Reject, then reload. There is still no vendor request.
- Open Privacy settings and allow the helper's category. The vendor script loads without a page reload.
- Turn the category off again and save. c15t reloads the page, and the new page makes no vendor request.
c15t reloads on revocation because removing a script element does not stop
code that already ran. The vendor's listeners, timers and queued events stay
alive until the page unloads. If you set reloadOnConsentRevoked: false, stop
the vendor yourself. Register a callback-only script whose onConsentChange
calls the vendor's opt-out API, as shown in
custom integrations, and check the
permission before each of your own event calls. The reload does not delete
cookies the vendor already set; see
clear on revocation for your framework.
The helper sets vendor to its script ID, so once you declare that vendor a
visitor can turn it off inside an allowed category. See
vendor consent for your framework. The
consent verification guide covers navigation,
expiry and hosting checks.