Skip to content

Conversation

@elisescu
Copy link
Contributor

@elisescu elisescu commented Dec 19, 2025

Adds support for using PH on the server side, following https://posthog.com/tutorials/nextjs-analytics

Comment on lines +37 to +40
const distinctId = cookieValue
? JSON.parse(cookieValue).distinct_id
: "anonymous";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this can crash a function in JSON.parse if the cookie value is malformed and it won't be caught then

const cookieValue = cookieStore.get(cookieName)?.value;
const distinctId = cookieValue
? JSON.parse(cookieValue).distinct_id
: "anonymous";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that anonymous is not the best fallback here, as then If there’s no cookie, every user becomes "anonymous" and will all share the same flag evaluation. Maybe it's better to go with a user's id or sth similar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants