Google Analytics 4 1 is free but sets cookies, so EU and UK privacy rules normally require consent first. Consent mode v2 loads the tag in a restricted state and unlocks it when the visitor agrees. Plausible 3,749 (https://github.com/plausible/analytics 29,236 ) is the common cookieless alternative: no persistent identifiers, hosted from $9 a month for 10,000 pageviews, or self-hosted under AGPL-3.0.
gtag('consent', 'default', { ad_storage: 'denied', ad_user_data: 'denied',
ad_personalization: 'denied', analytics_storage: 'denied' });
acceptButton.onclick = () => gtag('consent', 'update', { analytics_storage: 'granted' });The MIT-licensed CookieConsent 5,686 (https://github.com/orestbida/cookieconsent 5,686 ) library (npm 2,036 i vanilla-cookieconsent) supplies the banner, per-category toggles and a callback for the update call.