public function GoogleAnalyticsCounterFeed::query in Google Analytics Counter 8.3
Public query method for all Core Reporting API features.
Parameters
$url:
$params:
$method:
$headers:
array $cache_options:
Return value
bool
Throws
\GuzzleHttp\Exception\GuzzleException
6 calls to GoogleAnalyticsCounterFeed::query()
- GoogleAnalyticsCounterFeed::queryAccounts in src/
GoogleAnalyticsCounterFeed.php - Query Management API - Accounts.
- GoogleAnalyticsCounterFeed::queryGoals in src/
GoogleAnalyticsCounterFeed.php - Query Management API - Goals.
- GoogleAnalyticsCounterFeed::queryProfiles in src/
GoogleAnalyticsCounterFeed.php - Query Management API - Profiles.
- GoogleAnalyticsCounterFeed::queryReportFeed in src/
GoogleAnalyticsCounterFeed.php - Query and sanitize report data.
- GoogleAnalyticsCounterFeed::querySegments in src/
GoogleAnalyticsCounterFeed.php - Query Management API - Segments.
File
- src/
GoogleAnalyticsCounterFeed.php, line 339
Class
- GoogleAnalyticsCounterFeed
- Authorize access and request data from Google Analytics Core Reporting API.
Namespace
Drupal\google_analytics_counterCode
public function query($url, $params, $method, $headers, $cache_options = array()) {
$params_defaults = [
'start-index' => 1,
'max-results' => 1000,
];
$params += $params_defaults;
// Provide cache defaults if a developer did not override them.
$cache_defaults = [
'cid' => NULL,
'expire' => GoogleAnalyticsCounterHelper::cacheTime(),
'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'] = 'GoogleAnalyticsCounterFeed:' . md5(serialize(array_merge($params, [
$url,
$method,
])));
}
$cache = \Drupal::cache()
->get($cache_options['cid']);
if (!$cache_options['refresh'] && isset($cache) && !empty($cache->data)) {
$this->results = $cache->data;
$this->fromCache = TRUE;
}
else {
$this
->request($url, $params, $headers);
}
if (empty($this->error)) {
// @todo remove cache, use default cache('default')
// Don't save $this->results, because the object will lose steam resource
// when caching, but it will lose response.
\Drupal::cache()
->set($cache_options['cid'], $this->results, $cache_options['expire']);
}
return empty($this->error);
}