How to get ClientID Yandex.Metrics?

Hello!

Tell me how to use this method?
https://yandex.ru/support/metrika/objects/get-clie...

So corny try - error "yaCounter99999 is not defined"
<script type="text/javascript">
 var clientid = yaCounter99999.getClientID();
console.log(clientid);
</script>


PS: the meter Number is correct, not the one in the example.
March 12th 20 at 07:58
3 answers
March 12th 20 at 08:00
Try this
<script type="text/javascript">
window.onload = function(){
 var clientid = yaCounter99999.getClientID();
console.log(clientid);
}
</script>


Counter not time to be initialized, I think
March 12th 20 at 08:02
perform first initialization scecina
var yaCounterXXXXXX = new Ya.Metrika(settings);
A list of fields that you can define in settings - on the same page
But code install counter already placed.
Accordingly, the initialization has already passed it?
5bbca19d0b68b408953363.jpeg - gregoria.Reynol commented on March 12th 20 at 08:05
March 12th 20 at 08:04
alternative you can use:
GetYMCID function() { 
 var match = document.cookie.match('(?:^|;)\\s*_ym_uid=([^;]*)');
 return (match) ? decodeURIComponent(match[1]) : false;
}

Find more questions by tags Yandex.MetricaJavaScript