Digivator Cookie Consent

By Floyd Sequeira

0+ active installationsVersion 1.0.0

A cookie consent banner built to work with Site Kit by Google. Four categories, script blocking, WP Consent API and Consent Mode v2.

Description

Digivator Cookie Consent asks visitors which cookies they are happy for your website to use, remembers the answer, and passes it on to the tools that need it. Optional categories stay off until a visitor agrees to them.

Built to work with Site Kit by Google

Digivator Cookie Consent is built to work with Site Kit by Google. Site Kit prints the Google tag for Analytics and other Google services, and Digivator Cookie Consent holds that tag back until a visitor agrees to Statistics or Marketing, then tells Google Consent Mode what the visitor chose. No extra setup is needed. Site Kit by Google is a product of Google. This plugin is independent and is not affiliated with or endorsed by Google.

Categories

  • Essential is always on and cannot be switched off. It covers storage the site needs to work, including remembering the visitor’s cookie choices.
  • Statistics covers analytics and measurement, including Google Analytics. Google Analytics is never treated as essential.
  • Preferences covers remembering visitor choices and personalisation.
  • Marketing covers advertising, remarketing and marketing tracking.

The banner

The default wording is: “We use cookies to understand how visitors use this website and offer personalised experiences. You can choose which cookies to allow.” You can edit it in the settings.

  • Accept essential switches off statistics, preferences and marketing, saves the choice, updates the WordPress Consent API and Google Consent Mode, and removes the banner straight away.
  • Accept all switches on all four categories, saves the choice, updates the same integrations, and removes the banner straight away.
  • Cookie preferences opens a window with a switch for each optional category. Nothing is preselected. Essential is shown as always on. A Save preferences button stores the visitor’s real choices and closes the window.

Accept essential and Accept all are the same size and weight so neither is favoured.

Changing or withdrawing consent

A small floating Cookie preferences button appears once a choice has been made (you can turn it off). You can also add a link to your footer or menu. Visitors can reopen the window at any time, change each category and save.

Choices are remembered

  • The choice is stored in a first-party cookie called digivator_cookie_consent with the consent version, a timestamp and one true or false value per optional category. The cookie is SameSite=Lax, is Secure on HTTPS and is limited to your site’s path.
  • If the browser refuses the cookie, the same record is kept in localStorage instead. If both are blocked, the visitor’s choice applies to the current page only and they are asked again on the next page. Storage failures never switch an optional category on.
  • A missing, malformed, expired or old-version record counts as no consent.
  • Change the Consent version setting when your policy or the cookies you use change in a material way, and every visitor is asked again.
  • No personal data is collected. The plugin has no tracking, no telemetry and makes no requests to any other site.

Script blocking

A banner alone does not stop tracking, so Digivator Cookie Consent can hold back scripts that you register. A held-back script is printed as an inert type="text/plain" placeholder and is only started once the visitor allows its category. The page output is identical for every visitor, so page caching cannot hand one visitor’s scripts to another.

Built in, and on by default, the plugin holds back Google tags that WordPress prints through its script functions: the Google tag (gtag.js) from Google Site Kit including its inline setup code, the Google Tag Manager container snippet, and Google AdSense. You can register your own scripts by handle, by URL or by hand-written markup. See “Developer notes” below.

WordPress Consent API

If the official WP Consent API plugin is active, Digivator Cookie Consent:

  • declares itself as a supporting plugin and sets the consent type to opt-in (PHP filter wp_get_consent_type and JavaScript window.wp_consent_type)
  • keeps these documented categories in step with the visitor’s choice using wp_set_consent(): functional (always allow), statistics and statistics-anonymous (both follow Statistics), preferences, and marketing
  • uses only the documented values allow and deny
  • reports functional as allowed even before a choice is made, because essential storage never needs consent
  • resets any stale “allow” values to “deny” when there is no valid saved choice, for example after the consent version changes
  • registers its own cookie with wp_add_cookie_info() and matches the Consent API cookie lifetime to your “Remember choices for” setting

If the plugin is not installed, everything else works and no JavaScript errors occur. The Consent API only passes choices around. Registering a category does not block anything, so other plugins must read the choice (wp_has_consent()) or be registered with Digivator Cookie Consent to be held back.

Google Consent Mode v2

When enabled (the default) Digivator Cookie Consent runs gtag('consent', 'default', ...) in the head before any other script, with everything optional denied. If the visitor has already chosen, a matching gtag('consent', 'update', ...) follows immediately. Every later choice sends a new update straight away, including withdrawals.

Category
Consent Mode signals

Essential (always on)
functionality_storage, security_storage

Statistics
analytics_storage

Preferences
personalization_storage

