Problem/Motivation
Currently, if a user logs in, we identify them server-side if the setting is enabled in posthog_php. We do the same for posthog_js, but we also only if the user is not anonymous.
We need to think of a way on how we would identify anonymous users in sync with the front and backend.
Currently for logged-in users, the admin can decide on the settings page, what user data should be used for the distinct id for user identification (e.g. uid, mail, etc.). This is not possible with anonymous users.
It's not even that important to identify these users, since we could also use the anonymous id generated by posthog, but we want to have the same anonymous id for front and backend events. Maybe we could use that id for logged out users, but caching could be a problem.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork posthog-3500561
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
grevil commentedComment #3
anybodyYes we need to think about how to solve this and see if anyone already solved this for posthog in PHP or other languages!
Comment #4
anybody@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.
Comment #5
anybodyComment #6
grevil commentedBesides 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:
Let's wait for their feedback!
Comment #7
grevil commentedThis 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...
Nothing automatic, but as above at least one way to do it - but the best way varies by framework and application
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
Comment #8
anybodyOkay let's leave this open for further discussions and possible implementations in the future. Thank you @Grevil!
Comment #9
anybodyFurther information: https://posthog.com/docs/data/sessions#passing-session-ids-from-client-s...
But I think it's just wrong to pass the ID from the client to the server. Server is always "first", as it builds the client... Guess we should wait for a posthog-side solution to create the ID server-side and then pass it to the client. Or we simply create one ourselves, which would mean the anonymous user needs a cookie / session...
Before proceeding here, let's discuss this. It's currently not important enough to spent a lot of time (which you can here ;))
Comment #10
grevil commentedThis now got a bit more important, because of #3554839: How to get gclid into Posthog PHP conversion?.
Comment #12
grevil commentedOk, there is still an update hook needed and the functionality needs to be tested.
Otherwise this is good to go.
Comment #13
grevil commentedAll green again! There was a little bug, but all good again :)
I'll do some final testing and then we should be good to go!
Comment #14
grevil commentedAll done! Works great!
Comment #15
grevil commentedComment #17
grevil commented