mirror of
https://github.com/BillyOutlast/posthog.com.git
synced 2026-02-08 21:31:21 +01:00
Co-authored-by: Edwin Lim <edwin@posthog.com> Co-authored-by: Vincent (Wen Yu) Ge <29069505+gewenyu99@users.noreply.github.com> Co-authored-by: Vincent (Wen Yu) Ge <gewenyu99@gmail.com> Co-authored-by: edwinyjlim <edwinyjlim@gmail.com>
103 lines
2.8 KiB
Plaintext
103 lines
2.8 KiB
Plaintext
---
|
|
title: Node.js experiments installation
|
|
showStepsToc: true
|
|
---
|
|
|
|
import { Steps, Step } from 'components/Docs/Steps'
|
|
import NodeInstall from '../../integrate/_snippets/install-node.mdx'
|
|
import StepCreateExperiment from './_snippets/step-create-experiment.mdx'
|
|
import StepAddPrimaryMetric from './_snippets/step-add-primary-metric.mdx'
|
|
import StepValidateExperimentEvents from './_snippets/step-validate-experiment-events.mdx'
|
|
import StepValidateFeatureFlags from './_snippets/step-validate-feature-flags.mdx'
|
|
import StepEvaluateExperimentResults from './_snippets/step-evaluate-experiment-results.mdx'
|
|
import Wizard from '../../getting-started/_snippets/wizard.mdx'
|
|
import Tab from "components/Tab"
|
|
|
|
<Steps>
|
|
|
|
<Step title="Install PostHog Node.js SDK" badge="required">
|
|
|
|
<Tab.Group tabs={['Wizard', 'Manual']}>
|
|
<Tab.List>
|
|
<Tab>Wizard</Tab>
|
|
<Tab>Manual</Tab>
|
|
</Tab.List>
|
|
<Tab.Panels>
|
|
<Tab.Panel>
|
|
<Wizard />
|
|
</Tab.Panel>
|
|
<Tab.Panel>
|
|
<NodeInstall />
|
|
</Tab.Panel>
|
|
</Tab.Panels>
|
|
</Tab.Group>
|
|
|
|
</Step>
|
|
|
|
<Step title="Capture conversion event" badge="required">
|
|
|
|
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.
|
|
|
|
```js
|
|
client.capture({
|
|
distinctId: 'distinct_id_of_the_user',
|
|
event: 'cta clicked',
|
|
})
|
|
```
|
|
|
|
</Step>
|
|
|
|
<Step checkpoint title="Validate PostHog events" subtitle="Confirm events are being sent to PostHog">
|
|
|
|
<StepValidateExperimentEvents />
|
|
|
|
</Step>
|
|
|
|
<Step title="Create an experiment" badge="required">
|
|
|
|
<StepCreateExperiment />
|
|
|
|
</Step>
|
|
|
|
<Step title="Add primary metric and launch" badge="required">
|
|
|
|
<StepAddPrimaryMetric />
|
|
|
|
</Step>
|
|
|
|
<Step title="Call feature flag" badge="required">
|
|
|
|
Use the PostHog SDK to call the experiment flag and update how your page renders based on the assigned variant.
|
|
|
|
```js
|
|
const 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](/docs/experiments/creating-an-experiment#distribution-and-release-conditions).
|
|
|
|
</Step>
|
|
|
|
<Step checkpoint title="Validate feature flag calls">
|
|
|
|
<StepValidateFeatureFlags />
|
|
|
|
</Step>
|
|
|
|
<Step title="Evaluate experiment results" badge="recommended">
|
|
|
|
<StepEvaluateExperimentResults />
|
|
|
|
</Step>
|
|
|
|
</Steps>
|