Microsoft Clarity with Cookie Compliance

Cookbook · guide Last verified View raw markdown (for agents)

In short: keep the Cookie Compliance snippet as the first script in <head>, then paste the Clarity snippet below it. The banner holds the recognised Clarity loader until the visitor allows Ad Personalisation, in regions whose rule requires consent first.

You need #

Where it goes #

Microsoft's docs say to paste Clarity into the <head>. With Cookie Compliance installed, keep the banner snippet first, then paste Clarity below it.

Paste the tracking code exactly as the Clarity portal gives it. It is an inline block that loads Clarity's tag from clarity.ms/tag/, which is the address the banner recognises.

What the order controls #

The banner recognises clarity.ms/tag/ and /clarity.js and holds them under category 4 Ad Personalisation by default. The whole inline block is held when it names that address. In regions whose rule requires consent first, Clarity waits until the visitor allows that category; it starts after Allow. A script placed above the banner snippet runs straight away.

Confirm the result #

View the page source: the banner snippet comes first in <head>, the Clarity snippet after it. Before choosing, in a region whose rule requires consent first, _clck and _clsk are absent; the held script shows type="javascript/blocked" in the Elements panel. After Allow, those cookies appear. Browser checks: plain-html; full procedure: verify-install.

Gotchas #

More help #