You are here

function yandex_metrics_reports_retreive_data in Yandex.Metrics 8.2

Same name and namespace in other branches
  1. 8.3 yandex_metrics_reports/yandex_metrics_reports.module \yandex_metrics_reports_retreive_data()
  2. 6.2 yandex_metrics_reports/yandex_metrics_reports.module \yandex_metrics_reports_retreive_data()
  3. 7.3 yandex_metrics_reports/yandex_metrics_reports.module \yandex_metrics_reports_retreive_data()
  4. 7.2 yandex_metrics_reports/yandex_metrics_reports.module \yandex_metrics_reports_retreive_data()

This is the helper function to retreive analytic information from Yandex.Metrics.

Parameters

string $service_uri - short uri of service:

array $parameters - associative array with parameters:

string $result_type - result type (json, xml):

14 calls to yandex_metrics_reports_retreive_data()
Reports::gender_chart in yandex_metrics_reports/src/Reports.php
The function generates pie chart with demography information.
Reports::geo_chart in yandex_metrics_reports/src/Reports.php
The function generates pie chart with geographical information on visitors.
Reports::hourly_chart in yandex_metrics_reports/src/Reports.php
The function generates chart with information about hourly traffic.
Reports::sources_chart in yandex_metrics_reports/src/Reports.php
The function generates pie chart with traffic sources summary.
Reports::visits_chart in yandex_metrics_reports/src/Reports.php
The function generates chart with information about page views, visitors and new visitors.

... See full list

File

yandex_metrics_reports/yandex_metrics_reports.module, line 92
The main code of Yandex.Metrics Reports module.

Code

function yandex_metrics_reports_retreive_data($service_uri, $parameters = array(), $result_type = 'json') {
  $parameters['oauth_token'] = yandex_services_auth_info('token');
  $query_parts = array();
  foreach ($parameters as $key => $value) {
    $query_parts[] = $key . '=' . $value;
  }
  $parameter_string = implode('&', $query_parts);
  $full_service_url = "http://api-metrika.yandex.ru" . $service_uri . "." . $result_type . "?" . $parameter_string;
  $request = Drupal::httpClient()
    ->get($full_service_url);
  try {
    $response = $request
      ->send();
    return $response;
  } catch (RequestException $e) {
    watchdog_exception('yandex_metrics_reports', $e);
    return FALSE;
  } catch (ClientErrorResponseException $e) {
    watchdog_exception('yandex_metrics_reports', $e);
    return FALSE;
  } catch (\Exception $e) {
    watchdog_exception('yandex_metrics_reports', $e);
    return FALSE;
  }
}