Hotjar 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 snippet from Hotjar below the banner snippet. The banner holds the recognised Hotjar loaders until the visitor allows Site Optimisation, in regions whose rule requires consent first.

You need #

Where it goes #

Paste the snippet from Hotjar below the banner snippet. Keep the Cookie Compliance snippet as the first script in <head>; the Hotjar code stays under it. Shape (paste Hotjar's own snippet; it names the addresses below):

<!-- Cookie Compliance snippet first, then Hotjar's snippet: -->
<script>
  /* Hotjar's tracking code — loads static.hotjar.com / script.hotjar.com */
</script>

What the order controls #

The banner recognises static.hotjar.com and script.hotjar.com and holds them under category 3 Site Optimisation by default. The whole inline block is held when it names that address. In regions whose rule requires consent first, the snippet 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 Hotjar snippet after it. Before choosing, in a region whose rule requires consent first, the held script shows type="javascript/blocked" in the Elements panel. After Allow, the script runs. Browser checks: plain-html; full procedure: verify-install.

Gotchas #

More help #