Contexts
Read time: 3 minutes
Last edited: Oct 02, 2024
Overview
This category has documentation topics about LaunchDarkly contexts.
Most, but not all, LaunchDarkly SDKs support contexts. Instead, some rely on legacy user objects. To learn which SDKs are available to use with contexts, read SDKs.
About contexts
LaunchDarkly contexts are data objects representing users, devices, organizations, and other entities that feature flags serve different variations to according to your flag targeting rules. These data objects contain context attributes that describe what you know about that context, such as their name, location, device type, or organization they are associated with.
You can manage how contexts interact with your app by targeting flag variations to specific contexts, based on their context attributes. When a flag evaluation occurs, the feature flag uses the evaluation context to understand what variation to serve. You can be as specific as targeting a flag to a single end user, or as broad as targeting your entire customer base. You can even use anonymous contexts and private attributes to control what data to include or exclude in the information you collect about your end users.
The SDK only evaluates flags based on the context you provide in the evaluation call. You must provide all applicable attributes for each evaluation in the SDK for your targeting rules to apply correctly. To learn more, read Evaluating flags.
Example context: Anna at Global Health Services
As an example, let's assume Anna is one of your end users. She is a doctor who works for a hospital chain called Global Health Services. Anna has two mobile devices, an Android phone and an iPad tablet. Anna uses your application on both devices as part of her work.
Given this information, you may know the following things about Anna:
- her name, email, and job function ("doctor"),
- her organization's name ("Global Health Services"),
- her device's type ("iPad")
Here is an example of what the data structure for Anna's context object might look like, though each SDK sends context data to LaunchDarkly in a slightly different format:
"context": {"kind": "user","key": "user-key-123abc","name": "Anna","email": "anna@globalhealthexample.com","organization": "Global Health Services","jobFunction": "doctor","device": "iPad"}
Context kinds
Each context has one kind
with a unique set of corresponding attributes that you can use for flag targeting and other features.
The most common context kind is user
. User contexts often include context attributes like name, email address, location, and so on. However, you can create other context kinds like organization
or device
. An organization
context kind might include attributes like "name" or "address," and a device
context kind might include attributes like "type" or "operating system."
To learn more, read Context kinds.
Related content
Here are the topics in this category: