Web experiments installation
- 1
Choose an installation method
RequiredYou can either add the JavaScript snippet directly to your HTML or install the JavaScript SDK via your package manager.
Add this snippet to your website within the
<head>tag. This can also be used in services like Google Tag Manager:HTMLInstall the PostHog JavaScript library using your package manager. Then, import and initialize the PostHog library with your project token and host:
JavaScript - 2
Implement your experiment
RequiredExperiments run on top of our feature flags. You can define which version of your code runs based on the return value of the feature flag:
- 3
Run your experiment
RequiredOnce you've implemented the feature flag in your code, you'll enable it for a target audience by creating a new experiment in the PostHog dashboard.
- 4
Next steps
RecommendedNow that you're running experiments, continue with the resources below to learn what else Experiments enables within the PostHog platform.
Resource Description Creating an experiment How to create an experiment in PostHog Adding experiment code How to implement experiments for all platforms Statistical significance Understanding when results are meaningful Experiment insights How to analyze your experiment data More tutorials Other real-world examples and use cases