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

@elisescu
Copy link
Contributor Author

elisescu commented Jan 2, 2026

Closing this for now. After further digging, it looks like in order to bootstrap PH init on the server side and correctly identify the user, we would need to migrate all the existing users to a new setup where IDs are created on the server side.

@elisescu elisescu closed this Jan 2, 2026
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