You are here

ga.install in Googalytics - Google Analytics 8

Contains ga module installation and update hooks.

File

ga.install
View source
<?php

/**
 * @file
 * Contains ga module installation and update hooks.
 */
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Implements hook_requirements().
 */
function ga_requirements($phase) {
  $requirements = [];
  if ($phase == 'runtime' && \Drupal::moduleHandler()
    ->moduleExists('gacsp')) {
    $requirements['ga_gacsp'] = [
      'severity' => REQUIREMENT_WARNING,
      'title' => new TranslatableMarkup('gacsp module'),
      'value' => new TranslatableMarkup('Enabled'),
      'description' => new TranslatableMarkup('To prevent duplicate tracking, Googalytics will not activate until gacsp module is uninstalled.'),
    ];
  }
  return $requirements;
}

/**
 * Implements hook_install().
 */
function ga_install() {
  _ga_copy_gacsp_config();
}

/**
 * Copy config from gacsp if available.
 */
function _ga_copy_gacsp_config() {
  $gacspConfig = \Drupal::configFactory()
    ->getEditable('gacsp.settings')
    ->getRawData();
  if (!empty($gacspConfig)) {
    \Drupal::configFactory()
      ->getEditable('ga.settings')
      ->setData($gacspConfig)
      ->set('premium', FALSE)
      ->set('sample_rate', 100)
      ->set('site_speed_sample_rate', 1)
      ->set('force_ssl', FALSE)
      ->save();
  }
}

/**
 * Add premium flag to configuration.
 */
function ga_update_8101() {
  \Drupal::configFactory()
    ->getEditable('ga.settings')
    ->set('premium', FALSE)
    ->save();
}

/**
 * Add default sample rate setting to configuration.
 */
function ga_update_8102() {
  \Drupal::configFactory()
    ->getEditable('ga.settings')
    ->set('sample_rate', 100)
    ->save();
}

/**
 * Add default site speed sample rate setting to configuration.
 */
function ga_update_8103() {
  \Drupal::configFactory()
    ->getEditable('ga.settings')
    ->set('site_speed_sample_rate', 1)
    ->save();
}

/**
 * Add default force SSL setting to configuration.
 */
function ga_update_8104() {
  \Drupal::configFactory()
    ->getEditable('ga.settings')
    ->set('force_ssl', FALSE)
    ->save();
}

Functions

Namesort descending Description
ga_install Implements hook_install().
ga_requirements Implements hook_requirements().
ga_update_8101 Add premium flag to configuration.
ga_update_8102 Add default sample rate setting to configuration.
ga_update_8103 Add default site speed sample rate setting to configuration.
ga_update_8104 Add default force SSL setting to configuration.
_ga_copy_gacsp_config Copy config from gacsp if available.