Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get clientId in Android Google Analytics V4?

I am trying to get the automatically set Analytics clientId in Android. (Setting it is explained in the Android API documentation as setClientId())

When I try to use tracker.get("clientId") it returns empty. Any idea anyone?

Thanks in advance!

like image 358
Koen Avatar asked Jul 28 '15 10:07

Koen


People also ask

What is Google Analytics Clientid?

In order for Google Analytics to determine that two distinct hits belong to the same user, a unique identifier, associated with that particular user, is sent with each hit via the Client ID field. The unique identifier is a randomly generated string.

Where do I find Cid in Google Analytics?

Open your website in Chrome, press F12, go to the Network tab, refresh the page, and in the Filter field, write a collect to see which queries go to Google Analytics: We find cuk cid in the query parameters and see that cd1 has appeared – that is, the second arbitrary parameter with the same value as that of cid.


1 Answers

I've ran a decompiler on it for you and it seems like the clientId property is stored with the key "&cid".

Internally it does this:

set("&cid", clientId);

The solution would be to call this:

tracker.get("&cid");

The get() method does however have special logic for the client ID key. It might also return a newly generated key or throw an InterruptedException like "ClientId loading or generation was interrupted" or an ExecutionException "Failed to load or generate client id"

You can solve these kinds of issues yourself in Android Studio (or IntelliJ IDEA) by installing the "Java Bytecode Decompiler" or "Java Decompiler IntelliJ Plugin" plugins. This allows you to find the Tracker.class symbol and view it as if it was a Java regular file.

like image 60
Byte Welder Avatar answered Oct 25 '22 10:10

Byte Welder