Google consent mode changed from v2 to v1 when updating from older versions

Created on 27 September 2024, 3 months ago

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?

🐛 Bug report
Status

Active

Version

2.1

Component

Miscellaneous

Created by

🇫🇮Finland hartsak

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024