isUserInAudience

The isUserInAudience(audienceID:) method checks if the user belongs to a given Data Activation audience.

Syntax

PiwikTracker.sharedInstance()?.isUserInAudience(audienceID: "audienceId") { isMember, error in
    if isMember {
        // Do something if the user is a member
    } else if let error = error {
        // Handle error
    }
}
[[PiwikTracker sharedInstance] isUserInAudienceWithID:@"audienceId" completionBlock:^(BOOL isMember, NSError * _Nullable error) {
    if (isMember) {
        // Do something if the user is a member
    } else if (error) {
        // Handle error
    }
}];

Parameters

  • audienceID NSString, required - The ID of the audience you want to check. You can find it in Data Activation > Audiences.

Callback parameters

  • isMember boolean, output - Whether the user belongs to a specific audience. True: Belongs. False: Doesn't belong.
  • error NSError?, output - The error object (if any).

Examples

To check if the user belongs to the audience with the ID 12345678-90ab-cdef-1234-567890abcdef, for example to display a special offer:

PiwikTracker.sharedInstance()?.isUserInAudience(audienceID: "12345678-90ab-cdef-1234-567890abcdef") { isMember, error in
    // do something if is member or handle error
}
[[PiwikTracker sharedInstance]
    isUserInAudienceWithID:@"12345678-90ab-cdef-1234-567890abcdef"
           completionBlock:^(BOOL isMember, NSError * _Nullable error) {
               // do something if is member or handle error
           }];

Notes

  • The user profile is identified by the visitor ID. Set isAnonymizationEnabled to false, so the SDK keeps the same visitor ID between app launches. Otherwise, it generates a new visitor ID each time the app starts and may not find the existing profile.
  • The completion block is called asynchronously on the main thread.
  • When optOut is true, the SDK doesn't send the request and calls the completion block with an error.

Related methods


Did this page help you?