function _yandex_metrics_reports_search_phrases in Yandex.Metrics 6.2
The function generates content of search phrases table ordered by popularity.
Parameters
string $counter_id:
string $filter:
1 string reference to '_yandex_metrics_reports_search_phrases'
- yandex_metrics_reports_yandex_metrics_reports_list in yandex_metrics_reports/
yandex_metrics_reports.module - Implements hook_yandex_metrics_reports_list().
File
- yandex_metrics_reports/
yandex_metrics_reports.module, line 320 - The main code of Yandex.Metrics Reports module.
Code
function _yandex_metrics_reports_search_phrases($counter_id, $filter) {
$output = '';
$date_range = _yandex_metrics_reports_filter_to_date_range($filter);
$parameters = array(
'id' => $counter_id,
'date1' => $date_range['start_date'],
'date2' => $date_range['end_date'],
);
$report_phrases = yandex_metrics_reports_retreive_data('/stat/sources/phrases', $parameters);
$phrases = json_decode($report_phrases->data);
if (empty($phrases->data)) {
return t('There is no information about search phrases for the selected date range.');
}
$phrases_totals_visits = $phrases->totals->visits;
$header = array(
t('Visits (%)'),
t('Phrase'),
);
$data = array();
$i = 1;
foreach ($phrases->data as $value) {
if ($i > YANDEX_METRICS_SEARCH_PHRASES_QUANTITY) {
break;
}
$percentage = round(100 * $value->visits / $phrases_totals_visits, 2);
$data[] = array(
$percentage,
check_plain($value->phrase),
);
$i++;
}
return theme('table', $header, $data, array(), t("Popular Search Phrases"));
}