You are here

function _ga_stats_update_counts in Google Analytics Statistics 7

Same name and namespace in other branches
  1. 7.2 includes/ga.inc \_ga_stats_update_counts()

Goes through sources and metrics and updates databases

Views cannot tell the difference between the various metrics and timeframes so we delete all counts before rebuilding.

Return value

int|bool

1 call to _ga_stats_update_counts()
ga_stats_update_counts in ./ga_stats.module
Refresh local cache of GA data.

File

includes/ga.inc, line 11

Code

function _ga_stats_update_counts() {
  $client = ga_stats_get_client();
  if (isset($client)) {
    $data = ga_stats_collect_data($client);
  }

  // Only wipe the data if we retrieved something to replace it with.
  if (!empty($data)) {
    db_query('DELETE FROM {ga_stats_count}');
    foreach ($data as $record) {
      ga_stats_write_count($record);
    }
    drupal_set_message(t('Counts Successfully Updated'));
    watchdog('ga_stats', 'Updated statistics for !count records.', array(
      '!count' => count($data),
    ));

    // Only schedule a new update if this was successful. If it failed, we should try to run a new
    // update in the next available opportunity. Request flooding is not the purpose of the scheduler.
    return ga_stats_schedule_update();
  }
  return FALSE;
}