You are here

function ga_stats_query_data in Google Analytics Statistics 7.2

Same name and namespace in other branches
  1. 7 includes/ga.inc \ga_stats_query_data()
  2. 7.x inc/ga.inc \ga_stats_query_data()

Query GA for a particular dataset.

Parameters

gapi $client: @param array $request

  • report_id
  • dimensions
  • metrics
  • sort_metric=null
  • filter=null
  • start_date=null
  • end_date=null
  • start_index=1
  • max_results=30

@return array

1 call to ga_stats_query_data()
ga_stats_ga_data in includes/ga.inc
Use the client library to query GA for fresh data.

File

includes/ga.inc, line 268

Code

function ga_stats_query_data($client, $request) {
  try {
    $data = $client
      ->requestReportData(variable_get('ga_stats_profile', ''), $request['dimensions'], $request['metrics'], $request['sort_metric'], NULL, $request['start_date'], $request['end_date'], 1, $request['max_results']);
  } catch (Exception $e) {
    watchdog('ga_stats', $e
      ->getMessage(), array(), WATCHDOG_ERROR);
    return array();
  }
  if (empty($data)) {

    // At this point in the call stack, $request['metrics'] will have only one item.
    watchdog('ga_stats', 'Successfully contacted Google Analytics, but an empty dataset was found for "!metric" between "!start" and "!end".', array(
      '!metric' => reset($request['metrics']),
      '!start' => $request['start_date'],
      '!end' => $request['end_date'],
    ), WATCHDOG_WARNING);
  }
  else {
    watchdog('ga_stats', 'Successfully retrieved data from Google Analytics.');
  }
  return $data;
}