Feature Flags Module
The Feature Flags Module provides access to feature flags (settings) that control the behavior and appearance of the application. Feature flags allow for dynamic configuration without requiring code changes or redeployment.
Accessing the Module
The Feature Flags Module is accessible through the GamanzaEngageWebClientSDK instance:
const sdk = GamanzaEngageWebClientSDK.getInstance();
const featureFlags = sdk.FeatureFlags;
Methods
getFeatureFlagValue
Returns the value for a specific feature flag identified by its key.
getFeatureFlagValue(featureFlagKey)
Parameters
Name | Type | Description |
---|---|---|
featureFlagKey | string | The unique identifier for the feature flag |
Returns
Promise<T | null>
: A promise that resolves to the value of the feature flag with the specified type, or null if the feature flag is not found.
Example
// Get a boolean feature flag
const isFeatureEnabled = await sdk.FeatureFlags.getFeatureFlagValue('my-feature-enabled');
// Get a string feature flag
const featureConfig = await sdk.FeatureFlags.getFeatureFlagValue('feature-config');
// Get a complex object feature flag
const featureSettings = await sdk.FeatureFlags.getFeatureFlagValue('feature-settings');
// featureSettings might contain: { enabled: true, maxAttempts: 3, displayName: "Feature Name" }
getFeatureFlags (Deprecated)
Returns all feature flags available for the current instance.
getFeatureFlags()
Note: This method is deprecated. Please use
getFeatureFlagValue
instead.
Returns
Promise<Array>
: A promise that resolves to an array of all available feature flags.
Example
// Get all feature flags (deprecated)
const allFlags = await sdk.FeatureFlags.getFeatureFlags();
Interfaces
FeatureFlag
Represents a feature flag with its metadata and value.
The FeatureFlag object has the following structure:
Property | Type | Description |
---|---|---|
key | string | Unique identifier for the feature flag |
scope | string | Scope of the feature flag (e.g., "global", "user", etc.) |
description | string | Detailed description of what the feature flag controls |
displayName | string | Human-readable name for the feature flag |
hidden | boolean | Indicates whether the feature flag should be hidden from user interfaces |
static | boolean | Indicates whether the feature flag value is static (unchangeable) |
type | string | Data type of the feature flag value (e.g., "boolean", "string", "object") |
value | any | The current value of the feature flag |
default | any | The default value of the feature flag if no value is set |
Caching Behavior
The Feature Flags Module implements caching to improve performance:
- Feature flag values are cached in IndexedDB for 30 minutes
- When requesting a specific feature flag value, the module first checks the cache
- If the value is not in the cache, it will be fetched from the server and then cached
- The cache is automatically cleared when the SDK session is closed
Error Handling
If a feature flag is not found, the getFeatureFlagValue
method returns null
. Your application should handle this case appropriately, typically by falling back to a default behavior.