Analytics Regions
Optional
Needed if your app measures how long users spend in product categories or aisles.
Available since SDK v9.9.0
Overview
Analytics regions are Regions that describe the merchandising layout of a store: category regions (the floor area of a product category) and aisle regions. Together with location visits, they let your app measure how much time users spend in each category or aisle, how far they walk there, and how long they stand still.
The basic flow (after a successful Login) is:
- Get the analytics regions of the building with IPSContent.getAnalyticsRegions(), filtered by type (category or aisle).
- Create an IPSLocationVisit for each region you want to monitor and register them with IPSProximity.addLocationVisitEvents().
- Receive IPSLocationVisitStatistics each time the user leaves a monitored region.
Getting Analytics Regions
Use IPSContent.getAnalyticsRegions() with the building ID and an IPSAnalyticsRegionType: IPSAnalyticsRegionType.CATEGORY or IPSAnalyticsRegionType.AISLE. Pass null to get regions of all types.
IPSContent.getAnalyticsRegions(
buildingId,
IPSAnalyticsRegionType.CATEGORY,
object : IPSGetByIdListener<IPSAnalyticsRegion> {
override fun onResults(results: List<IPSAnalyticsRegion>) {
// Category regions of the building
}
override fun onError(error: IPSError) {
}
}
)
The method returns an IPSCancelable that can be used to cancel the request. If the SDK is offline (see IPSCore.ConnectionState), it returns null and onError is called.
Analytics Region Object
IPSAnalyticsRegion extends IPSRegion, so it has all the properties described in the Regions guide, plus a region type:
| Property | Description | Example |
|---|---|---|
analyticsRegionType |
The type of the region (CATEGORY or AISLE), or null if unspecified. |
CATEGORY |
getPlacements() |
The region's placements, usually a single one. Each placement has a shape: rectangular (bottom-left and top-right corners), circular (center and radius in meters), or polygonal (list of vertices). See Region Shape. | Rectangle from (10.0, 30.22) to (100.0, 140.84) |
getName() |
Category regions: the category description. | Dairy |
getClientDepartmentId() |
Category regions: the category ID. Aisle regions: the aisle number. |
1023 / 59 |
getMetadata() |
JSON with additional fields. Aisle regions: categories holds the IDs of the categories inside the aisle. |
{"categories": ["1023", "1056"]} |
Tip
The category and aisle data is set up by Oriient from the store's planogram data during onboarding.
Tracking Location Visits
An IPSLocationVisit describes a location to monitor and a callback that is invoked when the user leaves it:
groupId: optional ID used to remove several visits at once;buildingIdandfloorOrder: where the location is;locationDefinition: the area to monitor, an IPSLocalProximityLocationDefinition. For an analytics region, useIPSLocalProximityLocationDefinition.fromIpsRegion(). It returnsnullfor unsupported shapes;onLocationVisited: called with the visit statistics once the user leaves the location.
fun onCategoryRegionsLoaded(regions: List<IPSAnalyticsRegion>, buildingId: String, floorOrder: Int) {
val visits = regions.mapNotNull { region ->
val location = IPSLocalProximityLocationDefinition.fromIpsRegion(region) ?: return@mapNotNull null
IPSLocationVisit(
groupId = "Category visits", // used to remove all these visits at once
buildingId = buildingId,
floorOrder = floorOrder,
locationDefinition = location,
onLocationVisited = { statistics ->
reportCategoryVisit(region.getClientDepartmentId(), statistics)
}
)
}
IPSProximity.addLocationVisitEvents(visits)
}
Important
Visits are detected from the user's position, so they are only tracked during an active Positioning session.
Visit Statistics
IPSLocationVisitStatistics describes a completed visit:
| Field | Description | Example |
|---|---|---|
travelDistance |
Distance (meters) traveled while inside the location. | 123.4 |
timeSpentMillis |
Total time (ms) spent in the location. | 32100 |
enterTimestamp |
Time (ms since epoch) the user entered the location. | 1785779144863 |
exitTimestamp |
Time (ms since epoch) the user exited the location. | 1785779969711 |
timeDwellMillis |
Time (ms) the user stood still within the location. Use it to tell a real dwell from a pass-through. | 25345 |
Managing Visits
- IPSProximity.addLocationVisitEvents() adds visits to the ones already registered;
- IPSProximity.setLocationVisitEvents() replaces the whole list;
- IPSProximity.removeLocationVisitEvents() removes the given visits;
- IPSProximity.removeLocationVisitEventsByGroupIds() removes every visit with one of the given
groupIds; - IPSProximity.removeAllLocationVisitEvents() removes all visits.
fun onUserLeftStore() {
IPSProximity.removeLocationVisitEventsByGroupIds(listOf("Category visits"))
}