You are here

public function GoogleAnalyticsReportsApiFeed::query in Google Analytics Reports 7.3

Public query method for all Core Reporting API features.

6 calls to GoogleAnalyticsReportsApiFeed::query()
GoogleAnalyticsReportsApiFeed::queryAccounts in google_analytics_reports_api/google_analytics_reports_api.lib.inc
Query Management API - Accounts.
GoogleAnalyticsReportsApiFeed::queryGoals in google_analytics_reports_api/google_analytics_reports_api.lib.inc
Query Management API - Goals.
GoogleAnalyticsReportsApiFeed::queryProfiles in google_analytics_reports_api/google_analytics_reports_api.lib.inc
Query Management API - Profiles.
GoogleAnalyticsReportsApiFeed::queryReportFeed in google_analytics_reports_api/google_analytics_reports_api.lib.inc
Query and sanitize report data.
GoogleAnalyticsReportsApiFeed::querySegments in google_analytics_reports_api/google_analytics_reports_api.lib.inc
Query Management API - Segments.

... See full list

File

google_analytics_reports_api/google_analytics_reports_api.lib.inc, line 268
Provides the Google Analytics Reports API Feed object type and associated methods.

Class

GoogleAnalyticsReportsApiFeed
GoogleAnalyticsReportsApiFeed class to authorize access to and request data from the Google Analytics Core Reporting API.

Code

public function query($url, $params = array(), $method = 'GET', $headers, $cache_options = array()) {
  $params_defaults = array(
    'start-index' => 1,
    'max-results' => 1000,
  );
  $params += $params_defaults;

  // Provide cache defaults if a developer did not override them.
  $cache_defaults = array(
    'cid' => NULL,
    'bin' => 'cache',
    'expire' => google_analytics_reports_api_cache_time(),
    'refresh' => FALSE,
  );
  $cache_options += $cache_defaults;

  // Provide a query MD5 for the cid if the developer did not provide one.
  if (empty($cache_options['cid'])) {
    $cache_options['cid'] = 'google_analytics_reports_data:' . md5(serialize(array_merge($params, array(
      $url,
      $method,
    ))));
  }
  $cache = cache_get($cache_options['cid'], $cache_options['bin']);
  if (!$cache_options['refresh'] && isset($cache) && !empty($cache->data) && $cache->expire > REQUEST_TIME) {
    $this->response = $cache->data;
    $this->results = json_decode($this->response->data);
    $this->fromCache = TRUE;
  }
  else {
    $this
      ->request($url, $params, $headers);
  }
  if (empty($this->error)) {
    cache_set($cache_options['cid'], $this->response, $cache_options['bin'], $cache_options['expire']);
  }
  return empty($this->error);
}