Svelte experiments installation
Install the PostHog JavaScript library using your package manager: If you haven't created a root layout already, create a new file called Learn more about SvelteKit layouts in the official documentation. Install Then, initialize the PostHog Node client where you'd like to use it on the server side. For example, in a load function: Make sure to always call Experiments 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: Once 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.Install the package
RequiredInitialize PostHog
Required+layout.js in your src/routes folder. Check the environment is the browser, and initialize PostHog if so:Server-side setup
Optionalposthog-node using your package manager:posthog.shutdown() after capturing events from the server-side. PostHog queues events into larger batches, and this call forces all batched events to be flushed immediately.Implement your experiment
RequiredRun your experiment
RequiredNext steps
RecommendedResource 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