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.
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 latest
kjeks-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
| Setting | Format | Where |
|---|---|---|
| GA4 measurement ID | G-XXXXXXXX | Settings → Kjeks Google (slug kjeks-google), or network defaults at kjeks-google-network. |
| GTM container ID | GTM-XXXXXX |
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_storageis granted only when Kjeksanalyticsis granted.- The three advertising signals are granted only when Kjeks
marketingis granted.
What actually loads
The tags register as a single Kjeks integration (ID google-tags) gated by your chosen category. Once the gate opens:
| Tag | Loads | Then |
|---|---|---|
| GA4 | googletagmanager.com/gtag/js?id=<GA4_ID> | gtag( 'config', '<GA4_ID>' ) |
| GTM | googletagmanager.com/gtm.js?id=<GTM_ID> | Container runs with Consent Mode applied. |
301 Config, filters & internals
Options
| Option | Scope |
|---|---|
kjeks_google | Per site |
kjeks_google_network | Network 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 );before-choice and reject-all states — that's the quickest proof your Consent Mode wiring is correct.