-
Notifications
You must be signed in to change notification settings - Fork 0
visitor context
A Context ties all SDK actions to a specific visitor. A unique visitor ID is required for deterministic bucketing -- as long as the ID stays the same, bucketing is consistent. On new experiments, ramping total traffic up or down keeps everyone in place too (see Bucketing Algorithm); a persistent DataStore preserves assignments across the config changes that do move visitors, such as re-weighting variations.
# visitor_attributes are copied defensively — later caller mutations don't leak in:
context = core.create_context(
"user-unique-id",
visitor_attributes={"country": "US", "language": "en"},
)The first argument is the visitor's unique ID. The second is an optional object of initial visitor properties used for audience and segment evaluation.
Every context method that runs experiences or features accepts an optional attributes object. This table lists all supported properties:
| Property | Type | Description |
|---|---|---|
locationProperties |
object / array | Key-value pairs used for evaluating experience locations |
visitorProperties |
object / array | Key-value pairs used for evaluating experience audiences (overwrites same keys from context creation) |
updateVisitorProperties |
boolean | Whether to permanently update in-memory visitor properties |
enableTracking |
boolean | Whether to track bucketing events immediately (default: true) |
environment |
string | Override environment for this call |
typeCasting |
boolean | Auto-convert feature variable values to the variable's defined type (default: true) |
experienceKeys |
string[] | Limit feature evaluation to specific experiences only |
# Per-call overlays are keyword-only and ephemeral. Visitor audiences via
# attributes=, location rules via location_attributes=. enable_tracking (default
# True) is also keyword-only — set it False to bucket without reporting the
# bucketing event. There is no inline updateVisitorProperties or typeCasting flag —
# use set_attributes() to persist visitor properties:
variation = context.run_experience(
"experience-key",
attributes={"plan": "pro"},
location_attributes={"url": "/pricing"},
enable_tracking=True,
)Visitor properties are key-value pairs used in audience evaluation and segment matching. They can be set at context creation, updated later, or passed inline with any experience/feature call.
Permanently merges new properties into the visitor's existing properties.
Visitor properties can also be updated inline when calling any experience or feature method by setting updateVisitorProperties to true in the attributes:
The Ruby SDK has no inline
updateVisitorPropertiesflag — pass per-call visitor properties for matching only, and callupdate_visitor_properties(above) when you want them persisted.
The iOS SDK has no mutable visitor-property API — attributes are fixed when the context is created (immutable for its lifetime). To change them, create a new context with the new
attributes.
Custom segments represent audiences of type segmentation. Use runCustomSegments to evaluate segment rules against the current visitor context.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| segmentKeys | string[] | Yes | List of segment keys to evaluate |
| attributes | object / array | No | Key-value pairs used for segment matching (PHP wraps these under a ruleData key) |
In Fullstack projects, segments do not persist unless you provide a DataStore. See the segments concept for more detail on how segmentation works.
Default segments are used for Convert reporting. Use setDefaultSegments to permanently update the visitor's default segments. Only the following properties are included in Convert Reports:
browserdevicessourcecampaignvisitorTypecountry
# The method is set_segments(); each call shallow-merges into the stored default
# segments, kept strictly separate from visitor attributes:
context.set_segments({
"country": "US",
"browser": "chrome",
"devices": "desktop",
})Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| segments | object / array | Yes | Key-value pairs merged with the initial visitor properties |
You can look up any entity in the project configuration by its key or numeric ID.
# entity_type comes FIRST (opposite of the JS/PHP/Ruby order) and is a plain
# string — one of "experiences", "features", "goals", "audiences", "segments".
# Returns the entity mapping, or None on a normal miss (never raises):
experience = context.get_config_entity("experiences", "experience-key")Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| key | string | Yes | Entity key |
| entityType | EntityType / string | Yes | One of: AUDIENCE, LOCATION, SEGMENT, FEATURE, GOAL, EXPERIENCE, VARIATION
|
# get_config_entity_by_id also takes entity_type first, then the id. Returns the
# entity mapping, or None on a normal miss (never raises):
feature = context.get_config_entity_by_id("features", "feature-id")Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | number / string | Yes | Entity numeric ID (PHP passes it as a string) |
| entityType | EntityType / string | Yes | Same values as getConfigEntity above |
Both methods return the matching entity object (or array in PHP), or null if not found.
The Ruby SDK resolves config entities by key only (
get_config_entity(key, entity_type)withentity_typeone of:experience,:feature,:goal); it has no by-ID variant.
Copyrights © 2025 All Rights Reserved by Convert Insights, Inc.
Getting Started
Python SDK
- Quickstart
- Installation
- Initialization
- Configuration
- Code Examples
- Type Hints
- Diagnostics
- Extending
- Testing
- Async & Frameworks
Migration
Core Concepts
- Experiences & Variations
- Feature Flags
- Bucketing Algorithm
- Rule Evaluation
- Segments
- Data Management
- Event System
- API Communication
How-To Guides
- Running Experiences
- Running Features
- Tracking Conversions
- Visitor Context
- Persistent DataStore
- Troubleshooting
- Direct Tracking Endpoint
- Server-Side Experimentation
- From Tracking Script to SDK
- QA & Preview
- Mutually Exclusive Experiments
Edge & Integrations
Maintainers