A
A
Alexander2018-10-09 15:19:28
JavaScript
Alexander, 2018-10-09 15:19:28

How to get the ClientID of Yandex.Metrica?

Hello!
Can you tell me how to use this method?
https://yandex.ru/support/metrika/objects/get-clie...
I try corny like this - the 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.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
xoo, 2018-10-09
@xoo

Try like this

<script type="text/javascript">
window.onload = function(){
  var clientid = yaCounter99999.getClientID();
  console.log(clientid);
}
</script>

The counter does not have time to initialize, I think so

D
Dmitry Eremin, 2018-10-09
@EreminD

initialize the counter first List of fields that can be defined in settings - on the same page

A
Anton Kravchenko, 2018-10-09
@AntonKravchenko

alternatively you can use:

function GetYMCID() {    
    var match = document.cookie.match('(?:^|;)\\s*_ym_uid=([^;]*)');
    return (match) ? decodeURIComponent(match[1]) : false;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question