Documentation / Pantry Analytics
Pantry Analytics
Contents: The GA4 tag, placed properly, with consent defaults.
Google Analytics 4 without a dashboard. Enter the measurement ID and the tag prints in the right place on the front end, with Consent Mode defaults so nothing is stored until a visitor agrees, and with the roles you choose left out of the numbers. The site's own server never talks to Google.
What it does
- One settings screen (Plugin Pantry > Analytics) with a Measurement ID field, validated against the
G-XXXXXXXshape before it is stored. An invalid value is rejected, the previous value is kept, and a settings error explains why. - Once a valid measurement ID is saved, the gtag.js tag prints once in
<head>, onwp_headat priority 1, on front-end pages only. - The tag never prints in
wp-admin, onwp-login.php, on a feed, on an embed, or on a REST API response. - Excluded roles: logged-in users with any of the roles you tick never receive the tag. Administrators are excluded by default. Signed-out visitors are always counted, regardless of this setting.
- Consent Mode: on by default. While it is on, the plugin prints Google Consent Mode v2 defaults (
ad_storage,ad_user_data,ad_personalizationandanalytics_storage, alldenied) before gtag.js loads, exactly as Google documents. Switch it off only on a site with no cookie banner at all. - While Consent Mode is on, the plugin also prints a small listener for the
pantry-consentbrowser event. Pantry Consent (or any other banner that dispatches the same event) can callgtag('consent', 'update', ...)on the fly once a visitor makes a choice. - Loading: an option to load the tag only after the visitor's first interaction (
pointerdown,keydownorscroll), or after five seconds if no interaction happens first, so gtag.js stays off the critical rendering path. Consent Mode defaults, when on, still print immediately -- only the gtag.js library and the config call are delayed. - One plain status line at the bottom of the settings screen states exactly what is currently printed: the measurement ID, whether Consent Mode defaults are on, whether loading is immediate or delayed, and which roles are excluded.
What it does not do
- No dashboard, charts or reports inside WordPress.
- No Google account connection and no server-side requests to Google. The visitor's own browser is the only thing that ever talks to Google.
- No other analytics vendors.
- No cookie banner. Pair this with Pantry Consent, or any banner that dispatches a
pantry-consentevent, or switch Consent Mode off. - No event tracking beyond what GA4 does itself.
These are deliberate scope limits from the Pantry Standard, not missing features. See does_not in the plugin's registry entry and https://thepluginpantry.com/standard.
Usage
- Activate the plugin.
- Go to Plugin Pantry > Analytics.
- Paste your GA4 measurement ID (from the GA4 admin, under Data Streams) into the Measurement ID field.
- Leave Consent Mode on unless the site has no cookie banner at all.
- Tick any roles that should never be counted, in addition to Administrator, which is excluded by default.
- Optionally turn on Load the tag only after the visitor's first interaction to keep gtag.js off the critical path.
- Save. The status line confirms exactly what will print.
Working with a consent banner
Pantry Analytics does not show a banner itself. Any script on the page, including Pantry Consent, can grant or deny consent by dispatching:
document.dispatchEvent( new CustomEvent( 'pantry-consent', {
detail: {
gtag: {
analytics_storage: 'granted',
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied'
}
}
} ) );
Pantry Analytics listens for this event (while Consent Mode is on) and immediately calls gtag('consent', 'update', event.detail.gtag).
Storage
Settings are stored in one option, pantry_analytics_settings, holding measurement_id, delay_load, consent_mode and excluded_roles. There are no custom tables, post types, post meta, transients or cron events.
Hooks
Pantry Analytics adds no PHP filters or actions of its own. It hooks into the standard WordPress wp_head action (priority 1) and reads is_admin(), is_feed(), is_embed(), REST_REQUEST and the current user's roles to decide whether to print. On the front end it listens for the plain browser CustomEvent named pantry-consent described above; that is a JavaScript event, not a WordPress hook, and any script on the page may dispatch it.
Uninstall
Deleting the plugin through the Plugins screen removes the pantry_analytics_settings option. There is nothing else to remove.