Skip to content

A compliant cookie banner

Installing the banner, holding back scripts, rules by region, the scanner and proof of consent.

Lesson
3/5
Reading time
8 min
Sections
4
Through the course
60%

Install at the top of the head

Paste the snippet as the opening script inside head on every page, before any tags it should control. It remembers the visitor's choice in a first-party cookie called sf_consent.

Holding back scripts

  • Common analytics, advertising, social and chat scripts are recognised and held until their category is allowed.
  • Manual: set a script's type to text/plain and add data-category (preferences, analytics or marketing).
  • With consent signals on, tags that understand consent start as denied and update when the visitor chooses.
  • Withdrawing a category reloads the page so scripts that already ran stop.
Illustrative interface, sample dataAn opt-in banner, with Reject all as prominent as Accept all.

Rules by region

Visitors in the UK, EU, EEA and Switzerland, and visitors whose country can't be determined, always get an opt-in banner with Reject all as prominent as Accept all. Elsewhere you can choose a banner, a notice or nothing. Global Privacy Control signals are treated as rejecting marketing.

Check your understanding

A visitor's country can't be determined. What do they get?

Scanner and proof

The scanner crawls your pages and recognises cookies and known scripts; your categories are kept on later scans. Every choice is logged with an anonymous consent id, policy version and what was allowed, with shortened, hashed IP addresses. After changing your cookies, use Ask everyone again.

Lesson 3 of 5

A compliant cookie banner