Dev guideAPI Reference
Dev guideAPI ReferenceUser GuideGitHubNuGetDev CommunityDoc feedbackLog In

Optimizely Data Platform audience segment qualification methods

Use the Optimizely Data Platform (ODP) Advanced Audience Targeting segment methods to fetch external audience mapping for the user. You can fetch user segments with the user identifier of the user context.

📘

Note

Advanced Audience Targeting segment qualification methods are in beta. Contact your Customer Success Manager for more information or register now on Optimizely.com.

fetchQualifiedSegments

Minimum SDK Version

4.0.0-beta2

Description

You can use the fetchQualifiedSegments method to retrieve the external audience mapping for a specific user from the ODP server. The Optimizely Feature Experimentation Android SDK provides a synchronous and asynchronous version of the Optimizely Data Platform (ODP) fetchQualifiedSegments method.

  • The caller will be blocked until the synchronous fetch has been completed.
  • The caller of asynchronous API will not be blocked.

fetchQualfiedSegments is a method of the UserContext object. See OptimizelyUserContext for details.

Parameters

The following table describes the parameters for the fetchQualifiedSegments method:

ParameterTypeDescription
options (optional)StringA set of options for fetching qualified segments from ODP.
completion (for asynchronous calls)Callback functionA completion handler to be called with the fetch result.

Returns - Synchronous call

The fetchQualifiedSegments synchronous method returns true if the qualified segments array in the user context was updated.

Returns - Asynchronous call

  • If the fetch completes successfully, the Python SDK will update the qualified segments array in the user context and then call the completion handler with a success status.
  • If the fetch fails, the SDK will call the handler with a failure status.

📘

Qualified segments array

You can read and write directly to the qualified segments array. This allows for bypassing the remote fetching process from ODP or for utilizing your own fetching service. This can be helpful when testing or debugging.

Example fetchQualifiedSegments

The following is an example of calling the fetchQualifiedSegments method and accessing the returned completion object:

Map<String, Object> attributes = new HashMap<>();
attributes.put("app_version", 1.3.2");
OptimizelyUserContext user = optimizelyClient.createUserContext("user123", attributes);

// Without segment option 
Boolean response = user.fetchQualifiedSegments((Boolean isFetchSuccessful) -> {
            System.out.println(isFetchSuccessful);
            
            OptimizelyDecision decision = user.decide("flag1");
            user.trackEvent("purchase_event");
        });

// With segment options
List<ODPSegmentOption> odpSegmentOptions = new ArrayList<>();
odpSegmentOptions.add(ODPSegmentOption.IGNORE_CACHE);
odpSegmentOptions.add(ODPSegmentOption.RESET_CACHE);

user.fetchQualifiedSegments((Boolean isFetchSuccessful) -> {
            System.out.println(isFetchSuccessful);
            
            OptimizelyDecision decision = user.decide("flag1");
            user.trackEvent("purchase_event");
        },
        odpSegmentOptions);
Map<String, Object> attributes = new HashMap<>();
attributes.put("app_version", "1.3.2");

// Method 1 create with user id
OptimizelyUserContext userWithUserId = optimizelyClient.createUserContext("user123", attributes);

// Without segment option 
Boolean response = userWithUserId.fetchQualifiedSegments();

// With segment options
List<ODPSegmentOption> odpSegmentOptions = new ArrayList<>();
odpSegmentOptions.add(ODPSegmentOption.IGNORE_CACHE);
odpSegmentOptions.add(ODPSegmentOption.RESET_CACHE);

Boolean response = userWithUserId.fetchQualifiedSegments(odpSegmentOptions);


OptimizelyDecision decision = userWithUserId.decide("flag1");
userWithUserId.trackEvent("myevent");


// Method 2 create OptimizelyUserContext with auto-generated VUID instead of user id
OptimizelyUserContext userWithVuid = optimizelyClient.createUserContext(attributes);

// Without segment option 
Boolean response = userWithVuid.fetchQualifiedSegments();


// With segment options
List<ODPSegmentOption> odpSegmentOptions = new ArrayList<>();
odpSegmentOptions.add(ODPSegmentOption.IGNORE_CACHE);
odpSegmentOptions.add(ODPSegmentOption.RESET_CACHE);

Boolean response = userWithVuid.fetchQualifiedSegments(odpSegmentOptions);


OptimizelyDecision decision = userWithVuid.decide("flag1");
userWithVuid.trackEvent("myevent");

Once the segments have been fetched, they are cached. This means that if the same user is requesting the segments again (when new user contexts are created), the audience segment information can be retrieved from the cache instead of being fetched again from the remote ODP server.

If you would like to bypass caching, you can add the following options to your odpSegmentOptions array:

  • ignoreCache – bypass segments cache for lookup and save
  • resetCache – reset all segments cache

isQualifiedFor

Minimum SDK Version

4.0.0-beta2

Description

Check if the user is qualified for the given audience segment.

Parameters

The following table describes the parameters for the isQualifiedFor method:

ParameterTypeDescription
segmentStringThe ODP audience segment name to check if the user is qualified for.

Returns

true if the user is qualified.

Examples

The following is an example of whether or not the user is qualified for an ODP segment:

Map<String, Object> attributes = new HashMap<>();
attributes.put("mobile_os", "ios");
OptimizelyUserContext user = optimizely.createUserContext("user123", attributes);

Boolean response = user.fetchQualifiedSegments();
Boolean isQualified = user.isQualifiedFor("segment1");

Source files

The language/platform source files containing the implementation for Android is TODO.