Dev guideAPI Reference
Dev guideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Implement Real-Time Segments for Feature Experimentation for client-side SDKs

How to implement Real-Time Segments for Feature Experimentation with client-side SDKs.

After creating an audience with Real-Time Segments for Feature Experimentation and assigning it to a flag rule, you can integrate the audience segments in your client-side code.

If you are not familiar with targeted deliveries and experiments in Optimizely Feature Experimentation, it is recommended you follow the Quickstart guide for your specific SDK first before following this document.

Install and initialize the client-side SDK

🚧

Important

You may need to upgrade your Optimizely Feature Experimentation SDK to the latest version to use Real-Time Segments for Feature Experimentation. Refer to the SDK compatibility matrix to view the latest release available for your SDK.

The first step is to install and initialize the Optimizely Feature Experimentation SDK in your application. Refer to the following documentation for your SDK:

Android –

Flutter –

JavaScript (Browser) –

React –

React Native –

Swift –

Audience targeting using OptimizelyUserContext

To fetch the audience segments your user qualifies for, you can use OptimizelyUserContext.

🚧

Important

With Real-Time Segments for Feature Experimentation, createUserContext is an async operation due to the client_initialized event.

When an OptimizelyUserContext is created, the SDK automatically sends an identify request to Optimizely Data Platform (ODP) through a network request.

  • If a known userID is also passed, the VUID is stitched to the profile of the userID.
  • If there is no userID, The SDK still registers the VUID with ODP through a network request, which means it needs to be handled async.
    • For example, for the JavaScript SDK, it needs to be handled through promise chaning or async/await.

Sending the identify event starts the customer profile merging process in ODP. Stitching VUIDs and userIDs lets any Feature Experimentation SDK (client or server-side) query ODP to get the complete customer profile.

Known users

If you have a userID, you can create an OptimizelyUserContext object as usual with your Feature Experimentation userID and additional attributes. The OptimizelyUserContext object lets you make flag decisions and track events for a user context.

To evaluate if your user would qualify in your audience, you can call fetchQualifiedSegments on the OptimizelyUserContext to fetch the ODP segments for the specific userID.

Refer to your specific SDK's documentation on creating a user context for details and code samples:

For information on the Real-Time Segments for Feature Experimentation methods, fetchQualifedSegments and isQualifiedFor refer to the following documentation:

πŸ“˜

Note

If you do not provide a userID, client-side SDKs create an OptimizelyUserContext using an automatically generated VUID.

Anonymous users

If you do not have a userID, you can still see if the anonymous user qualifies for an audience segment using OptimizelyUserContext.

Client-side SDKs automatically generate a VUID or device ID if one cannot be found upon instantiation. Also, the SDK sends a register event automatically to ODP with the VUID when the SDK is instantiated. This is helpful when sending decision data before the user is logged in, such as in anonymous segmentation.

To evaluate if your anonymous user would qualify for your audience, you can callOptimizelyUserContext with no userID to fetch the user's ODP segments. Refer to your specific SDK's documentation on creating user context for details and code samples:

πŸ“˜

Note

You can only call fetchQualifiedSegments after the datafile was fetched.

After the datafile is fetched, you can call fetchQualifiedSegments at any time to request fresh ODP segment qualifications

Make experiment decisions

You can use the standard Decide methods enriched with Real-Time Segments for Feature Experimentation to return flag decisions for a user using a userID or VUID. The flag decision includes the status if the flag is enabled or disabled and the flag variation. When an ODP-type audience condition is required for the decision, the SDK can look up the ODP segments saved in the current user context. Refer to your specific SDK's documentation on calling these methods:

Android –

Flutter -

JavaScript (Browser) –

React –

React Native –

Swift –

Send events to Optimizely Data Platform

You can call sendOdpEvent() on the OptimizelyClient for sending arbitrary event data to ODP. For example, stitching an email address identifier to the Optimizely Feature Experimentation userID identifier. Refer to your SDK to learn more:

Customize configuration

You can customize the ODPManager or override the entire ODPManager with a custom one. But each Optimizely SDK implements its own way of supporting it. Refer to your desired SDK to learn more: