Location Triggers (RXP) - rezolved/rezolve_sdk_sampleapp_android GitHub Wiki

One of the most powerful tools you can take advantage of with Rezolve Inside™ SDK is Location Triggers. It keeps a reference of the user's location, and through a decision making mechanism it sends unobtrusive Push Notifications at the right time, thus enticing customers into an action when it is deemed proper.

Initialising

The entry point of Location Triggers is run once, in order to inform the backend about the user's essential information - it is done automatically after RxpSDK is initialized (More on RxpSdk here). You can run checkIn yourself by using

APIResult<String> checkInApiResult = RXPClientProvider.client.checkIn(pushToken);
if (checkInApiResult instanceof APIResult.Success){
    //handle successful check in
    String accessToken = ((APIResult.Success<String>) checkInApiResult).getResult();
} else {
    //handle error
}

Getting available Interest Tags

With the current user already in check-in state, as seen in the previous section, we can now fetch the state of the user's Interest Tags. An array of RXPTag models will be provided as a response to this request, indicating the following parameters for each item:

  • tagId A unique identifier for this item
  • name Descriptive name of the Interest Tag
  • state Indicates whether the Tag is "UNDEFINED", "ENABLED" or "DISABLED" for this user Tags are accessible in two ways:
  • By TagsListWorker with RXPDatabase (currently only with Kotlin support - WIP: adding getting tags from db as LiveData)
RxpSdkProvider.sdk.runTagsListWorkerOnce();
val tags = RXPDatabaseProvider.database.tagDAO().getTags();
  • By executing RXPClientInterface.listTags()
APIResult<List<Tag>> listTagsApiResult = RXPClientProvider.client.listTags();
if (listTagsApiResult instanceof APIResult.Success){
    List<Tag> tags = ((APIResult.Success<List<Tag>>) listTagsApiResult).getResult();
} else {
    //handle error
}

Updating Interest Tags

The defining step that subscribes your audience into your established Location Triggers is updating the user's chosen Interest Tags, as seen on the following example. Any of this methods calls should trigger TagsUpdateWorker which is uploading Interest Tags from DB to API:

  • List<TagEntity> tags;
    RXPDatabaseProvider.database.tagDAO().updateTagsAndSetAllTagsWithStateUndefinedToDisabled(tags);
  • State state;
    RXPDatabaseProvider.database.tagDAO().updateAllTagsToState(state);
  • State withState;
    State toState;
    RXPDatabaseProvider.database.tagDAO().updateAllTagsWithStateToState(withState, toState)

or by executing RXPClientInterface.updateTags()

List<Tag> tagsToUpdate;
APIResult<List<Tag>> updateTagsApiResult = RXPClientProvider.client.updateTags(tagsToUpdate);
if (updateTagsApiResult instanceof APIResult.Success){
    //handle successful update
} else {
    //handle error
}

Invoking Location Tracking

After the user has identified to the backend service, and their Interest Tags are set, the last step would be to engage Location Tracking. During RxpSdk initialization periodic and onLocationChanged TrackingWorker are set up. You can modify its behaviour by modifing Checker.shouldProcessLocationUpdate method and supplying it in CheckerProvider. It needs to be set after RxpSdk initialization. You can also send your own updateTracking request

float latitude;
float longitude;
int radius;
APIResult<Geofences> updateTrackingApiResult = RXPClientProvider.client.updateTracking(
    latitude,
    longitude,
    radius,
    CoordinateSystem.WGS84
);
if (updateTrackingApiResult instanceof APIResult.Success){
    //handle successful update
} else {
    //handle error
}
⚠️ **GitHub.com Fallback** ⚠️