Closed aplr closed 1 year ago
Hey @aplr , have you looked at posthog-node
, it might be what you want here - it is stateless, in the sense that you can use the same client for multiple requests without having to reinitialise things.
And, it's built on top of posthog-core while taking care of all internals necessary.
Feel free to re-open if there's things it doesn't do that you need.
Hey @neilkakkar, yea I had a look, but it's not 100% what I'm looking for and how I imagined it. I'll check and see if it works out, also in edge environments, and with the custom code I have to build around it. Would be really cool to just have PostHog initialize from an incoming request w/ parsing cookies and headers and just call function without having to specify distinct / anonymous id etc, that's what I've imagined :)
Is your feature request related to a problem?
We're currently implementing PostHog into our Next.js app-dir-based application. We want to send events from several locations in the code, including middleware, RSC, route handlers and browser. For RSC and route handlers, we want a way to conveniently initialize a PostHog client for each request from the cookies sent by the browser to take over the cookies.
Describe the solution you'd like
We'd like to directly use
PostHogCore
fromposthog-core
to implement this wrapper, including initialization from headers, and memory persistant storage.Describe alternatives you've considered
Currently, we're subclassing the exported
PostHog
fromposthog-js-lite
. Works, but does not feel right.