Problem/Motivation

The opt-out switch (pianoanalytics-optout-switch.js) has three issues:

  1. Unchecking the switch hardcodes the consent mode back to 'essential':

    If the visitor had previously granted full consent ('opt-in', e.g. through a CMP integration), that choice is silently lost: after an opt-out round trip they end up in 'essential' instead of their actual prior choice.

  2. Toggling the switch only updates localStorage, the pa_consent_mode cookie and the body class. The live SDK keeps its current purposes until the next page load.

  3. In _configurePrivacy(), when localStorage holds no valid mode and cnil_exempt is disabled, setAllPurposes() is never called and setConsentBodyClass() receives null, so the SDK state and the body class do not reflect any effective mode.

Steps to reproduce

  1. Grant full consent so pianoanalytics_consent_mode = 'opt-in'.
  2. Check the opt-out switch, then uncheck it.
  3. localStorage now holds 'essential' instead of the original 'opt-in'.
  4. Also: check the switch and observe that hits on the current page are still sent with the previous purposes until a reload.

Proposed resolution

  1. When toggling, save the current mode into a new pianoanalytics_consent_mode_prior localStorage key — only when it is not 'opt-out', so the saved value is always a real consent choice — and restore it when the switch is unchecked (removing the consent mode entirely when no prior exists).
  2. After a toggle, re-apply Drupal.pianoanalytics._configurePrivacy() (guarded on window.pa) so the new mode takes effect immediately, without a page reload.
  3. In _configurePrivacy(), fall back to paConsent.getMode() when no stored or exempt mode applies, and call setAllPurposes() unconditionally so SDK purposes and body class always reflect the effective mode.

The _prior key also gives consent integrations (e.g. a tarteaucitron bridge) a place to record the visitor's banner decision while the opt-out switch is active, so it can be restored on opt-back-in.

API changes

New localStorage key: pianoanalytics_consent_mode_prior.
No PHP API changes.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

funstenolf created an issue. See original summary.

funstenolf’s picture

Status: Active » Needs review

I added a merge request that do work of restoring prior consent mode after unchecking the opt-out switch.

  • mably committed f82831b7 on 2.x authored by funstenolf
    feat: #3593679 Opt-out switch: restore the prior consent mode when...
mably’s picture

Assigned: funstenolf » Unassigned
Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.