You are here

function ga_stats_query_data in Google Analytics Statistics 7.x

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

Parameters

$metric - one of the metrics values - a string value - i.e. 'pageviews': $report_id, $dimensions, $metrics, $sort_metric=null, $filter=null, $start_date=null, $end_date=null, $start_index=1, $max_results=30

1 call to ga_stats_query_data()
ga_stats_ga_data in inc/ga.inc
call back funciton for pulling data from google anaylics

File

inc/ga.inc, line 142

Code

function ga_stats_query_data($request) {

  //this is really a waste I think because this shit is preprocessed
  require_once 'gapi.class.php';
  $user = variable_get('ga_stats_email', '');
  $password = variable_get('ga_stats_password', '');
  $aid = variable_get('ga_stats_profile', '');
  if ($user && $password) {
    try {
      $ga = new gapi($user, $password);
      $data = $ga
        ->requestReportData($aid, $request['dimensions'], $request['metrics'], $request['sort_metric'], null, $request['start_date'], $request['end_date'], 1, $request['max_results']);
    } catch (Exception $e) {
      drupal_set_message('Invalid Google Analytics login.', 'error');
      watchdog('ga_stats', 'Invalid Google Analytics login.');
      return array();
    }
    return $data;
  }
  else {
    drupal_set_message('Google Analytics Email and password not set.', 'error');
    watchdog('ga_stats', 'Google Analytics email and password not set.');
  }
}