Audience Service
Audience Service is responsible with subscribing to Segments on DataSapien Mobile Backend to make targeting users possible via Audiences.
Segments (Segment Definitions to be more specific) and Audiences are created and managed on Orchestrator.
Mobile SDK performs background network access to download Segments Definitions & Audiences from DataSapien Mobile Backend.
Segment Subscriptions
A Segment subscription is a simple flag that indicates a particular Mobile SDK instance is in a specific Segment Definition. Mobile SDK may "subscribe to" or "unsubscribe from" a segment upon MeData collection. Audience Service is triggered upon MeData value collection and if there is a defined segmentation for the MeData Definition for which a new value was collected, Audience Service calls DataSapien Mobile Backend's subscription endpoint.
It is possible to create Segment Definitions based on any MeData Definition on Orchestrator. As an example consider Country of residence MeData Definition, we can create a UK Residents segment by selecting "Country" MeData Definition and providing "UK" as the value. It is clear that we can have TR Residents, US Residents and so forth. Similarly, Gender MeData Definition with "Male" value creates Males segment and "Female" value creates Females segment.
On mobile side, when MeData Service collects and updates the value for Country of residence (source of this is not relevant at this stage), Audience Service taps in to see if there is a segmentation for that value. If collected country value is "UK", Audience Service calls Mobile Backend subscription endpoint to subscribe to UK Residents.
Audiences
Audiences are logical combinations of Segment Definitions. In other words; an Audience is just a named combination of 'Segments'.
Lets reuse Country of residence and Gender based Segments from previous section to understand how powerfull Audiences can be. Using just those two we can create various Audiences:
UK MalesAudience: By using "AND" logical operator: "UK Residents"AND"Males"Turkey or UK ResidentsAudience: By using "OR" logical operator: "TR Residents"OR"UK Residents"Females in Turkey or UKAudience: By using "AND" and "OR" logical operators: "Females"AND("TR Residents"OR"UK Residents")
With users (Mobile SDK in their name) subscribed to their related Segments, platform is now capable of finding specific users for a given Audience by calculating combinations.
Audience Service Functions
To access AudienceService functions; get its instance from DataSapien object: DataSapien.getAudienceService().
Fetch Segments
Fetches Segment list from the backend.
- Swift
- Kotlin
// Signature
public func fetchSegments(onSuccess: @escaping ([Segment]) -> Void,
onError: ((Error) -> Void)? = nil)
// Usage
DataSapien.getSegmentService().fetchSegments { segments in
} onError: { error in
}
// TBD...
Fetch and subscribe Segments
Fetches and auto subscribes to segments.
- Swift
- Kotlin
// Signature
public func fetchAndSubscribeToSegments(onSuccess: @escaping ([Segment]) -> Void,
onError: ((Error) -> Void)? = nil)
// Usage
DataSapien.getSegmentService().fetchAndSubscribeToSegments { segments in
} onError: { error in
}
// TBD...