Zurück zum Hilfe-Center

Integrations

Block hard-coded scripts with data attributes

Hold back scripts GetCookies does not recognise until consent

Known trackers are held back automatically, wherever they are in your page; see Automatic tracker blocking. Use data-gc-category for scripts GetCookies does not recognise, to put a script in a specific category, or to stop the browser from even fetching a tracker before consent.

Mark a script with its category

Add data-gc-category with the consent category the script needs:

html
<script data-gc-category="analytics" src="https://cdn.example.com/stats.js"></script>

The GetCookies loader holds the script back before it runs, until the visitor accepts that category. This works for any script, known tracker or not, also when Automatic tracker blocking is set to Monitor or Off, and for scripts that other scripts or Google Tag Manager add later.

A browser reads ahead in your HTML and can fetch a <script src> before any script on the page can stop it (the file is downloaded, it does not run). To make no request at all before consent, also add type="text/plain":

html
<!-- Analytics -->
<script type="text/plain" data-gc-category="analytics" src="https://cdn.example.com/stats.js"></script>

<!-- Marketing -->
<script type="text/plain" data-gc-category="marketing">
  /* Meta Pixel code */
</script>

The browser never runs or fetches a text/plain script. GetCookies loads it, with its original type, as soon as the visitor accepts the category.

Embeds work the same way. Put the address in data-src so nothing loads before consent; the visitor sees a placeholder with a Load content button:

html
<iframe data-src="https://www.youtube.com/embed/VIDEO_ID" data-gc-category="marketing" width="560" height="315"></iframe>

Categories to use

  • necessary (always allowed)
  • analytics
  • marketing
  • preferences

Other attribute names

data-cookieconsent (the Cookiebot name) and data-getcookies-category work too on type="text/plain" scripts, so you can switch from another banner without changing your markup. Only data-gc-category also holds back a script that is not marked text/plain.

How it works

  • Scripts in your HTML: the loader watches the page while it is parsed and changes a marked script to type="text/plain" before it runs. In Firefox it also cancels the script at the last moment (beforescriptexecute) if needed.
  • Scripts added later by other code or Google Tag Manager: checked when they are inserted.
  • When a visitor rejects a category, its scripts stay inert. When they accept it, the scripts run.

Troubleshooting

  • The GetCookies script must be the first script in <head>. Code above it runs before it can be held.
  • If a script still fires early, check that it is marked and not loaded a second time elsewhere.
  • Clear caches/CDN so the updated markup ships.
  • In the browser console, GetCookies.getBlockingReport() lists what is held back.

Immer noch nicht weitergekommen?

Schreiben Sie an [email protected] mit Ihrer Domain und dem, was Sie versucht haben. Angemeldete Kunden können außerdem im Dashboard ein Ticket eröffnen.