@noidme/consent-mode
v0.1.0-beta.0
Published
Google Consent Mode v2 + GPC + server-side GTM, from a purpose-based consent map. Maps consent to the four GCM v2 signals, the sGTM `gcs` string, and a gtag/dataLayer consent update; detects + enforces Global Privacy Control. Framework-agnostic, zero-depe
Maintainers
Readme
@noidme/consent-mode
Google Consent Mode v2 + GPC + server-side GTM — from a purpose-based consent map. Zero-dependency, framework-agnostic. A noidme.js plugin, usable standalone.
Give it a { purpose: granted } map (e.g. from @noidme/consent)
and it produces everything Google's stack needs:
import { toConsentModeV2, gcsFromConsent, pushConsentModeV2, detectGPC } from '@noidme/consent-mode';
const consent = { advertising: true, analytics: false, ad_personalization: false };
toConsentModeV2(consent);
// → { ad_storage:'granted', analytics_storage:'denied', ad_user_data:'granted', ad_personalization:'denied' }
gcsFromConsent(consent); // → 'G110' (the `gcs` param server-side GTM reads)
pushConsentModeV2(consent, { gtag }); // gtag('consent','update', …)
pushConsentModeV2(consent, { dataLayer }); // dataLayer.push(['consent','update', …])
detectGPC(navigator); // → Global Privacy Control honored?- Consent Mode v2 — the four required signals (
ad_storage,analytics_storage,ad_user_data,ad_personalization), mappable per purpose via aConsentModeMapping. - Server-side GTM — the
gcsstring +appendConsentToCollector(url, consent)so a first-party sGTM collector honors consent; aCollectorRegistryfor multiple tags. - GPC —
detectGPC/gpcApplies(region)/applyGPCto honor Global Privacy Control per jurisdiction.
Install
npm i @noidme/consent-modeLicense
MIT.
