Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose distinct UUID generation and parser/constructor for cookie payload #126

Open
1 of 4 tasks
joernroeder opened this issue Nov 3, 2023 · 1 comment
Open
1 of 4 tasks
Labels
enhancement New feature or request help wanted Extra attention is needed nodejs

Comments

@joernroeder
Copy link

joernroeder commented Nov 3, 2023

Is your feature request related to a problem?

I'd love to hand out one URL domain.com/download-app to send users to the android and apple stores by having a dynamic redirect depending on the user agent visiting that page in place — of course I'd love to track this event in PostHog.

Initiating the client inside a lambda function is straight forward, there are two things I'm doing manually right now:

  • reading the cookie headers, checking for an existing PH cookie and grabbing the distinct_id from there.
  • generate a new v4 uuid() if there is no PH header present (the phone did not visit our main landing page before) and write it into a cookie via Set-Cookie header which the client side PostHog then picks up and continues to use when the phone visits our domain.com.

All that works great!

I noticed that ph uses this generateUUID function but does not export it on the posthog-node package. The anonymous uuids seem to share a common prefix 081b in my case, which differs from what the v4 uuids are looking which I am generating (via uuid).

Also parsing and constructing the cookie myself feels error prone, exposing those three building blocks from the lib would make this future proof.

Describe the solution you'd like

  • export the generateUUID function to reuse it
  • export a method to construct the cookie payload
  • export a method to parse a PH cookie payload

Related sub-libraries

  • All of them
  • posthog-web
  • posthog-node
  • posthog-react-native

Additional context

Thank you for your feature request – we love each and every one!

@joernroeder joernroeder added the enhancement New feature or request label Nov 3, 2023
@marandaneto marandaneto added nodejs help wanted Extra attention is needed labels Feb 29, 2024
@marandaneto
Copy link
Member

@joernroeder we use the uuidv7() method now.
would you like to contribute with a PR exposing the construct and parse of cookies?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed nodejs
Projects
None yet
Development

No branches or pull requests

2 participants