Answer the question
In order to leave comments, you need to log in
How to activate the visor in Yandex Metrica in PHP?
I'm trying to create a Yandex metrics counter - it doesn't work. More precisely, it is possible to create a regular counter, but not with a click map and a webvisor.
Here is the code to create a regular counter:
$data = array(
'site' => "$url",
'name' => "$name",
'oauth_token' => 'TOKEN'
);
$url = "http://api-metrika.yandex.ru/counters";
$content = json_encode($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($curl);
$code_options = array(
'clickmap' => '1',
'visor' => '1'
);
$c_options = json_encode($code_options);
$data = array(
'site' => "$url",
'name' => "$name",
'code_options' => "$c_options",
'oauth_token' => 'TOKEN'
);
$url = "http://api-metrika.yandex.ru/counters";
$content = json_encode($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($curl);
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