You are here

function google_analytics_requirements in Google Analytics 8.3

Same name and namespace in other branches
  1. 8.2 google_analytics.install \google_analytics_requirements()
  2. 4.x google_analytics.install \google_analytics_requirements()

Implements hook_requirements().

File

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

Code

function google_analytics_requirements($phase) {
  $requirements = [];
  if ($phase == 'runtime') {
    $config = \Drupal::config('google_analytics.settings');

    // Raise warning if Google user account has not been set yet.
    if (!preg_match('/^UA-\\d+-\\d+$/', $config
      ->get('account'))) {
      $requirements['google_analytics_account'] = [
        'title' => t('Google Analytics module'),
        'description' => t('Google Analytics module has not been configured yet. Please configure its settings from the <a href=":url">Google Analytics settings page</a>.', [
          ':url' => Url::fromRoute('google_analytics.admin_settings_form')
            ->toString(),
        ]),
        'severity' => REQUIREMENT_WARNING,
        'value' => t('Not configured'),
      ];
    }

    // Raise warning if debugging is enabled.
    if ($config
      ->get('debug')) {
      $requirements['google_analytics_debugging'] = [
        'title' => t('Google Analytics module'),
        'description' => t('Google Analytics module has debugging enabled. Please disable debugging setting in production sites from the <a href=":url">Google Analytics settings page</a>.', [
          ':url' => Url::fromRoute('google_analytics.admin_settings_form')
            ->toString(),
        ]),
        'severity' => REQUIREMENT_WARNING,
        'value' => t('Debugging enabled'),
      ];
    }

    // Raise warning if php code is being used.
    if ($config
      ->get('visibility.request_path_mode') && $config
      ->get('visibility.request_path_mode') === '2') {
      $requirements['google_analytics_php'] = [
        'title' => t('Google Analytics module'),
        'description' => t('Using PHP code in Google Analytics is deprecated and not available in Drupal 9. You must move your logic into a custom module, and change the <a href=":url">Page Visibility settings</a> to suppress this message.', [
          ':url' => Url::fromRoute('google_analytics.admin_settings_form')
            ->toString(),
        ]),
        'severity' => REQUIREMENT_ERROR,
        'value' => t('PHP code exists'),
      ];
    }
  }
  return $requirements;
}