Consent handling

The GOV.UK analytics JavaScript has been implemented so that no analytics code is run until users consent to cookies. This includes calling the GA4/GTM script from Google.

This JavaScript implements a blocklist when initialising Google Tag Manager. This prevents various items from being included from GTM, such as custom scripts and HTML.

Additionally, consent has been configured in GTM as an additional layer of certainty. All tags have the Exception - All Events - Declined Cookies exception (blocking trigger) applied, which prevents the tags from firing if the user’s consent cookie does not match “usage”:true.

The trigger leverages a Lookup variable (LT - cookies_policy - check) that returns ‘true’ where the string matches and ‘false’ where it does not. The exception then evaluates to TRUE (and will block tags from firing) when the LT - cookies_policy - check returns false.

Another exception (Exception - All Events - hostname filter) has also been added to all tags that prevents them from firing unless the Page Hostname matches one of the specified dev, integration, staging or production domains.