Skip to content Skip to navigation

How to request user’s consent for analytics tracking with SEOPress

SEOPress Free lets you ask visitors for consent before loading the analytics tracking configured through SEOPress. The cookie bar provides acceptance, refusal, a choice per category (since SEOPress 10.4) and, optionally, a way to change the choice later.

  1. Go to SEO, Analytics and enable the Analytics module.
  2. Configure the trackers you want to use, then open the GDPR / Cookie Bar tab.
  3. Enable Request user consent for analytics tracking.
  4. For an explicit opt-in, leave Display and automatically accept user consent on page load disabled. This separate option starts tracking without waiting for an Accept click; displaying a banner is not the same as obtaining consent.
  5. Under Consent per category, keep Let visitors choose per category enabled if visitors should be able to allow analytics and advertising separately. Disable it to keep a banner with only two buttons. See the next section.
  6. Enable Allow users to change their cookie preferences if you want a preferences button to remain available.
  7. Save changes and clear your website cache.

Let visitors choose per category

Since SEOPress 10.4, visitors can allow analytics and advertising separately. The Let visitors choose per category option is enabled by default, also on sites updated from an earlier version, unless you turned it off. With this option, the banner shows three buttons:

  • Accept all: allows every category.
  • Decline all: keeps only the Necessary category.
  • Customize: unfolds the list of categories, each with a checkbox, and a Save my choices button.
Category What visitors read Google Consent Mode v2 signals
Necessary Required for the site to work, such as remembering this choice. Marked Always active, it has no checkbox. None
Analytics Audience measurement and visit statistics. analytics_storage
Advertising Measuring ad performance and showing relevant ads, including on other sites. ad_storage, ad_user_data, ad_personalization

Every checkbox starts unticked. Saving with nothing ticked is a refusal, like Decline all.

If you left the Accept and Decline button texts empty, the buttons read Accept all and Decline all in this mode. Texts you entered yourself are kept. The same goes for the message: when it is empty, the default message tells visitors they can accept all, decline all or choose which cookies they allow.

With the option disabled, the banner keeps its Accept and Decline buttons: Accept allows every category, Decline none.

Customize the message and appearance

Edit the consent message and the Accept, Decline and Cookie preferences button labels. Since SEOPress 10.4, the Customize button text field sets the label of the button that opens the per-category choices (default: Customize). Existing installations may still use “Close” as the refusal label. The refusal action does not become acceptance when its label changes.

You can use links and basic formatting in the message. Select your privacy policy page in WordPress settings, then use [seopress_privacy_page] as the destination of a link to that page.

Choose the banner position, alignment, width, colors and backdrop. The recommended insertion point is after the opening body tag. Your theme must support wp_body_open; if it does not, choose the footer insertion point and test again.

The integration covers Google Analytics, Matomo, Microsoft Clarity and custom tracking code added through SEOPress. It does not automatically control scripts inserted by your theme, another plugin or an independently configured tag manager. Check those integrations separately.

Each tracker waits for the categories it needs:

Tracker Starts when the visitor allows
Google Analytics (GA4) Analytics or Advertising. Each Consent Mode signal then follows its own category.
Matomo Analytics
Microsoft Clarity Analytics. Clarity’s ad storage consent follows Advertising.
Custom tracking code (Custom Tracking tab: HEAD, BODY and FOOTER tracking code, for example Google Tag Manager) Analytics and Advertising, both

Custom tracking code can contain anything, a heatmap as well as an advertising pixel, so SEOPress only runs it once both categories are allowed. If a visitor allows only Advertising, the Google tag still loads, with analytics_storage denied.

When GA4 and the cookie bar are enabled, SEOPress manages Google Consent Mode v2 signals for analytics_storage, ad_storage, ad_user_data and ad_personalization. The default is denied. Since SEOPress 10.4, Analytics grants analytics_storage and Advertising grants the three ad signals; Accept all grants all four, Decline all denies all four. Microsoft Clarity receives the same answer through its consent API: analytics storage follows Analytics, ad storage follows Advertising. Consent Mode communicates that choice to Google and does not itself collect the visitor’s consent.

