Answer the question
In order to leave comments, you need to log in
How to get the days when there were no visitors from the Yandex metrics API?
How can I get an empty (0) value using the Yandex Metrics API when I make a request with grouping with grouping.?
That is, when there were no visitors on the site that day, for example.
I display information for a month, but if there were no visitors on some day, then the api does not send information about this.
$context = stream_context_create(array(
'http' => array(
'method' => 'GET',
'header' => "Host: api-metrika.yandex.net\r\n" .
"Authorization: OAuth token\r\n" .
"Content-Type: application/x-yametrika+json\r\n"
)
));
$url = 'https://api-metrika.yandex.ru/stat/v1/data';
$allParams = [
'ids' => 'id',
'oauth_token' => 'token',
'lang' => 'ru',
];
// Визиты/Посетители/Просмотры/отказы/просмотр по времени
$defaultParams = array_merge($allParams , [
'metrics' => 'ym:s:visits,ym:s:pageviews,ym:s:users,ym:s:bounceRate,ym:s:avgVisitDurationSeconds',
]);
//дефолт даты
$defaultFirstDate = array_merge($defaultParams,[
'date1' => '30daysAgo',
'date2' => 'today',
]);
$params_TrafficSourceFirst = array_merge($defaultFirstDate , [
'filters' => rawurldecode("ym:s:trafficSource=='organic'"),
'dimensions' => 'ym:s:trafficSource,ym:s:date',
'sort' => 'ym:s:date',
]);
$json_TrafficSourceFirst = file_get_contents( $url . '?' . http_build_query($params_TrafficSourceFirst),false, $context );
$data_TrafficSourceFirst = json_decode($json_TrafficSourceFirst, true)['data'];
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question