Skip to content

Google Consent Mode v2

How OptinStack integrates with Google Tag Manager and Google Consent Mode v2.

OptinStack drives Google Consent Mode v2 automatically. On every consent state change, the runtime calls gtag('consent', ...) with the mapped signals and pushes OptinStack events to dataLayer for GTM triggers.

How it works

When the consent kernel initializes:

  1. OptinStack ensures window.dataLayer exists (creates an empty array if missing).
  2. OptinStack ensures window.gtag exists (installs a minimal function that pushes to dataLayer if missing).
  3. The first Consent Mode call uses gtag('consent', 'default', …) and includes wait_for_update: 500.
  4. Later consent changes use gtag('consent', 'update', …).
  5. DataLayer events such as optinstack_consent_updated are pushed for use in GTM triggers.

You do not need to pre-install gtag for Consent Mode signals. You still need Google tags (or GTM) on the page for those tags to consume the signals.

Place the OptinStack script before GTM / gtag so default consent is set early. See Install.

Tracker blocking (scripts, iframes, cookies, storage) is separate from Consent Mode. Blocking uses your published inventory and data-optinstack-categories. Consent Mode only updates Google's consent signals. See Basic vs Advanced Google Consent Mode for when cookieless pings may still fire.

GTM parameterOptinStack category
ad_personalizationmarketing
ad_storagemarketing
ad_user_datamarketing
analytics_storageanalytics
functionality_storagepreferences
personalization_storagepreferences
security_storagenecessary

Each parameter is set to 'granted' or 'denied' based on the corresponding OptinStack consent category, with the exceptions below.

Disabled categories

Project configuration can disable entire categories (for example, hide the marketing toggle in consent preferences). When a category is disabled in config, the SDK treats it as essential for enforcement purposes and sends granted for the mapped Google Consent Mode signals on that category. Disabled categories are not shown in the preferences UI and cannot be declined by visitors.

Preview and override modes

Dashboard preview or rule-override flows can force a temporary banner rule in the browser. When an override forces an opt-in rule for preview, Consent Mode updates may be skipped so preview behavior does not fight production Google tags. Production traffic uses the published regional policy and always drives Consent Mode as described above.

OptinStack GTM guides

For full setup walkthroughs, see:

Example

When a user accepts all categories, the SDK sends:

gtag('consent', 'update', {
  ad_personalization: 'granted',
  ad_storage: 'granted',
  ad_user_data: 'granted',
  analytics_storage: 'granted',
  functionality_storage: 'granted',
  personalization_storage: 'granted',
  security_storage: 'granted',
});

When a user rejects all optional categories:

gtag('consent', 'update', {
  ad_personalization: 'denied',
  ad_storage: 'denied',
  ad_user_data: 'denied',
  analytics_storage: 'denied',
  functionality_storage: 'denied',
  personalization_storage: 'denied',
  security_storage: 'granted', // necessary is always granted
});

DataLayer events

The SDK also pushes events to the dataLayer array for use in GTM triggers:

DataLayer eventWhen
optinstack_gpc_signal_detectedOn init, if Global Privacy Control is active
optinstack_consent_updatedEvery time consent state changes
optinstack_necessary_acceptedFirst time necessary is granted (fires once)
optinstack_analytics_acceptedFirst time analytics is granted (fires once)
optinstack_marketing_acceptedFirst time marketing is granted (fires once)
optinstack_preferences_acceptedFirst time preferences is granted (fires once)
optinstack_unclassified_acceptedFirst time all four consent categories are granted (fires once)

Using dataLayer events in GTM

Create a custom trigger in GTM based on these events:

  1. Go to TriggersNew
  2. Select Custom Event
  3. Set the event name to optinstack_analytics_accepted
  4. Use this trigger on tags that should only fire after the user grants analytics consent

The *_accepted events fire only once per page load. They will not re-fire if consent is toggled off and on again within the same load. If a category is later denied, the corresponding accepted marker is cleared so a new grant can fire again later in the session.

Webflow Insights

If your Webflow project uses Webflow Insights and follows an opt-in GDPR policy rule, configure Webflow Insights so that tracking is disabled until the user has granted consent. This ensures analytics are not collected before the user has explicitly opted in. Webflow Insights Inside Webflow designer, navigate to Insights → Tracking and set Tracking defaults to Don't track by default.

The runtime also syncs analytics consent with Webflow's user-tracking APIs (wf.allowUserTracking / wf.denyUserTracking) when those APIs are present.

Was this helpful?