- 1
Install PostHog Node.js SDK
RequiredInstall PostHog in seconds with our wizard by running this command in your project directory with your terminal (it also works for LLM coding agents like Cursor and Bolt):
promptnpx -y @posthog/wizard@latest --region usWait for it to finish and test the setup once the wizard is complete.
The wizard supports React, Next.js, Svelte, and React Native. We've got more on the way.
Check out the wizard's GitHub repo for more details.
Set up a reverse proxy (recommended)
We recommend setting up a reverse proxy, so that events are less likely to be intercepted by tracking blockers.
We have our own managed reverse proxy service included in the platform add-ons, which routes through our infrastructure and makes setting up your proxy easy.
If you don't want to use our managed service then there are several other options for creating a reverse proxy, including using Cloudflare, AWS Cloudfront, and Vercel.
Grouping products in one project (recommended)
If you have multiple customer-facing products (e.g. a marketing website + mobile app + web app), it's best to install PostHog on them all and group them in one project.
This makes it possible to track users across their entire journey (e.g. from visiting your marketing website to signing up for your product), or how they use your product across multiple platforms.
- 2
Capture conversion event
RequiredOnce PostHog is initialized, you should be able to capture events. For your experiment to be meaningful, we need to capture an event that we want to measure, such as a conversion event.
For this tutorial, let's report a conversion event when a clicks a CTA. In server SDKs like Node, this can be called when a specific route is visited or reported from your client side app.
JavaScriptclient.capture({distinctId: 'distinct_id_of_the_user',event: 'cta clicked',}) - 3
Create an experiment
RequiredGo to the Experiments tab in the PostHog app and click on the New experiment button in the top right.
For this tutorial, let's create a new experiment using simplified test values:
- Name: "Test experiment"
- Description: "This is a test experiment"
- Feature flag key: "test-experiment-ff-key"
- Experiment type: "Feature flag"
- Variants: "control" and "test"
- Participant type: "Users"
Then click Save as draft.
- 4
Add primary metric and launch
RequiredScroll down to the Primary metrics section and click + Add primary metric.
Choose Single-use and select Type > Mean.
Then search for the event
cta clicked
under Metric and click Save.By default, experiments are exposed to 100% of users. You can customize release conditions to expose the experiment to a subset of users.
For this tutorial, we'll ship the experiment to all users and click Launch in the top right.
- 5
Call feature flag
RequiredUse the PostHog SDK to call the experiment flag and update how your page renders based on the assigned variant.
JavaScriptconst variant = await client.getFeatureFlag('your-experiment-key', 'user_distinct_id')if (variant === 'control') {// Show control variant UI} else {// Show test variant UI}Now when a user triggers a
cta clicked
event, PostHog automatically assigns the user to a variant and records an experiment exposure.By default, users are split equally between variants. If you want to assign specific users to a specific variant, see more about distribution and release conditions.
- 6
Evaluate experiment results
RecommendedAs you capture more
cta clicked
events, more exposures will populate the primary metrics in your experiment.With enough data, you can analyze the experiment and its variants by:
- Conversion rates
- Statistical significance
- Credible intervals
- Chance to win %
- Minimum detectable effect
- And more
Node.js experiments installation
Last updated:
|Questions? Ask Max AI.
It's easier than reading through 794 pages of documentation
Community questions
Was this page useful?
Next article
Python experiments installation
Once PostHog is initialized, you should be able to capture events. For your experiment to be meaningful, we need to capture an event that we want to measure, such as a conversion event. For this tutorial, let's report a conversion event when a clicks a CTA. In server SDKs like Node, this can be called when a specific route is visited or reported from your client side app. Use the PostHog SDK to call the experiment flag and update how your page renders based on the assigned variant. Now when a…