Marketing
ad_storage, ad_user_data, ad_personalization

This is the same category split that Google Site Kit 1.191.0 uses in its own Consent Mode and WP Consent API mapping. You can change it with the digivator_cookie_consent_google_signals filter.

Accessibility

The banner and window work on desktop, tablet and mobile. They are keyboard accessible, have visible focus outlines, use labelled controls and ARIA attributes, announce saves to screen readers, use the native modal dialog element so focus stays in the window while it is open and returns afterwards, and respect reduced-motion settings. While the banner is showing, the page keeps extra space and scroll padding so the banner never hides the control that has keyboard focus (WCAG 2.2 criterion 2.4.11). These checks were made with automated and keyboard tests in Chromium. The banner has not been manually tested with screen readers.

Colours

Choose every colour in Settings > Digivator Cookie Consent with the native WordPress colour pickers. A live preview updates as you pick, and the page warns you if a pairing falls below WCAG contrast. Defaults are a purple and navy palette.

Compliance readiness checklist

Settings > Digivator Cookie Consent includes a ticked checklist for UK GDPR and PECR, EU GDPR and ePrivacy, Google’s requirements and WCAG 2.2 level AA. Each item has a plain text status:

  • Built in means the plugin does it by design and automated tests cover it.
  • Set up on this site or Action needed is worked out from your saved settings, for example whether the banner is on, a privacy policy link is set, Google tags are held back, Consent Mode is on and your colours are readable.
  • You confirm is for things only you can know, such as whether your privacy policy lists your cookies. Tick the box when it is true.
  • Not covered lists what the plugin does not do, such as server-side records of consent, cookie scanning, IAB TCF certification and region detection. These are never counted as ticks.

The ticks show that settings and checks are in place. They are not legal advice or a certificate, and a full set of ticks does not mean your site complies with any law.

Important

Digivator Cookie Consent is a consent interface and a blocking helper. It does not make a website compliant with UK GDPR, PECR or any other law by itself. You remain responsible for the cookies and scripts on your site, your privacy policy and your legal compliance. See the limitations below.

Developer notes

Register an enqueued script

add_action( 'wp_enqueue_scripts', function () {
    digivator_cookie_consent_register_script( 'my-pixel', 'marketing' );
} );

Call it before the script prints. A trailing * matches any handle with that prefix. Several categories mean “any of these” (array( 'statistics', 'marketing' )).

Register rules for handles, URLs or inline code

add_filter( 'digivator_cookie_consent_script_rules', function ( $rules ) {
    $rules[] = array(
        'category' => 'marketing',
        'src'      => 'connect.facebook.net/en_US/fbevents.js',
    );
    $rules[] = array(
        'category' => 'statistics',
        'inline'   => 'window.myAnalytics',
    );
    return $rules;
} );

A rule needs category plus at least one of handle, src or inline. Rules apply to scripts printed through wp_enqueue_script(), wp_add_inline_script(), wp_print_script_tag() and wp_print_inline_script_tag(). Inline scripts that carry data rather than code are never blocked.

Hand-written markup

<script type="text/plain" data-digivator-cookie-consent-category="statistics" data-digivator-cookie-consent-src="https://example.com/tool.js"></script>
<script type="text/plain" data-digivator-cookie-consent-category="marketing">window.myPixel = true;</script>

Use data-digivator-cookie-consent-src instead of src. Several categories separated by spaces mean “any of these”.

Other hooks and functions

  • digivator_cookie_consent_google_signals filters the category to Consent Mode signal map.
  • digivator_cookie_consent_cookie_patterns filters the first-party cookie name patterns cleared on withdrawal.
  • digivator_cookie_consent_preferences_link( $args ) prints the preferences button.
  • digivator_cookie_consent_has_consent( $category ) is a server-side check of the saved choice. Do not use it to change the HTML of cacheable pages.
  • JavaScript: window.DigivatorCookieConsent offers getConsent(), hasConsent( category ), open(), acceptAll(), acceptEssential() and save( { statistics, preferences, marketing } ).
  • JavaScript event: document.addEventListener( 'digivator_cookie_consent_updated', function ( e ) { /* e.detail.consent, e.detail.previous, e.detail.source */ } ). The standard wp_listen_for_consent_change event also fires when the Consent API is active.

Notes

  • Scripts started after consent are added in document order. If a held-back script depends on another script, register both.
  • A Content Security Policy must allow the inline scripts WordPress prints and the scripts you release.

Privacy

