Workflow
This document describes the workflow of the v3 of the Mobile Engage API.
Process
-
App start-up
-
App/Browser loads Emarsys SDK
-
As part of initialization (before any behavior could be tracked),
-
If device properties have changed or were never sent: Emarsys SDK automatically registers the device properties with the ME Backend. Emarsys SDK gets back the
X-CLIENT-STATEwhich it stores and then sends on every other request. See /apps/:appCode/client endpoint of Client Properties Service -
If there are no contact tokens and anonymous users are enabled: Emarsys SDK automatically links the anonymous user with the ME Backend and receives a refresh-token as well as a contact token and stores them on the device. See /apps/:appCode/client/contact?anonymous endpoint of Client Service
-
-
The Emarsys SDK automatically registers a
app:startinternal event to the DES servers using the contact token received. See /apps/:appCode/client/events endpoint of Device Event Service -
The app may or may not receive a push token from the push token provider (fcm/apns/chrome/firefox/safari), but if it does, the Emarsys SDK always registers the push token with the ME Backend. See /apps/:appCode/client/push-token endpoint of Client Service.
-
The app developer can ask the SDK to track interaction and events, and the Emarsys SDK will register the event with the ME Backend using the current contact token. See /apps/:appCode/client/events endpoint of Device Event Service
-
The app user signs into the customer backend, the customer backend verifies the credentials and provides the app with the unique, non-guessable, immutable value assigned to an Emarsys CRM Database contact. The Emarsys SDK uses that value as the contact field value (together with the initially configured contact field id) and sends it to the ME backend to link the client to the contact. The Emarsys SDK receives new refresh and contact tokens. See /apps/:appCode/client/contact endpoint of Client Service.
-
When the app user logs out from the customer backend, the app developer will trigger the Emarsys SDK to unlink the identified contact and link to a new anonymous contact. The Emarsys SDK receives new refresh and contact tokens. See /apps/:appCode/client/contact?anonymous endpoint of Client Service.
Typical scenario
App downloaded from app store and started for the first time
-
Because there was never a registration of the device’s properties to the backend, the Emarsys SDK calls the /apps/:appCode/client endpoint without app developer input. The SDK stores X-CLIENT-STATE and a hash of what it sent to /apps/:appCode/client.
-
Because the local contact token and refresh token do not exist, the Emarsys SDK calls the /apps/:appCode/client/contact?anonymous endpoint without app developer input just to link the device to an anonymous user. The SDK stores the returned contact- and refresh token.
-
No matter what the state of previous calls were, the Emarsys SDK automatically calls the /apps/:appCode/client/events endpoint with X-CONTACT-TOKEN and the internal session:start event without app developer input. The SDK also sends the X-CLIENT-STATE it has stores the newly returned X-CLIENT-STATE and a hash of what it sent to /apps/:appCode/client.
Once the app receives the push token, either the SDK directly receives it and registers it or the app developer triggers an update of the push token with /apps/:appCode/client/push_token endpoint.
-
If the app user at a later stage verifies their credentials with the customer backend, the app developer uses the immutable, unique and non-guessable identifier it stored on the Emarsys CRM DB it got from its backend and uses the Emarsys SDK to call /apps/:appCode/client/contact with that identifier. The SDK also sends the X-CLIENT-STATE it has and stores the newly returned X-CLIENT-STATE.
App was already on the device and the user already logged into to the customer backend and was started for the first time since it was upgraded to an Emarsys SDK using version
-
Because there was never a registration of the device’s properties to the backend, the Emarsys SDK calls the /apps/:appCode/client endpoint without app developer input. The SDK stores X-CLIENT-STATE and a hash of what it sent to /apps/:appCode/client.
-
Because the local contact token and refresh token do not exist, the Emarsys SDK calls the /apps/:appCode/client/contact?anonymous endpoint without app developer input just to link the device to an anonymous user. The SDK stores the returned contact- and refresh token.
-
No matter what the state of previous calls were, the Emarsys SDK automatically calls the /apps/:appCode/client/events endpoint with X-CONTACT-TOKEN and the internal session:start event without app developer input. The SDK also sends the X-CLIENT-STATE it has stores the newly returned X-CLIENT-STATE and a hash of what it sent to /apps/:appCode/client/contact.
-
Once the app receives the push token, either the SDK directly receives it and registers it or the app developer triggers an update of the push token with X-CONTACT-TOKEN and the /push-token endpoint. The SDK also sends the X-CLIENT-STATE it has and stores the newly returned X-CLIENT-STATE and a hash of what it sent to /pushtoken.
-
As the app user was already authentified, the app developer uses the immutable, unique and non-guessable identifier it stored on the Emarsys CRM DB it got from its backend and uses the Emarsys SDK to call /apps/:appCode/client/contact with that identifier. The SDK stores the tokens. The SDK also sends the X-CLIENT-STATE it has and stores the newly returned X-CLIENT-STATE.
-
If app developer decides to notify Emarsys of any event, the SDK queues it up to call the /events on a separate thread. Events are sent as an array of at least one event using X-CONTACT-TOKEN. The SDK also sends the X-CLIENT-STATE it has and stores the newly returned X-CLIENT-STATE.
App on the same version without any new push token is started a second time by a user
-
Because nothing changed on the device properties, the Emarsys SDK does not call the /apps/:appCode/client/contact endpoint.
-
No matter what the state of previous calls were, the Emarsys SDK automatically calls the /apps/:appCode/client/events endpoint with X-CONTACT-TOKEN and the internal session:start event without app developer input. The SDK also sends the X-CLIENT-STATE it has stores the newly returned X-CLIENT-STATE and a hash of what it sent to /apps/:appCode/client/contact.
-
Once the app receives the push token, if it has not changed, the SDK does not call the /apps/:appCode/client/push_token endpoint.
-
As the app user was already authentified, the app developer uses the immutable, unique and non-guessable identifier it stored on the Emarsys CRM DB it got from its backend and uses the Emarsys SDK to call /apps/:appCode/client/contact with that identifier. The SDK stores the returned tokens. The SDK also sends the X-CLIENT-STATE it has and stores the newly returned X-CLIENT-STATE.