You are here

function google_analytics_cron in Google Analytics 8.3

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

Implements hook_cron().

File

./google_analytics.module, line 468
Drupal Module: Google Analytics.

Code

function google_analytics_cron() {
  $config = \Drupal::config('google_analytics.settings');
  $request_time = \Drupal::time()
    ->getRequestTime();

  // Regenerate the tracking code file every day.
  if ($request_time - \Drupal::state()
    ->get('google_analytics.last_cache') >= 86400 && $config
    ->get('cache')) {
    _google_analytics_cache('https://www.googletagmanager.com/gtag/js', TRUE);
    \Drupal::state()
      ->set('google_analytics.last_cache', $request_time);
  }
}