You are here

function google_analytics_update_8300 in Google Analytics 4.x

Same name and namespace in other branches
  1. 8.3 google_analytics.install \google_analytics_update_8300()

Migrate create only fields to gtag.js parameters.

File

./google_analytics.install, line 80
Installation file for Google Analytics module.

Code

function google_analytics_update_8300() {
  $config = \Drupal::configFactory()
    ->getEditable('google_analytics.settings');
  $create_only_fields = $config
    ->get('codesnippet.create');
  $parameters = [
    'client_id' => $create_only_fields['clientId'],
    'cookie_name' => $create_only_fields['cookieName'],
    'cookie_domain' => $create_only_fields['cookieDomain'],
    'cookie_expires' => $create_only_fields['cookieExpires'],
    'sample_rate' => $create_only_fields['sampleRate'],
    'site_speed_sample_rate' => $create_only_fields['siteSpeedSampleRate'],
    'use_amp_client_id' => $create_only_fields['useAmpClientId'],
    'user_id' => $create_only_fields['userId'],
  ];
  $parameters = array_filter($parameters);
  $config
    ->set('codesnippet.create', $parameters)
    ->save();
  return t('Migrated create only fields to gtag.js parameters.');
}