Tags and pixels with Cookie Compliance

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

In short: add each tag below the Cookie Compliance snippet in the same <head>, exactly as its vendor gives it to you. Tags the banner recognises wait for the visitor's choice, in regions whose rule requires consent first. For a tag it does not recognise, add your own pattern in Autoblocking, or mark the script.

You need #

How each tag is held #

Both banner engines recognise the tags below by the address of the script file. In regions whose rule requires consent first, a recognised tag waits until the visitor allows its category: 1 Basic Operations, 2 Content Personalisation, 3 Site Optimisation, 4 Ad Personalisation. The category shown is the built-in default. You can file any tag under a different category with your own Autoblocking pattern or a data-hu-category mark.

Tracker Recognised by the built-in list Default category How to add it
GA4 (gtag) Yes: the googletagmanager.com loader, gtag/js or gtm.js 2 Paste Google's snippet below the banner snippet, unchanged.
Google Ads Yes: the same googletagmanager.com loader, and the googleadservices.com/pagead/conversion files (conversion.js, conversion_async) 2 for the loader, 4 for the conversion files Paste the Ads tag below the banner snippet, unchanged.
Meta Pixel Yes: connect.facebook.net (fbevents.js) 4 Paste the Pixel code below the banner snippet. The whole inline block is held, because it names that address.
Hotjar Yes: static.hotjar.com and script.hotjar.com 3 Paste the Hotjar snippet below the banner snippet. The whole inline block is held, because it names that address.
Microsoft Clarity Yes: clarity.ms/tag/ and /clarity.js 4 Paste the Clarity snippet below the banner snippet. The whole inline block is held, because it names that address.
LinkedIn Insight Tag Yes: the insight.min.js loader (lms-analytics/insight.min.js) 3 Paste the Insight Tag below the banner snippet, in <head> or where LinkedIn places it. The whole inline block is held, because it names that address.
TikTok Pixel Yes: analytics.tiktok.com 4 Paste the Pixel code below the banner snippet. The whole inline block is held, because it names that address.
Matomo Yes, for a script file named matomo.js (self-hosted or Matomo Cloud) 3 Load matomo.js with a normal <script src> below the banner snippet. Matomo's standard inline snippet builds the file name in pieces, so mark it: class="hu-block" data-hu-category="3".

A tracker file with a different name (for example piwik.js, or a Matomo Tag Manager container) is yours to name: add its address as your own pattern in Autoblocking, or mark the script, as in the next section.

Marking a script yourself #

To choose the category of any script, inline or external, add class="hu-block" and data-hu-category with the category number:

<script class="hu-block" data-hu-category="3">
  /* the tag's own inline code */
</script>

data-hu-category on its own is enough to mark a script; hu-block on its own marks it as category 2. A script marked data-hu-category="1" is essential and runs straight away.

Where it goes #

  1. Keep the Cookie Compliance snippet as the first script in <head>.

  2. Put each tag below it, in the same <head> (or wherever the vendor places it, as long as it is below the banner snippet), as the vendor gives it to you:

    <head>
      <!-- Cookie Compliance: first script on the page -->
      <script>var huOptions = { "appID": "YOUR_APP_ID", "currentLanguage": "en", "blocking": true, "globalCookie": false };</script>
      <script src="https://cdn.hu-manity.co/v2/hu-banner.min.js" type="text/javascript" charset="utf-8"></script>
    
      <!-- your tags stay below it -->
      <script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXX"></script>
    </head>
    
  3. Or fire the tags through Google Tag Manager and gate them with consent triggers (both engines). On the New engine, recognised tags that GTM fires are also held automatically. See gtm for placing the banner above the container.

What the order controls #

The banner holds recognised trackers that load after it until the visitor chooses, in regions whose rule requires consent first. A script placed above the snippet runs straight away, and a script you mark data-hu-category="1" is treated as essential. What runs before consent is your decision, so keep analytics and pixels below the snippet.

Confirm the result #

Use a private window. In the page source the banner snippet comes first in <head> and your tags come after it. Then open the browser's Application → Cookies panel before choosing anything: no tracking cookies (for example _ga, _gcl_au, _fbp) appear in a region whose rule requires consent first. After Allow, the tags start and their cookies appear. A held tag shows type="javascript/blocked" in the Elements panel until the visitor chooses.

Test from a region your strictest rule covers (for example the EU), or confirm region rules are off. The browser checks are in plain-html, and the full procedure is verify-install.

Gotchas #

More help #