Nuxt experiments installation
- 1
Install the package
RequiredInstall the PostHog JavaScript library using your package manager:
Nuxt versionThis guide is for Nuxt v3.0 and above. For Nuxt v2.16 and below, see our Nuxt docs.
- 2
Add environment variables
RequiredAdd your PostHog API key and host to your
nuxt.config.jsfile:nuxt.config.js - 3
Create a plugin
RequiredCreate a new plugin by creating a new file
posthog.client.jsin your plugins directory:plugins/posthog.client.js - 4
Server-side setup
OptionalTo capture events from server routes, install
posthog-nodeand instantiate it directly. You can also use it to evaluate feature flags on the server:server/api/example.js - 5
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.
For client-side experiments, use the JavaScript snippet. For server-side experiments, use the Node.js snippet:
- 6
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.
- 7
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