posthog.com icon indicating copy to clipboard operation
posthog.com copied to clipboard

Docs - Tracking anonymous users across frontend and backend

Open timgl opened this issue 3 years ago • 1 comments

Strapline

If you have the concept of a logged in user, collating events between frontend and backend is trivial, just use posthog.identify(unique_id). But if you don't have that concept, it's much harder. See this thread for an example of how one user hackily solved this.

Figuring this out was one of my biggest frustrations using a competitive product a couple of years ago.

Why should we do it?

It'd be good for us to give an 'official' way of doing this. There are two main options:

  1. Use posthog-js as normal in the frontend, then grab the cookie in the backend as per this thread. Downside is the server would only have access to the distinct id after the first page load. Simplest, and could make this even simpler by integrating it in the client libs?
  2. Create a random unique ID in the backend, send that to the frontend. Most reliable but fiddly.

Outline

Bullet point outline of structure / questions / topics to be covered

timgl avatar Aug 17 '22 20:08 timgl

@timgl That link is now dead. Is there documentation anywhere as to how to grab the cookie from the backend so you can identify "people" that have already been created on the front-end?

em77 avatar Oct 10 '24 15:10 em77

Still a missing piece in the docs.

sreuter avatar Apr 27 '25 23:04 sreuter