@leancodepl/openfeature-posthog-provider
v10.2.1
Published
OpenFeature provider that delegates feature flag evaluation to PostHog
Readme
openfeature-posthog-provider
OpenFeature provider that delegates feature flag evaluation to PostHog. Use PostHog feature flags through the OpenFeature standard API.
Installation
npm install @leancodepl/openfeature-posthog-providerAPI
OpenFeaturePosthogProvider(client)
Delegates feature flag evaluation to PostHog (posthog-js). Use this to access PostHog feature flags through the OpenFeature standard API. Flags return default values until PostHog has loaded and feature flags are available.
Parameters:
client-PostHog- Initialized PostHog client instance
Usage Examples
Basic setup with OpenFeature
import posthog from 'posthog-js';
import { OpenFeature } from '@openfeature/web-sdk';
import { OpenFeaturePosthogProvider } from '@leancodepl/openfeature-posthog-provider';
posthog.init('YOUR_API_KEY');
OpenFeature.setProvider(new OpenFeaturePosthogProvider(posthog));
const client = OpenFeature.getClient();
const isEnabled = await client.getBooleanValue('my-feature', false);Evaluating different flag types
import { OpenFeature } from '@openfeature/web-sdk';
const client = OpenFeature.getClient();
const stringValue = await client.getStringValue('welcome-message', 'Hello');
const numberValue = await client.getNumberValue('max-items', 10);
const jsonValue = await client.getObjectValue('config', { theme: 'light' });