Enabling a setting does not, by itself, establish legal compliance for your entire website.

Expiry, preferences and excluded roles

Cookie expiration (days) sets how long the choice is remembered; the default is 30 days. When the choice cookie is no longer present, an eligible visitor can be asked again. Clearing browser cookies also removes the saved choice.

Since SEOPress 10.4, the choice is stored in a single cookie, seopress-user-consent, which lists the allowed categories separated by a pipe, for example necessary|analytics. Visitors who answered before SEOPress 10.4 keep their answer and are not asked again: the former seopress-user-consent-accept cookie counts as allowing every category, seopress-user-consent-close as declining all. These older cookies keep their original expiry date, and are deleted when the visitor answers again.

The preferences button reopens the banner so a visitor can choose again. With per-category consent, it opens the list of categories directly, with the boxes ticked for what the visitor allowed so far. Google’s tag and Clarity are told about a new choice at once, but revoking consent does not undo data already sent or guarantee that every third-party script already running on the page stops. Also test the next page load and the behavior of your custom scripts.

Under Analytics, Advanced, review excluded user roles. Test while logged out or with a role that is not excluded, otherwise the banner or tracking may be absent by design.

Verify your setup

  1. Open a fresh private browser session. Before clicking a button, inspect tracking requests and the consent state with your browser’s developer tools or Google Tag Assistant.
  2. Click Accept (or Accept all), then navigate to another page. Verify that the intended trackers run and the saved choice is respected.
  3. Repeat in a separate fresh session and click Decline (or Decline all). Verify that analytics is not authorized.
  4. With per-category consent, repeat in another fresh session: click Customize, tick only Analytics and click Save my choices. analytics_storage must be granted and the three ad signals denied. Matomo and Clarity start, custom tracking code does not.
  5. Reopen preferences, change the choice, then reload and test again.
  6. Repeat with your cache and JavaScript optimization enabled. If results differ, clear the cache and isolate the optimization setting responsible.

If the banner is missing, check the module switch, the consent option, excluded roles, existing consent cookies and the theme’s insertion hook.

SEOPress 10.3 resolves each visitor’s saved choice in their browser. The same cached page can therefore be served to visitors who have accepted, declined or not answered yet (and, since SEOPress 10.4, to visitors who allowed only some categories). With explicit opt-in enabled, SEOPress keeps its tracking payload inactive until consent is available, then loads the authorized tracking code. A returning visitor’s choice is read again on the next page.

JavaScript delay, combining, minification or consent tools from other plugins can still affect execution order. After an update or a settings change, purge the page cache and any CDN cache.

Earlier versions of this guide asked you to exclude the seopress-user-consent-accept cookie from your page cache. Since SEOPress 10.3, this is no longer needed. If you added this rule, remove it: every visitor who has accepted bypasses the cache on every page view, which on most sites is the majority of your traffic. Do not exclude the seopress-user-consent cookie used since SEOPress 10.4 either.

The cached page is now the same for every visitor, so there is nothing to exclude. Depending on your cache plugin, the rule is here:

  • WP Rocket: Advanced Rules tab, Never Cache Cookies field.
  • LiteSpeed Cache: Cache menu, Excludes tab, Do Not Cache Cookies field.

Save, then purge the whole cache.

JavaScript optimization

Since SEOPress 10.4, the cookie bar works with JavaScript optimization plugins without any exclusion. It reads and writes its cookie by itself, without the seopress-cookies library, so the order in which an optimizer runs the scripts no longer matters, and it still starts when the optimizer delays it until after the page has loaded. If you added the exclusions below, keeping them is harmless.

With SEOPress 10.3 or earlier, the cookie bar uses two scripts that must run in this order:

  • seopress-cookies: the library that reads and writes the consent cookies;
  • seopress-cookies-ajax: the cookie bar itself, which depends on the first one.

