Angular experiments installation
Install the PostHog JavaScript library using your package manager: In your For Angular v17 and above, you can set up PostHog as a singleton service.
To do this, start by creating and injecting a Create a service by running The service is initialized outside of the Angular zone
to reduce change detection cycles. This is important to avoid performance issues with
session recording.
Then, inject the service in your app's root component In your 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: 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. Now that you're running experiments, continue with the resources below to learn what else Experiments enables within the PostHog platform.Install the package
RequiredInitialize PostHog
Requiredsrc/main.ts, initialize PostHog using your project API key and instance address:PosthogService instance.ng g service services/posthog. The
service should look like this:app.component.ts.
This will make sure PostHog is initialized before any other component is rendered.src/main.ts, initialize PostHog using your project API
key and instance address. You can find both in your
project settings.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