# Push Diagnosis Data

## **Introduction**

The DriveKit SDK regularly collects information on the smartphone's configuration: application permissions, sensor statuses and any user-generated events.

The push diagnosis data service is designed to share all diagnosis data collected by the DriveKit SDK installed on each of your users' mobile applications with your platform.

These insights can be used to:

* Identify users facing configuration issues, which may improve the onboarding experience
* Detect trip recording issues caused by user events (logout, app uninstallation, phone shutdown...)

## **Principle**

The diagnosis data push service sends the diagnosis events right after they are transmitted by the DriveKit SDK to the DriveQuant platform. The process is described below:

* The DriveKit SDK collects the diagnosis data, which is stored locally on the user's phone.
* The DriveKit SDK sends the diagnosis data to the DriveQuant platform at least one a day. There is no precise time for data retrieval, as this depends on the state of the application and the smartphone.
* If you subscribe to the push diagnosis data service, the data is transmitted to your platform as soon as it is received and stored on the DriveQuant platform.

{% hint style="info" %}
All diagnostic events are shared after an initial installation and initialization of the DriveKit SDK. The initial push diagnosis data is delayed by at least 30 minutes in order to give the user time to grant permissions.

The push is triggered by the SDK, which sends information once a day even if there are no changes in diagnostic indicators. An empty push means that there are no changes. The daily push, even if empty, confirms that the application is still installed and active on the user's phone.
{% endhint %}

## Configuration

