user2979757 user2979757 - 1 month ago 20
Javascript Question

how to get the Google analytics client ID

When you are creating a new instance of analytics.js by running

ga('create', 'UA-XXXXXXX-Y', {'cookieDomain': 'none'});


GA creates a unique client Id.
I want to fetch this id and use it for my own purposes,
but I can find only setter for this parameter but can't find any getter method to get it.

GA send it later in a parameter called
&cid=123123.232323


Does anyone knows how do I get it?

Answer

Google does have some documentation on getting the client id.

Looks like this:

ga(function(tracker) {
  var clientId = tracker.get('clientId');
});

I've used this before, too:

ga.getAll()[0].get('clientId');