1

I have to send Analytics4 events from php backend. The API require to send client_id

In some Php code samples, I see this id is randomely generated. But in official Google JS documentation, it is get from gtag

So, I suppose GA4 generate this id by itself.

My question is: Isn't it better to send client_id from GA4 instead of generating another one ? For example, when an user makes a pageview with classic JS tag, I suppose that if I use the same client_id to send event from my backend, Analytics will be able to know this is the same user for the two events...

Well wath is the good practice ? Thanks

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
wAx
  • 11
  • 2

1 Answers1

0

You can check this method as google recommends it.

You should not directly access the cookie analytics.js sets, as the cookie format might change in the future. Instead, developers should use the readyCallback to wait until analytics.js is loaded, and then get the clientId value stored on the tracker.

https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#getting_the_client_id_from_the_cookie

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 25 '22 at 12:01