Location Tracking (Version 2.x)

The Data 360 Module for the Engagement Mobile SDK supports location tracking for all events. Enable this functionality using the setLocation method on the Data 360 Module to set coordinates and expiresIn.

iOS
1// Prepare the coordinates using the CdpCoordinates wrapper
2let coordinates = CdpCoordinates(latitude: 54.187738, longitude: 15.554440)
3
4// Set the location coordinates and expiration time in seconds
5CdpModule.shared.setLocation(coordinates: coordinates, expiresIn: 60)
Android
1CdpSdk.requestSdk { sdk ->
2    // Prepare the coordinates using the Coordinates wrapper
3    val coordinates = Coordinates(latitude = 54.187738, longitude = 15.554440)
4
5    // Set the location coordinates and expiration time in seconds
6    sdk.setLocation(coordinates = coordinates, expiresIn = 60)
7}

When the SDK has non-expired location coordinates, the location attributes are automatically appended to event attributes as key-value pairs with the key names latitude and longitude.

When the expiration interval is exceeded, the SDK location coordinates are cleared and no longer attached to events. To prevent location from being attached to events before the coordinates expire, call setLocation and pass nil values as the coordinates.

You’re responsible for handling location tracking permission from the customer, requesting location permission, fetching the location, and ensuring the desired accuracy range.

Note