Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Context fundamentals

Contexts are composed of three core elements: a unique key, custom attributes, and optional meta attributes.

Key

A string that uniquely identifies a context. The key:

  • May represent an individual user, session, device, or any other entity you wish to target
  • Must be unique for each context instance
  • Cannot be marked as private
  • Is used for individual targeting, experimentation, and as the default value for rollouts

Attributes

Each attribute can have one or more values. You can define custom attributes with any additional information you wish to target on.

Supported attribute types

Attributes can contain one or more values of any of these supported types:

  • String
  • Boolean
  • Number
  • Semantic Version (string format)
  • Date (RFC3339 or Unix Timestamp in milliseconds)

Some operations within rule clauses such as “less than” and “greater than” only support specific types.

Nested attributes

You can target on nested objects in contexts using a JSON path notation. For example, to target on an iOS version within a nested device object, use /os/ios/version as the attribute path.

Meta attributes

Meta attributes are reserved by LaunchDarkly and may have special meaning or usage in the platform.

Key meta attributes

Key meta attributes include:

NameDescription
keyRequired. Cannot be private. Used for individual targeting, experimentation and the default value for rollouts
anonymousWhen true, the context will be hidden from the dashboard and will not appear in autocomplete
nameUsed in the contexts dashboard and autocomplete search
_meta/privateAttributesList of attribute names whose values will be redacted from events sent to LaunchDarkly

For a complete list, see Built-in and custom attributes in the LaunchDarkly documentation.

Code examples

Server SDK

In server-side SDKs, pass the context on every variation call:

ldclient.variation("release-widget", context, fallback);

Client SDK

In client-side SDKs, provide context at initialization and update via identify():

const ldclient = LaunchDarkly.initialize(clientId, context);

// Later, update the context
ldclient.identify(newContext);

Usage and billing

Usage is based on the number of unique context keys seen for your primary (most used) context, deduplicated across your entire account.

Limits are not hard lines. Overages do not impact the evaluation of feature flags in your application.

To learn more, read Usage metrics.