Boolean and multivariate flags are helpful for dynamic values that differ from user to user, but sometimes you need a simple way to pass configuration related to your application without having to make code changes or redeploy your app.
Remote config flags enable you to configure a simple flag that always returns the same payload wherever it is called. Remote config flags can also be stored as encrypted values and decrypted on the server side when requested. Encryption/decryption is handled automatically.
There are 3 steps to start using remote config flags:
Step 1: Find your feature flags secure API key
The feature flags secure API key is a secret project specific token listed in the Feature Flags tab of your project settings in the "Feature Flags Secure API Key" section. It provides the SDKs with access to the feature flag definitions for your project so they can evaluate flags locally.
This key needs to be kept secret, and should not be used in the frontend or exposed to users.
Note: Existing personal API keys will continue to work for local evaluation, but we recommend switching to the feature flags secure API key for local evaluation moving forward. We will be deprecating personal API keys for local evaluation in the future.
How to obtain a feature flags secure API key
The key should be displayed in the "Feature Flags Secure API Key" section.
Copy the key and use it to initialize the PostHog client.
Step 2: Initialize PostHog with your feature flags secure API key
const client = new PostHog('<ph_project_api_key>',{host: 'https://us.i.posthog.com',personalApiKey: 'your feature flags secure API key from step 1',featureFlagsPollingInterval: 30000 // Optional. Measured in milliseconds. Defaults to 30000 (30 seconds)})
Note: When you initialize PostHog with your feature flags secure API key to enable remote config, PostHog also enables local evaluation.
Step 3: Use remote config flags
const config = posthog.getRemoteConfigPayload('landing-page-config')// config is a JsonType
You can think of remote config flags as multivariate flags with a single variant which is served for all flag requests. By default, enabled remote config flags roll out to 100% of all users.
Note: Remote config flags are meant to always serve payloads and be called with the flag payload function in each SDK. If
getFeatureFlag
is called instead, the SDK simply returnstrue