- Issue created by @Grevil
- 🇩🇪Germany Anybody Porta Westfalica
Yes we need to think about how to solve this and see if anyone already solved this for posthog in PHP or other languages!
- 🇩🇪Germany Anybody Porta Westfalica
@grevil please contact Posthog support and ask for best practices. Also ask how to identify an anonymous user server-side (null value) - if it's not possible to identify them. Frontend JS allows that, which is a bit strange.
- 🇩🇪Germany Grevil
Besides the frontend and backend capture calls, we also have the autocapture calls.
I already contacted the support regarding this on Thursday last week, but since we have the free plan, I don't think we'll get an answer.
Now I also contacted the support with a paid account (although the message is not as thought out). I wrote the following:
Hello,
I was wondering whether there is a way to programmatically sync the posthog distinct ID, in the front- (JS-SDK) and backend (PHP-SDK) for logged-out users (which optimally supports caching).
Basically, I would like to somehow generate a distinct ID for users with no unique information and use that distinct ID for the backend capture method calls, frontend capture method calls, and frontend auto capture calls.
Furthermore, I was wondering why the "distinctId" is optional for frontend "capture" method calls (uses auto generated UID as a fallback) but not for PHP-SDK "capture" method calls.
Thanks in advance!
Let's wait for their feedback!
- 🇩🇪Germany Grevil
This is the support answer:
We recommend passing any data you need to sync along to the backend. In the case of a logged out user, the easiest thing tends to be to add PostHog info to request headers and read those in the backend.
You can see for example we do this here for PostHog session ids. https://github.com/PostHog/posthog/blob/968ddb2a22109e82742a4954feb9a051...
I was wondering whether there is a way to programmatically sync the posthog distinct ID, in the front- (JS-SDK) and backend (PHP-SDK) for logged-out users (which optimally supports caching).
Nothing automatic, but as above at least one way to do it - but the best way varies by framework and application
Furthermore, I was wondering why the "distinctId" is optional for frontend "capture" method calls (uses auto generated UID as a fallback) but not for PHP-SDK "capture" method calls.
The front end is a controlled environment with a concrete lifecycle and storage the SDK can be (almost) guaranteed to have access to. That's not true on the backend. So, these front/back end overlaps tend to need manual sync
Thanks
P
- 🇩🇪Germany Anybody Porta Westfalica
Okay let's leave this open for further discussions and possible implementations in the future. Thank you @Grevil!
- 🇩🇪Germany Anybody Porta Westfalica
Further information: https://posthog.com/docs/data/sessions#passing-session-ids-from-client-s...