STeN
STeN

Reputation: 61

Google Analytics 4 and client id (IoT devices, older specialized and incompatible browsers, etc.)

There are devices where you cannot use Kotlin/Java or the Swift/Objective-C library for GA4, as well as gtag.js (https://developers.google.com/analytics/devguides/collection).

This could be IoT devices, older specialized and incompatible browsers or platforms like Roku, win32 app... simply any platform that the Google does not provide a library.

For such cases I guess there is Measurement Protocol (Google Analytics 4) (https://developers.google.com/analytics/devguides/collection/protocol/ga4) that allows use of the HTTP requests and call the API Google Analytics endpoint directly.

That is okay, but there is one problem. The question is where to get the client_id value (it has format 'GA.1.1' + unique identifier + Unix timestamp) used to identify the device required in an HTTP API request. It is written everywhere that In order for an event to be valid, it must have a client_id that has already been used to send an event from gtag.js.

The same is true if you want to use Google Analytics for Firebase. The similar app_instance_id value is used here, but the documentation says: In order for an event to be valid, it must have an app_instance_id that has already been used to send an event from the Google Analytics for Firebase SDK.

But what if neither gtag.js or Firebase SDK is not available on the target platform?

What remains is to generate the client_id manually and save it locally on the device. The question is whether it is okay. I believe that the unique identifier part from the format 'GA.1.1' + unique identifier + Unix timestamp is not just an ordinary random number, but that at least some bit flags may have some meaning.

It's interesting that apps I have seen usually generated UUID or some other identifier in a different format. Roku, for example, uses GetClientTrackingId() function (https://developer.roku.com/en-gb/docs/references/brightscript/interfaces/ifdeviceinfo.md#getchannelclientid-as-string), whose the result is a string in a completely different format (e.g. YR007C832727)...

Any advice on what is the correct implementation?

The post here (Google Analytics 4 - Measurement Protocol API used without gtag.js or firebase) suggest it is really random value, but in GA3 it was almost certainly used e.g. to encode the sample rate (https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#sampleRate)...

Thanks a lot Petr

Upvotes: 1

Views: 272

Answers (0)

Related Questions