Digivator Cookie Consent stores the visitor’s choice in a first-party cookie (or localStorage) named digivator_cookie_consent. It contains the consent version, a timestamp and a true or false value for statistics, preferences and marketing. It holds no personal data and is never sent to the plugin authors or any other service. The plugin makes no external requests and loads no remote assets. When the WP Consent API plugin is active it also writes its own wp_consent_* cookies. A suggested paragraph for your privacy policy is added to Settings > Privacy > Policy Guide.

Installation

  1. Upload the digivator-cookie-consent folder to /wp-content/plugins/, or use Plugins > Add New > Upload Plugin and choose the ZIP.
  2. Activate Digivator Cookie Consent.
  3. Go to Settings > Digivator Cookie Consent. Check the banner wording, add your privacy policy URL and choose colours if you wish.
  4. Add the Cookie preferences link to your footer (see below).
  5. Optional: install and activate the official WP Consent API plugin if other plugins need to read visitor choices.
  6. Test in a private window with the browser developer tools open. See “Checking your own site”.

Footer link

Visitors must always be able to change or withdraw their choice. Use any one of these:

  • Shortcode: [digivator_cookie_consent_preferences]. Optional attributes: label="Privacy choices" and class="my-class".
  • Menu: add a Custom Link with the URL #digivator-cookie-consent-preferences.
  • Any element: add the attribute data-digivator-cookie-consent-open to a button or link.
  • Template: <?php if ( function_exists( 'digivator_cookie_consent_preferences_link' ) ) { digivator_cookie_consent_preferences_link(); } ?>

Google Site Kit and Consent Mode setup

  1. Set up Site Kit and Google Analytics as you normally would.
  2. In Settings > Digivator Cookie Consent keep “Google Consent Mode” and “Block Google tags” ticked. These are the defaults.
  3. Site Kit prints the Google tag through WordPress’s script functions with the handle google_gtagjs. Digivator Cookie Consent turns the tag and its inline setup code into inert placeholders. No Google script loads, no request is sent and no Analytics cookie is set until the visitor accepts Statistics or Marketing. This gives Basic Consent Mode behaviour, which means nothing from Google runs before consent.
  4. Site Kit’s own Consent Mode setting is optional. On its own it follows Advanced Consent Mode, where the Google tag loads straight away in a denied state. Digivator Cookie Consent already supplies the defaults and updates, so you do not need it. If you do enable it, both use the same category mapping.
  5. Check the result in your browser (see below).

Statistics only: analytics may run. Marketing only: advertising tags may run. Accept all: both may run. After Accept essential or a rejection, neither runs.

Checking your own site

Open a private window, open the developer tools Network tab, and load a page. Before you choose, you should see no requests to googletagmanager.com, google-analytics.com or other tracking hosts, and the Application tab should show no _ga or _gcl cookies. Then test each choice. Repeat after any change to your theme, plugins or tag setup.

FAQ

Does this make my site legally compliant?

No plugin can do that on its own. Digivator Cookie Consent helps you ask for consent in a fair way, holds back scripts you have registered and shows a checklist of what is in place and what you still need to do. Compliance depends on what your site actually does, what your privacy policy says and the laws that apply to you. The checklist is not legal advice, so please take your own advice.

What does the compliance checklist cover?

It covers UK GDPR and PECR (using the ICO guidance on storage and access technologies), EU GDPR and ePrivacy (using the EDPB Cookie Banner Taskforce report), Google’s EU user consent policy and Consent Mode, and WCAG 2.2 level AA for the banner. It also lists what is not covered, including server-side records of consent. Google requires a Google-certified consent management platform that supports the IAB Transparency and Consent Framework for personalised ads through AdSense, Ad Manager or AdMob in the EEA, UK and Switzerland. Digivator Cookie Consent is not one.

Does Statistics need consent?

This plugin asks for consent for all Statistics. UK law now has narrow exceptions for some low-risk statistics, with conditions such as aggregated data and an easy way to object, and they do not cover advertising. Whether an exception could apply to the tools you use is your decision.

Does it block every tracking script automatically?

No. It blocks scripts it has been told about. It does not scan or rewrite the whole page, because that breaks themes and plugins. It covers Google tags printed through WordPress’s script functions by default, plus anything you register. It cannot catch hard-coded scripts pasted into theme templates, duplicate tags, tags added by other plugins that bypass the WordPress script functions, scripts injected later by another script, or tags managed inside Google Tag Manager. Those need to be registered, wrapped in the documented markup, moved into WordPress’s script functions, or configured in their own tool. Always test with your browser’s developer tools.

What about Google Tag Manager?

The container snippet is held back until Statistics or Marketing is accepted when WordPress prints it through its script functions, as Site Kit does. Tags inside the container are controlled by GTM, so give each tag the right built-in Consent Mode checks there. Site Kit’s Tag Manager module also prints a <noscript> iframe for visitors with JavaScript turned off. Those visitors cannot see the banner and this plugin cannot block that iframe.

