Skip to content

Google Consent Mode v2: gtag.js rules remain active after switching to GTM integration #178

@ricktibbe

Description

@ricktibbe

Describe the bug
When Google Consent Mode v2 (GCM) is enabled, region rulesets configured under the default implementation “Google tag (gtag.js)” remain active even after switching the implementation to “Google Tag Manager (GTM) template”. This leads to conflicting behavior where the old gtag.js region rulesets can override consent configuration that is set up via GTM.

Steps to reproduce

  1. Go to Cookie Consent → Settings → Consent mode.
  2. Enable Google Consent Mode v2 (GCM).
  3. Ensure the implementation is set to Google tag (gtag.js) (default).
  4. Configure one or more regions using the gtag.js implementation. Save changes.
  5. Switch the implementation to Google Tag Manager (GTM) template. Save changes.
  6. Configure consent/regions via GTM (e.g. using the Pressidium Cookie Consent tag template).
  7. Using the GTM previewer, observe that behavior still reflects (or is overridden by) the previously configured gtag.js region rulesets, despite GTM template being selected.

Expected behavior
When the user switches the GCM implementation from gtag.js to GTM template, any region rulesets and related logic belonging to the gtag.js implementation should be disabled/unloaded (not applied on the frontend) unless gtag.js is the selected implementation.

Environment

  • Plugin version: 1.9.1
  • WordPress version: 6.9
  • PHP version: 8.5

Additional context
This seems like an implementation “leak” between two mutually exclusive modes. If region rulesets are stored in shared settings and always injected/applied regardless of selected implementation, switching to GTM template effectively runs GTM configuration plus the gtag.js regional overrides.

Suggested fix
When GTM template is selected, prevent the plugin from outputting/applying any gtag.js-specific region rulesets (and vice versa). At minimum, unload/disable the previously configured gtag.js region rulesets at runtime when that implementation is not selected, so GTM can be the single source of truth for regional consent behavior.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions