PostHog / posthog-js-lite

Reimplementation of posthog-js to be as light and modular as possible.
https://posthog.com/docs/libraries
MIT License
70 stars 36 forks source link

Publish posthog-core to npm #112

Closed aplr closed 1 year ago

aplr commented 1 year ago

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 from posthog-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 from posthog-js-lite. Works, but does not feel right.

neilkakkar commented 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.

aplr commented 1 year ago

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 :)