function _yandex_metrics_search_phrases in Yandex.Metrics 7
Same name and namespace in other branches
- 6 yandex_metrics.module \_yandex_metrics_search_phrases()
The function generates content of search phrases table ordered by popularity.
Parameters
string $counter_id:
string $filter:
2 calls to _yandex_metrics_search_phrases()
- yandex_metrics_ajax in ./
yandex_metrics.module - Menu callback; outputs content of one of the 4 reports. It is intended for AJAX calls.
- yandex_metrics_report in ./
yandex_metrics.module - Menu callback; displays a Summary page containing reports and charts.
File
- ./
yandex_metrics.module, line 385 - The main code of Yandex.Metrics module.
Code
function _yandex_metrics_search_phrases($counter_id, $filter) {
$output = '';
$date_range = _yandex_metrics_filter_to_date_range($filter);
$parameters = array(
'id' => $counter_id,
'date1' => $date_range['start_date'],
'date2' => $date_range['end_date'],
);
$report_phrases = yandex_metrics_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', array(
'header' => $header,
'rows' => $data,
'caption' => t("Popular Search Phrases"),
));
}