Kjeks
← All docs

Kjeks Google — Consent Mode v2

Google Tag Manager and GA4, loaded through Consent Mode v2. Signals default to denied and the container is withheld until Kjeks grants consent.

Requires WordPress 6.8+PHP 8.3+Requires the Kjeks coreSource on GitHub →

101 Setup

This add-on wires Google's tags into Kjeks. Install thecore plugin first — the add-on boots onplugins_loaded and does nothing without it.

Install & activate

  • Download the latestkjeks-google.zipand upload it under Plugins → Add New → Upload Plugin, then activate it (network-activate on multisite).
  • There is no activation step or migration — it simply registers a Google integration with Kjeks.
  • Updates arrive automatically from GitHub releases via plugin-update-checker.

Enter your IDs

SettingFormatWhere
GA4 measurement IDG-XXXXXXXXSettings → Kjeks Google (slug kjeks-google), or network defaults at kjeks-google-network.
GTM container IDGTM-XXXXXX
IDs are validated: anything that isn't a valid G-… or GTM-…value is stored as empty and simply not loaded.

Pick the gating category

Choose which Kjeks category unlocks Google's tags. Allowed values areanalytics (the default) and marketing.

201 How Consent Mode v2 works

Defaults: everything denied

Before any Google script loads, the add-on emits Consent Mode defaults inwp_head — all signals denied, with a short update window:

gtag( 'consent', 'default', {
    ad_storage:         'denied',
    ad_user_data:       'denied',
    ad_personalization: 'denied',
    analytics_storage:  'denied',
    wait_for_update:    500,
} );

Granting on consent

The add-on synchronises Google's signals to Kjeks on the kjeks:grantedand kjeks:withdrawn events (and on DOMContentLoaded):

// When Kjeks 'analytics' is granted:
gtag( 'consent', 'update', { analytics_storage: 'granted' } );

// When Kjeks 'marketing' is granted:
gtag( 'consent', 'update', {
    ad_storage:         'granted',
    ad_user_data:       'granted',
    ad_personalization: 'granted',
} );
  • analytics_storage is granted only when Kjeks analytics is granted.
  • The three advertising signals are granted only when Kjeks marketing is granted.

What actually loads

The tags register as a single Kjeks integration (ID google-tags) gated by your chosen category. Once the gate opens:

TagLoadsThen
GA4googletagmanager.com/gtag/js?id=<GA4_ID>gtag( 'config', '<GA4_ID>' )
GTMgoogletagmanager.com/gtm.js?id=<GTM_ID>Container runs with Consent Mode applied.

301 Config, filters & internals

Options

OptionScope
kjeks_googlePer site
kjeks_google_networkNetwork defaults

Both resolve to the same shape:

{ "gtm_id": "GTM-XXXXXX", "ga4_id": "G-XXXXXXXX", "gating_category": "analytics" }

A site's own option wins; otherwise the network defaults apply. On multisite the network page (kjeks-google-network, capabilitymanage_network_options) sets the fallback, and each site page (kjeks-google, capability manage_options) can override it.

Filter

Adjust the resolved configuration at runtime with kjeks_google_config(receives the config array and the blog ID):

add_filter( 'kjeks_google_config', function ( $config, $blog_id ) {
    // $config = [ 'gtm_id' => '', 'ga4_id' => 'G-XXXX', 'gating_category' => 'analytics' ]
    return $config;
}, 10, 2 );
Use the scanner to confirm that no Google request fires in the before-choice and reject-all states — that's the quickest proof your Consent Mode wiring is correct.