isUserInAudience
The isUserInAudience() method checks if a user belongs to a specific Data Activation audience.
Syntax
tracker.isUserInAudience(audienceId,
{ isMember ->
// handle result
},
{ errorMessage ->
// handle error
}
)getTracker().isUserInAudience(audienceId,
isMember -> {
// handle result
},
errorMessage -> {
// handle error
});Parameters
audienceId (string, required)
The ID of the audience you want to check. You can find it in Data Activation > Audiences.
onResult (required)
A callback that receives true if the user belongs to the audience or false if not.
onError (required)
A callback that receives an error message.
Examples
To check whether a user belongs to the audience with the ID 12345678-90ab-cdef-1234-567890abcdef, for example, to show a special offer:
tracker.isUserInAudience("12345678-90ab-cdef-1234-567890abcdef",
{ isMember ->
// handle result
},
{ errorMessage ->
// handle error
}
)getTracker().isUserInAudience("12345678-90ab-cdef-1234-567890abcdef",
isMember -> {
// handle result
},
errorMessage -> {
// handle error
});Notes
- The user profile is identified by the visitor ID. Call setAnonymizationState(false), otherwise the SDK generates a new visitor ID each time the app starts and may not find the existing profile.
- Either
onResultoronErroris called asynchronously on the main thread. - If setOptOut(true) is set, the SDK doesn't send the request and calls
onError.
Related methods
Updated 11 days ago
Did this page help you?