On those versions, if your cache plugin combines, defers or delays JavaScript and the cookie bar does not appear (the browser console shows Cookies is not defined), exclude both scripts from each JavaScript optimization you have enabled. Excluding only one of them is what breaks the bar.

  • WP Rocket (File Optimization tab): add them to the Excluded JavaScript Files field of Minify JavaScript files, Load JavaScript deferred and Delay JavaScript execution.
  • LiteSpeed Cache (Page Optimization menu): add them to JS Excludes (JS Settings tab, used by JS Combine) and to JS Deferred / Delayed Excludes (Tuning tab, used by Load JS Deferred in both Deferred and Delayed modes).

Enter one per line:

seopress-cookies
seopress-cookies-ajax

Save and purge the cache. Updating to SEOPress 10.4 or later removes the need for these exclusions.

Test that one visitor’s choice does not affect another

  1. Enable the page cache and explicit opt-in; leave automatic acceptance disabled.
  2. In browser A, start with no saved choice, load a page, accept and revisit it so the cache is populated.
  3. In a separate browser B with no saved choice, open the same URL. The banner must still ask for a decision. Decline and check that B does not inherit A’s permission.
  4. Return to A and confirm its acceptance is retained. Reverse the order: prime the cache from a declining visitor and then visit from an accepting browser.
  5. Use the preferences button to change a choice and check both the current page and a subsequent navigation.

The presence of tracking configuration in the page source does not prove that it has executed. Inspect network requests and the trackers’ consent state as well. A custom script already executed on a page needs its own handling for consent withdrawal.

For developers

SEOPress 10.4 adds two filters. Add them to a custom plugin or your child theme’s functions.php.

seopress_user_consent_categories changes the label and description of the categories shown in the banner. Only these two fields can be changed: the category slugs (necessary, analytics, advertising) and the Consent Mode signals they grant stay as they are, and you cannot add a category.

add_filter( 'seopress_user_consent_categories', function( $categories ) {
	$categories['analytics']['label']       = 'Statistics';
	$categories['analytics']['description'] = 'Visit statistics that help us improve the site.';
	return $categories;
} );

seopress_user_consent_snippet_categories changes which categories each tracker waits for. The keys are gtag_js (Google Analytics), matomo_js and matomo_body_js (Matomo), clarity_js (Clarity), head_js, body_js and footer_js (HEAD, BODY and FOOTER tracking code) and custom (code added with the seopress_custom_tracking filter). Each value is a list of alternatives, and each alternative a list of categories that must all be allowed: array( array( 'analytics' ), array( 'advertising' ) ) starts on either, array( array( 'analytics', 'advertising' ) ) only on both. Unknown categories are ignored, and a tracker left without a valid category waits for both. The filter applies to trackers held until consent, not to automatic acceptance on page load.

add_filter( 'seopress_user_consent_snippet_categories', function( $requirements ) {
	// Start the HEAD, BODY and FOOTER tracking code on Analytics alone.
	$requirements['head_js']   = array( array( 'analytics' ) );
	$requirements['body_js']   = array( array( 'analytics' ) );
	$requirements['footer_js'] = array( array( 'analytics' ) );
	return $requirements;
} );

In the browser, window.seopressConsent.has( 'analytics' ) tells whether a category is allowed, and window.seopressConsent.categories() returns the allowed categories (null before any answer). After each choice, SEOPress pushes a seopress_consent_updated event to the dataLayer and fires a seopress.consent event on document. Since SEOPress 10.4, they carry the list of categories (seopress_consent_categories in the dataLayer, detail.categories in the event), and the summary value can be accept, decline or partial.

The seopress_user_consent filter still sets the default Consent Mode state printed at the top of the page. The admin-ajax actions seopress_cookies_user_consent and seopress_cookies_user_consent_close, no longer used by the banner since SEOPress 10.3, were removed in SEOPress 10.4.