Google Analytics behind a cookie banner

The first post said this site had no scripts. It has one now: a small consent script that loads Google Analytics, but only for visitors who say yes.

Why add analytics at all

Google Search Console, set up in the baseline post, covers what happens before a click: impressions, clicks, positions and queries. It says nothing about what happens after: which pages people read, where visitors come from besides Google search, and whether they go on to a second page. Google Analytics 4 covers that side. Together they describe the whole path from search result to reading.

Why there is a banner

Google Analytics stores cookies in the visitor's browser. Under EU rules (the ePrivacy rules, which Sweden applies through its electronic communications law, and the GDPR), cookies that aren't strictly needed to deliver the site require consent before they are set. Sweden's data protection authority, IMY, has previously ruled against companies over how they used Google Analytics. A banner isn't decoration here; it's the condition for using the tool at all.

How it works

  • Nothing loads before a choice. Google's tag isn't on the page until the visitor clicks Accept. Until then, no request goes to Google.
  • Consent Mode set to denied by default. Google's Consent Mode is told up front that analytics and advertising storage are both denied. Accepting changes only analytics; advertising stays denied.
  • Accept and Decline look the same. European data protection authorities have criticised banners that make refusing harder than accepting, through hidden buttons or weaker colours. Here both are identical buttons, side by side.
  • The choice can be changed. Every page has a “Cookie settings” link in the footer. Declining after accepting deletes the Analytics cookies.
  • The choice is remembered locally. It's saved in the browser's own storage so the banner doesn't return on every page. That record is needed to respect the choice, so it doesn't need consent itself.
  • A privacy page says who runs the site, what's collected, which cookies are used and how to object.

What it costs

Every visitorThe consent script: about 1 KB compressed
After AcceptGoogle's tag: about 180 KB compressed, around 540 KB once unpacked, loaded without blocking the page
Layout shiftNone: the banner floats above the page instead of pushing content down

The heavy part only reaches people who chose it. Someone who declines, or ignores the banner, gets a page that is about 1 KB heavier than before.

What it means for SEO

Googlebot never clicks Accept, so Google's crawler sees the site without Analytics. The banner itself is not a ranking problem: Google's guidance on intrusive interstitials explicitly excludes dialogs that are required by law, such as cookie consent. Keeping the banner small and at the bottom of the screen also keeps it out of the way of the content it sits over.

The trade-off: counting only those who say yes

Consent Mode has an “advanced” setting that sends cookieless signals to Google even before consent, which Google uses to estimate the visitors it can't see. Heliocite doesn't use it. Nothing is sent until someone accepts, which is the simpler and more cautious choice.

The cost is that Google Analytics will undercount. Every number it shows is a lower bound: only visitors who clicked Accept are in it. Search Console doesn't depend on cookies, so its click count stays complete. Comparing the two, clicks from Google search in Search Console against visits from Google search in Analytics, gives a rough idea of how many people accept the banner. That comparison will be in a future post, once there are enough visitors to compare.

← All posts