The SDK can now be used to load and evaluate Mixpanel Feature Flags (see https://docs.mixpanel.com/docs/featureflags). It supports two modes of operation, remote evaluation and local evaluation.
Remote Evaluation
const mixpanel = Mixpanel.init(`<YOUR_TOKEN>`, {
remote_flags_config: {
// optional configuration
request_timeout_in_seconds: 5,
},
});
// or to enable remote evaluation with no custom configuration:
const mixpanel = Mixpanel.init(`<YOUR_TOKEN>`, {
remote_flags_config: {},
});
// A network call is made to fetch the assigned variant for a user
const variantValue = await mixpanel.remote_flags.getVariantValue(`<YOUR_FLAG_KEY>`, `<FALLBACK_VARIANT>`, {
distinct_id : `<USER DISTINCT ID>`,
});Local Evaluation
const mixpanel = Mixpanel.init(`YOUR_PROJECT_TOKEN`, {
local_flags_config: {
enable_polling: true,
polling_interval_in_seconds: 60,
},
});
// or to enable local evaluation with no custom configuration:
const mixpanel = Mixpanel.init(`<YOUR_TOKEN>`, {
local_flags_config: {},
});
// Polls the endpoint for flag definitions
mixpanel.local_flags.startPollingForDefinitions();
// User is quickly assigned to a variant based on polled flag definitions
const variantValue = mixpanel.local_flags.getVariantValue(`<YOUR_FLAG_KEY>`, `<FALLBACK_VARIANT>`, {
distinct_id : `<USER_DISTINCT_ID`,
});Further Node.js-specific Feature Flags documentation is available at https://docs.mixpanel.com/docs/tracking-methods/sdks/nodejs/nodejs-flags.