Sorry, I'm a bit late with this and I'm not sure how relevant this issue is.
Anyway, when I updated from 2.1.0 to 2.1.2 I thought my settings would stay the same as they were. However, this was not the case with Google Consent mode. I had intentionally set it to v2 before and it changed to v1.

This happened because of the update hook

function cookieinformation_update_9201() {
  $config_factory = \Drupal::configFactory();
  $config = $config_factory->getEditable('cookieinformation.settings');

  if ($config->get('enable_google_consent_mode')) {
    $config->set('google_consent_mode', 'v1');
  }
  elseif($config->get('enable_google_consent_mode_v2')) {
    $config->set('google_consent_mode', 'v2');
  }
  else {
    $config->set('google_consent_mode', '');
  }

It turns out my issue happened because I had checked both checkboxes v1 and v2 in the old version. The if block above seems to assume right away that if I have v1 enabled it will give me v1 in the future. I'm not a Google consent mode expert but I'd think it would be a bit more logical to check for v2 first? If you had both v1 and v2 enabled in the past, you would want to use only v2. So maybe change those around?

  if ($config->get('enable_google_consent_mode_v2')) {
    $config->set('google_consent_mode', 'v2');
  }
  elseif($config->get('enable_google_consent_mode')) {
    $config->set('google_consent_mode', 'v1');
  }
  else {
    $config->set('google_consent_mode', '');
  }

What do you think?

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

hartsak created an issue. See original summary.

heikkiy’s picture

Hi @hartsak.

Thank you for the message. Yes, the old implementation for the settings was a bit confusing and we also mixed them a bit when we were trying to figure out how to support both v1 and v2. Sorry for the bad UX that originally caused this issue.

I think in the process we initially thought that people by default have been using v1 and we didn't want to suddenly switch the default to v2 without them acknowleding any other change they might need to do for example in the Cookie information template.

The change should be still be visible in the config that you see the correct v1 or v2 version so the change should be pretty easy to catch.

I am trying to think if you should in the future enforce v1 or v2 if both have been selected before.

heikkiy’s picture

Version: 2.1.2 » 2.2.x-dev

heikkiy’s picture

Status: Active » Needs review

I think this change could be done for both the new 2.2.x and previous 2.1.x branches. I will make a MR for both.

Then we could release 2.1.5 and 2.2.1 with the small backward compatibility fix.

  • heikkiy committed c9703554 on 2.2.x
    Issue #3477206: Google consent mode changed from v2 to v1 when updating...

kekkis’s picture

Status: Needs review » Reviewed & tested by the community

LGTM here too. On both MRs.

  • heikkiy committed 14b852cf on 2.1.x
    Issue #3477206 by heikkiy, hartsak, kekkis: Google consent mode changed...
heikkiy’s picture

Status: Reviewed & tested by the community » Fixed

Merged to both 2.1.x and 2.2.x. Credited the fix to you.

Status: Fixed » Closed (fixed)

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