function yandex_metrics_reports_get_counter_for_current_site in Yandex.Metrics 6.2
Same name and namespace in other branches
- 8.3 yandex_metrics_reports/yandex_metrics_reports.module \yandex_metrics_reports_get_counter_for_current_site()
- 8.2 yandex_metrics_reports/yandex_metrics_reports.module \yandex_metrics_reports_get_counter_for_current_site()
- 7.3 yandex_metrics_reports/yandex_metrics_reports.module \yandex_metrics_reports_get_counter_for_current_site()
- 7.2 yandex_metrics_reports/yandex_metrics_reports.module \yandex_metrics_reports_get_counter_for_current_site()
Gets counter ID for the current site from Yandex.Metrics.
2 calls to yandex_metrics_reports_get_counter_for_current_site()
- yandex_metrics_reports_report in yandex_metrics_reports/
yandex_metrics_reports.module - Menu callback; displays a Summary page containing reports and charts.
- yandex_metrics_reports_save_popular_content in yandex_metrics_reports/
yandex_metrics_reports.module - Fetch Popuplar content from Yandex.metrika and save it to the database.
File
- yandex_metrics_reports/
yandex_metrics_reports.module, line 666 - The main code of Yandex.Metrics Reports module.
Code
function yandex_metrics_reports_get_counter_for_current_site() {
$counter_id = variable_get('yandex_metrics_reports_counter_id', '');
if (!empty($counter_id)) {
return $counter_id;
}
$result = yandex_metrics_reports_retreive_data('/counters', array(
'field' => 'mirrors',
));
if (isset($result->error)) {
watchdog('yandex_metrics_reports', 'Counters request seems to be fail, due to "%error".', array(
'%error' => $result->code . ' ' . $result->error,
), WATCHDOG_WARNING);
return;
}
$counters = json_decode($result->data);
$current_host = $_SERVER['HTTP_HOST'];
// Try to decode national domain.
$decoded_domain = _yandex_metrics_reports_idna_decode($current_host);
if ($decoded_domain != FALSE && $decoded_domain != $current_host) {
$current_host = $decoded_domain;
}
foreach ($counters->counters as $key => $counter) {
if ($counter->site == $current_host) {
variable_set('yandex_metrics_reports_counter_id', $counter->id);
return $counter->id;
}
// If current host is equal of any site mirror.
if (isset($counter->mirrors) && in_array($current_host, $counter->mirrors)) {
variable_set('yandex_metrics_reports_counter_id', $counter->id);
return $counter->id;
}
}
return FALSE;
}