See [Configuration](https://docs.drivequant.com/introduction#configuration) in the parent section.

The body of the request is a JSON object with a set of fields that contain the driving scores organized by categories and the raw data collected on the user smartphone stored in tables.  An example of data in JSON format is given at [the end of this section](#sample-message).

Your service should respond with a `2xx` http status code (typically `200 OK`) when the push request is accepted. **Any other code will be considered as a failure**, and the service will attempt to send the data again as defined in the [Retry Policy section](#retry-policy).

{% hint style="danger" %}
If your service responds with a `2xx` http status code, while the data has *not* been accepted by your platform, then there will be *no further attempt to send the data!*
{% endhint %}

## Retry Policy

Every push request not successfully acknowledged by your service will be retried **once a day**. Also, the failed events will be sent every time the SDK sends an update, and *before* sending any new event. After 30 unsuccessful attempts, the push data will be permanently discarded.

## Sample Message

The body of the request is a JSON object with a set of fields containing the user unique identifier, the user's smartphone data, and a list of the events collected by the SDK, divided into 4 categories:

1. **permissions**: events related to the application’s permissions
2. **sensors**: events related to the smartphone’s sensors
3. **settings**: events related to the smartphone’s configuration
4. **events**: events related to user's events (login/logout, app install/uninstall, smartphone on/off)

The table below lists the types of diagnosis data and their possible values.

<table><thead><tr><th width="159">Category</th><th width="288">Type</th><th>Possible values</th></tr></thead><tbody><tr><td><strong>permissions</strong></td><td><code>NOTIFICATION_ACCESS</code></td><td><code>GRANTED</code> / <code>DENIED</code></td></tr><tr><td><strong>permissions</strong></td><td><code>LOCATION_ACCESS</code></td><td><code>GRANTED</code> / <code>DENIED</code></td></tr><tr><td><strong>permissions</strong></td><td><code>BLUETOOTH_ACCESS</code></td><td><code>GRANTED</code> / <code>DENIED</code></td></tr><tr><td><strong>permissions</strong></td><td><code>ACTIVITY_ACCESS</code></td><td><code>GRANTED</code> / <code>DENIED</code></td></tr><tr><td><strong>sensors</strong></td><td><code>GPS_SENSOR</code></td><td><code>ENABLED</code> / <code>DISABLED</code> </td></tr><tr><td><strong>sensors</strong></td><td><code>BLUETOOTH_SENSOR</code></td><td><code>ENABLED</code> / <code>DISABLED</code> </td></tr><tr><td><strong>settings</strong></td><td><code>LOW_POWER_MODE</code></td><td><code>ENABLED</code> / <code>DISABLED</code> </td></tr><tr><td><strong>settings</strong></td><td><code>PERMISSIONS_AUTO_DELETE</code></td><td><code>ENABLED</code> / <code>DISABLED</code></td></tr><tr><td><strong>settings</strong></td><td><code>BATTERY_OPTIMISATION</code></td><td><code>ENABLED</code> / <code>DISABLED</code></td></tr><tr><td><strong>events</strong></td><td><code>PHONE_STATE</code></td><td><code>TURNED_ON</code> / <code>TURNED_OFF</code></td></tr><tr><td><strong>events</strong></td><td><code>APP_STATE</code></td><td><code>INSTALLED</code> / <code>UNINSTALLED</code></td></tr><tr><td><strong>events</strong></td><td><code>LOGIN_STATE</code></td><td><code>LOGGED_IN</code> / <code>LOGGED_OUT</code></td></tr></tbody></table>

The OpenAPI specification can be downloaded [here](https://gist.github.com/DriveQuantPublic/f9993ed846c18538b6d86a2fb8aba1c7) in OpenAPI YAML format.

<details>

<summary>Sample message (click to expand)</summary>

```json
{
    "userId": "john.doe@drivequant.com",
    "installationId": "9cc02aaa-92b4-cbd2-73fb-3dda6243dddf",
    "smartphoneData": {
        "phoneModel": "iPhone 15 Pro",
        "appBuildNumber": "1032",
        "appVersion": "5.2.1",
        "osVersion": "17.4.1",
        "osType": "iOS",
        "sdkVersion": "2.1",
        "lastUpdate": "2024-05-21T08:52:53.470+0000"
    },
    "permissions": [
        {
            "date": "2024-05-20T12:15:32.000+0000",
            "type": "NOTIFICATION_ACCESS",
            "value": "DENIED"
        },
        {
            "date": "2024-05-20T14:15:32.000+0000",
            "type": "NOTIFICATION_ACCESS",
            "value": "GRANTED"
        },
        {
            "date": "2024-05-20T12:15:24.000+0000",
            "type": "BLUETOOTH_ACCESS",
            "value": "DENIED"
        },
        {
            "date": "2024-05-20T14:15:24.000+0000",
            "type": "BLUETOOTH_ACCESS",
            "value": "GRANTED"
        },
        {
            "date": "2024-05-20T12:15:26.000+0000",
            "type": "ACTIVITY_ACCESS",
            "value": "DENIED"
        },
        {
            "date": "2024-05-20T14:15:26.000+0000",
            "type": "ACTIVITY_ACCESS",
            "value": "GRANTED"
        },
        {
            "date": "2024-05-20T12:15:22.000+0000",
            "type": "LOCATION_ACCESS",
            "value": "DENIED"
        },
        {
            "date": "2024-05-20T14:15:22.000+0000",
            "type": "LOCATION_ACCESS",
            "value": "GRANTED"
        }
    ],
    "sensors": [
        {
            "date": "2024-05-20T12:14:22.000+0000",
            "type": "GPS_SENSOR",
            "value": "DISABLED"
        },
        {
            "date": "2024-05-20T14:14:22.000+0000",
            "type": "GPS_SENSOR",
            "value": "ENABLED"
        },
        {
            "date": "2024-05-20T13:15:02.000+0000",
            "type": "BLUETOOTH_SENSOR",
            "value": "DISABLED"
        },
        {
            "date": "2024-05-20T13:15:22.000+0000",
            "type": "BLUETOOTH_SENSOR",
            "value": "ENABLED"
        }
    ],
    "settings": [
        {
            "date": "2024-05-20T11:44:00.000+0000",
            "type": "LOW_POWER_MODE",
            "value": "ENABLED"
        },
        {
            "date": "2024-05-20T12:03:27.000+0000",
            "type": "LOW_POWER_MODE",
            "value": "DISABLED"
        }
    ],
    "events": [
        {
            "date": "2024-05-15T13:25:22.000+0000",
            "type": "PHONE_STATE",
            "value": "TURNED_OFF"
        },
        {
            "date": "2024-05-15T13:28:22.000+0000",
            "type": "PHONE_STATE",
            "value": "TURNED_ON"
        },
        {
            "date": "2024-05-10T14:15:22.000+0000",
            "type": "APP_STATE",
            "value": "INSTALLED"
        },
        {
            "date": "2024-05-12T08:34:21.000+0000",
            "type": "APP_STATE",
            "value": "UNINSTALLED"
        },
        {
            "date": "2024-05-18T11:12:46.000+0000",
            "type": "APP_STATE",
            "value": "INSTALLED"
        },
        {
            "date": "2024-05-10T14:20:02.000+0000",
            "type": "LOGIN_STATE",
            "value": "LOGGED_IN"
        },
        {
            "date": "2024-05-12T08:32:11.000+0000",
            "type": "LOGIN_STATE",
            "value": "LOGGED_OUT"
        },
        {
            "date": "2024-05-18T11:15:35.000+0000",
            "type": "LOGIN_STATE",
            "value": "LOGGED_IN"
        }
    ]
}
```

</details>
