You are here

function google_analytics_reports_api_report_data in Google Analytics Reports 8.3

Same name and namespace in other branches
  1. 7.3 google_analytics_reports_api/google_analytics_reports_api.module \google_analytics_reports_api_report_data()

Request report data.

Parameters

array $params: An associative array containing:

  • profile_id: required [default=variable_get('google_analytics_reports_api_profile_id')].
  • metrics: required.
  • dimensions: optional [default=none].
  • sort_metric: optional [default=none].
  • filters: optional [default=none].
  • segment: optional [default=none].
  • start_date: optional [default=2005-01-01].
  • end_date: optional [default=today].
  • start_index: optional [default=1].
  • max_results: optional [default=10,000].

array $cache_options: An optional associative array containing:

  • cid: optional [default=md5 hash].
  • expire: optional [default=CACHE_TEMPORARY].
  • refresh: optional [default=FALSE].

Return value

object GoogleAnalyticsReportsApiFeed object to authorize access and request data from the Google Analytics Core Reporting API after reporting data.

1 call to google_analytics_reports_api_report_data()
GoogleAnalyticsQuery::execute in src/Plugin/views/query/GoogleAnalyticsQuery.php
Executes the query and fills the associated view object with according values.

File

google_analytics_reports_api/google_analytics_reports_api.module, line 106
Implements the API through which Google Analytics data can be accessed.

Code

function google_analytics_reports_api_report_data(array $params = [], array $cache_options = []) {
  $config = \Drupal::config('google_analytics_reports_api.settings');
  if (isset($params['profile_id'])) {
    $params['profile_id'] = 'ga:' . $params['profile_id'];
  }
  else {
    $params['profile_id'] = 'ga:' . $config
      ->get('profile_id');
  }
  $ga_feed = google_analytics_reports_api_gafeed();
  if ($ga_feed) {
    $ga_feed
      ->queryReportFeed($params, $cache_options);
    return $ga_feed;
  }
  else {
    \Drupal::messenger()
      ->addMessage(t('There was an authentication error. Please check your Google Analytics API settings and try again.'), 'error', FALSE);
    \Drupal::logger('google_analytics_reports_api')
      ->error('There was an authentication error. Please check your Google Analytics API settings and try again.');
    return [
      'error' => TRUE,
    ];
  }
}