getAudiences

The getAudiences() method returns the IDs of the Data Activation audiences the user belongs to.

Syntax

tracker.getAudiences(
    { audienceIds ->
        // handle result
    },
    { errorMessage ->
        // handle error
    }
)
getTracker().getAudiences(
        audienceIds -> {
            // handle result
        },
        errorMessage -> {
            // handle error
        });

Parameters

onResult (required)

A callback with the list of audience IDs. The list is empty if the user doesn't belong to any audience.

onError (required)

A callback that receives an error message. For example, HTTP 404: ... if the user profile doesn't exist yet.

Examples

To get the audiences of the user:

tracker.getAudiences(
    { audienceIds ->
        // Do something with the audience IDs
    },
    { errorMessage ->
        // Handle error
    }
)
getTracker().getAudiences(
        audienceIds -> {
            // Do something with the audience IDs
        },
        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 onResult or onError is called asynchronously on the main thread.
  • If setOptOut(true) is set, the SDK doesn't send the request and calls onError.

Related methods


Did this page help you?