Stats
Apps connected to TAG can report how they are used: which screens people open, what they tap, scan or play, and when the app starts and stops. TAG stores every event so administrators can chart app usage by day, week or month, and drill into any part of the app, without knowing anything about the app in advance.
Before you start:
The app needs an access token for its device, obtained through Device Discovery and Authentication. The events are recorded against the device behind the token; there is no device field in the request.
Send the User-Agent described in REST API with every call. TAG stores it with each event, and it is how reports tell app names and versions apart.
Event object
Each event is a JSON object with these properties:
recordedAt (integer, required): when the event happened on the device, as a Unix timestamp in seconds. It may be in the past (events queued while offline), but no more than 5 minutes in the future.
path (string, required, up to 255 characters, starts with
/): what the app is showing, see Paths.eventType (string, required, up to 64 characters): what happened, see Event types. Lower-case letters, digits,
-and_only.message (string, optional, up to 255 characters): a human-friendly label for the path or the event, shown in reports, like
Print spoolorSubmit registration.payload (object, optional, up to 4096 bytes once JSON encoded): any extra detail, see Payload.
Any other property makes the event invalid, so a misspelt mesage is reported rather
than silently lost.
Example:
{
"recordedAt": 1793906300,
"path": "/settings/printers/spool",
"eventType": "view",
"message": "Print spool"
}
Paths
The path describes what the app is currently showing, from the screen down to the control the event is about, one level per segment:
/settings/printers/spool: the print spool screen, under printers, under settings/exhibitors/satellite: the page for the exhibitor Satellite/intro/registration/form/submit-button: the submit button of the registration form
Reports group events by path and drill into them one segment at a time, so:
Use the same path every time the same thing is shown. Build it from stable names, not from what happens to be on screen.
Write each segment as a lower-case slug, with words separated by
-.Never put personal data in a path. A path names a screen, not a person.
Put the readable name in
messageand keep the path short and stable.
Paths whose first segment starts with _, like /_app, are reserved for the
Lifecycle events below. Any other path in that range is rejected.
Event types
The event type says what happened at the path. Use these types whenever they fit, so that reports work the same way across every app:
eventType |
When to send it |
Payload suggestion |
|---|---|---|
|
A screen is shown. The path is the screen, like |
|
|
The user touches a control on a touch screen. The path names the control, like
|
|
|
The same as |
|
|
The app shows the on-screen keyboard. The path names the field, like
|
|
|
The app handles input the user typed, once per field committed. Never send what was typed. |
|
|
The app hides the on-screen keyboard. |
|
|
The app scans an RFID tag or a barcode. The path is the scanning screen. |
|
|
The user takes a picture. The path is the capture screen. |
|
|
The user plays, or causes, audio, video or an animation to play. The path names the
media or the player, like |
|
This list is not exhaustive. When none of these fits, add your own type following the
same convention: a short, lower-case word for the interaction, with words separated by
-. For example swipe for a swipe gesture or print when the app sends something
to a printer. Tell the TAG team about new types so they can be added here and reused by
other apps.
Lifecycle events
Three reserved events mark when the app is in use. Send them every time, so reports can tell when and for how long the app was used:
path |
eventType |
When to send it |
|---|---|---|
|
|
The app process starts (a cold start). |
|
|
The app comes to the foreground, or the user starts using it. |
|
|
The app goes to the background or is closed. |
Payload
The payload carries any detail that does not fit the other properties, as a JSON object
of up to 4096 bytes once encoded. Its values keep their JSON types. Keys must be letters,
digits or _, must not start with _, and must not be password, secret or
token. Keep it small and keep personal data out of it unless the project needs it,
such as the badge code a scan read.
{
"recordedAt": 1793906200,
"path": "/exhibitors/satellite/lead-scanner",
"eventType": "scan",
"message": "Badge scanned",
"payload": {"kind": "barcode", "value": "DLG-000412"}
}
Sending events
Events are sent in batches of 1 to 500. The app can send each event as it happens, in a batch of one, or keep a queue and send it in batches, which is better while the device is offline. Send events in the order they happened, and never send the same event twice: TAG does not detect duplicates, so a resent event is counted twice.
Each event in a batch is checked on its own. Valid events are stored even when others in the same batch are rejected, and the response lists the rejected ones with the reason. When handling the response:
200: the batch is done. Remove every event in it from the queue, including the rejected ones; log the rejections so they can be fixed in the app, but do not resend them, they would be rejected again.
400: nothing was stored, because the batch itself was malformed or every event in it was rejected. Do not resend it as it is.
401: the access token is missing or expired. Get a new token and resend.
404: the token does not belong to a device. Pair the app again through device discovery.
5xx or no response: nothing is known to be stored. Keep the events and resend them later.
POST /stats/events
Stores a batch of events for the device behind the access token.
The request has one property:
events: a list of 1 to 500 events, each as described in Event object
Example request:
POST /api/v5/stats/events.json HTTP/1.1
Authorization: Bearer <device-access-token>
Content-Type: application/json
User-Agent: EventScanner/1.0.3/1799_LAB (SM-G965F; Android 10; Scale/2.63)
{
"events": [
{"recordedAt": 1793905923, "path": "/_app", "eventType": "start"},
{"recordedAt": 1793905924, "path": "/_session", "eventType": "start"},
{"recordedAt": 1793905925, "path": "/intro", "eventType": "view", "message": "Welcome"},
{"recordedAt": 1793905940, "path": "/intro/registration/form", "eventType": "view",
"message": "Registration form"},
{"recordedAt": 1793905952, "path": "/intro/registration/form/email", "eventType": "keyboard-show"},
{"recordedAt": 1793905970, "path": "/intro/registration/form/submit-button", "eventType": "tap",
"message": "Submit registration"},
{"recordedAt": "yesterday", "path": "/exhibitors/satellite", "eventType": "view"},
{"recordedAt": 1793906200, "path": "/exhibitors/satellite/lead-scanner", "eventType": "scan",
"message": "Badge scanned", "payload": {"kind": "barcode", "value": "DLG-000412"}},
{"recordedAt": 1793906400, "path": "/_session", "eventType": "end"}
]
}
The response gives the number of events stored, the events rejected, by their position
in the list (counting from 0) with the reasons per property. Errors about the event as a whole, such as an unknown property or a reserved
path, are listed under event.
Example response:
{
"data": {
"accepted": 8,
"rejected": [
{"index": 6, "errors": {"recordedAt": ["Please enter an integer."]}}
]
},
"meta": []
}
When the batch itself is malformed, the reason is given under meta.validation.events:
{
"data": [],
"meta": {
"validation": {"events": "Must contain at most 500 events."},
"error": {"code": 400, "message": "The submitted data does not validate.", "internalCode": 400}
}
}
When every event is rejected, meta.validation.rejected holds the same list as
data.rejected above.