You are here

function ga_stats_update_counts in Google Analytics Statistics 7.x

Same name and namespace in other branches
  1. 7.2 ga_stats.module \ga_stats_update_counts()
  2. 7 ga_stats.module \ga_stats_update_counts()
1 call to ga_stats_update_counts()
ga_stats_cron in ./ga_stats.module
1 string reference to 'ga_stats_update_counts'
ga_stats_admin_settings in ./ga_stats.module

File

./ga_stats.module, line 76

Code

function ga_stats_update_counts() {
  $metrics = ga_stats_ga_metrics();
  $timeframes = ga_stats_ga_timeframes();
  $data = array();
  $user = variable_get('ga_stats_email', '');
  $password = variable_get('ga_stats_password', '');
  $aid = variable_get('ga_stats_profile', '');
  if ($user && $password) {
    foreach ($metrics as $metric => $title) {
      foreach ($timeframes as $key => $time) {
        $filter = isset($time['filter']) ? $time['filter'] : null;
        $new_data = ga_stats_get_data($metric, time() - $time['secsToSub'], time(), $key, $filter);
        $data = array_merge($data, $new_data);
      }
    }
    db_query('DELETE FROM {ga_stats_count}');
    foreach ($data as $obj) {
      ga_stats_write_count($obj);
    }
    drupal_set_message('Counts Successfully Updated');
    return $data;
  }
  else {
    drupal_set_message('Google Analytics email and password not set.', 'error');
  }
}