What if one Google tag carries both Analytics and Google Ads and a visitor accepts only one?

The tag loads with the other category’s Consent Mode signals denied. For Analytics, Digivator Cookie Consent also sets Google’s documented ga-disable-ID flag for any GA4 or Universal Analytics ID it finds in the held-back tags while Statistics is not accepted. Google Ads has no equivalent flag, so Google’s own denied-state behaviour applies. If you need a stricter split, use separate tags.

Does withdrawing consent delete cookies?

It stops future use of the related tags and clears common first-party Google cookies it can see (for example _ga, _ga_*, _gid, _gcl_*) on your domain. It cannot delete cookies that belong to other domains or that are HttpOnly, and it cannot recall data already collected. A script that has already started cannot be unloaded from the current page. Turn on “Reload the page when a visitor withdraws consent for something already running” if you want a reload to guarantee that nothing keeps running. Add other cookie names with the digivator_cookie_consent_cookie_patterns filter.

Where is the visitor’s choice stored?

In the first-party digivator_cookie_consent cookie, or in localStorage under the same name if cookies are refused. Nothing is stored in your database and nothing is sent anywhere. Typical lifetime is 180 days, which you can change from 1 to 395 days.

How do I ask everyone again?

Change the Consent version in the settings (for example from 1 to 2). Saved choices from the old version are ignored.

Does it work with page caching and CDNs?

Yes. The HTML is the same for every visitor and all decisions happen in the browser. If a performance plugin delays, defers or combines JavaScript, exclude digivator-cookie-consent.js so the banner and Consent Mode update are not late.

Is Statistics the same as the Consent API’s statistics category?

Yes. Digivator Cookie Consent also sets statistics-anonymous to the same value so that a visitor who declines Statistics is not treated as agreeing to any measurement. The Consent API has no category called “essential”, so Essential is reported as functional.

Can I change the button labels?

The labels are translatable like any other plugin text. Wording, category descriptions, colours and the privacy link are editable in the settings.

What happens if I turn the banner off in the settings?

The plugin then outputs nothing on the front end. There is no banner, no script blocking and no Consent Mode signals. Hand-written type="text/plain" placeholders stay inert.

What happens to choices made with version 0.1.0?

Version 0.1.0 only asked about analytics, so those choices are ignored and visitors are asked again. The old localStorage key is removed.

Changelog

1.0.0

  • First public release. Earlier version numbers were private development builds.
  • Renamed from the earlier working name. Settings saved under that name are moved across once on the first page load, and visitors are asked again because the cookie has a new name.

0.2.1

  • New compliance readiness checklist in Settings > Digivator Cookie Consent for UK GDPR and PECR, EU GDPR and ePrivacy, Google requirements and WCAG 2.2 level AA. It combines built-in features, ticks worked out from your settings, owner confirmations and a list of what is not covered.
  • Fixed the banner covering keyboard focus on the page behind it (WCAG 2.2 criterion 2.4.11). The page now keeps scroll padding and a blank spacer while the banner is showing, and both are removed when it goes.
  • Owner confirmations are sanitised and only known items are stored.

0.2.0

  • Rebuilt around four categories: Essential, Statistics, Preferences and Marketing. Opt-in by default, nothing preselected.
  • Fixed the banner not closing after a choice. Accept essential and Accept all now remove it immediately and it stays dismissed.
  • New Accept essential, Accept all and Cookie preferences buttons. New default wording.
  • New accessible preferences window (native modal dialog) with a switch per category and a Save preferences button.
  • Persistent Cookie preferences access: shortcode, menu link, data attribute, template function and an optional floating button.
  • Reliable persistence: first-party cookie with consent version and timestamp, localStorage fallback, and strict validation. Changing the consent version asks everyone again.
  • WordPress Consent API integration rewritten to use the documented categories and values, set opt-in, and cope with the plugin being absent.
  • Google Consent Mode v2 defaults and updates for all seven signals.
  • Script blocking for registered scripts, with Google Site Kit, Tag Manager and AdSense registered by default. Developer filter and helper functions added.
  • Best-effort clearing of first-party Google cookies when consent is withdrawn, and an optional reload on withdrawal.
  • Settings page rebuilt with the Settings API: banner switch, wording, privacy URL, consent version, remember period, category descriptions, twelve colour pickers with live preview and contrast warnings, and documentation.
  • Colour output is sanitised and escaped. Admin access needs the manage_options capability and the standard settings nonce.
  • Added uninstall.php, an upgrade routine for 0.1.0 settings and a privacy policy suggestion.

0.1.0

  • Initial development release.