getAudiences

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

Syntax

PiwikTracker.sharedInstance()?.getAudiences { audienceIDs, error in
    // handle audienceIDs or error
}
[[PiwikTracker sharedInstance] getAudiencesWithCompletionBlock:^(NSArray<NSString *> * _Nullable audienceIDs, NSError * _Nullable error) {
    // handle audienceIDs or error
}];

Callback parameters

  • audienceIDs NSArray<NSString *>?, output - The IDs of the audiences the user belongs to. The array is empty if the user doesn't belong to any audience.
  • error NSError?, output - The error object (if any). For example, HTTP 404 when the profile doesn't exist yet.

Examples

To get the user's audience IDs:

PiwikTracker.sharedInstance()?.getAudiences { audienceIDs, error in
    if let audienceIDs = audienceIDs {
        // Do something with the audience IDs
    } else if let error = error {
        // Handle error
    }
}
[[PiwikTracker sharedInstance] getAudiencesWithCompletionBlock:^(NSArray<NSString *> * _Nullable audienceIDs, NSError * _Nullable error) {
    if (audienceIDs) {
        // Do something with the audience IDs
    } else if (error) {
        // 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?