# Application tracking

## Setup summary

In order to track activities on your application, you'll need to keep in mind the following :

* All user activities need to be sent to mediarithmics using the [**Tracking API**](/data-streams/data-ingestion/real-time-user-tracking/api.md)
* The [**Signature authentication**](https://developer.mediarithmics.io/resources/api-overview/authentication#signature-authentication) should be used to authenticate any requests between your application and mediarithmics. Don't hesitate to contact your Account manager to have more information about this.
* The activity and events in the payload need to comply with the specificities described below
* The user agent identifier ($user\_agent\_id) needs to be particularly formatted using guidelines described [here](/user-points/user-identifiers/userdevicetechnicalid.md#user_agent_id)

## Application integration options

The first option is to integrate a small piece of code (approx. 100 lines) into the application to execute calls to the mediarithmics tracking API. <mark style="color:$danger;">**Sample code for iOS and Android is available in the**</mark> [<mark style="color:$danger;">**Authentication**</mark>](/resources/api-overview/authentication.md#examples) <mark style="color:$danger;">**section**</mark> (see illustration below).

<figure><img src="/files/SHuvcxqAxGl57naXYNoq" alt=""><figcaption></figcaption></figure>

The second option is to re-use an already existing analytics tool. It is then possible to transfer events from the analytics solution's server to the mediarithmics API.

<figure><img src="/files/F5omJ7nwhbT3n7J4MiUl" alt=""><figcaption></figcaption></figure>

## Predefined event names

In the context of app tracking, predefined event names are available out-of-the-box to simplify and automate event processing ([full list of predefined event names](/user-points/user-activities.md#predefined-event-names)):

* app open event (`$app_open`) corresponds to the opening of the app and app resume event (when the app becomes active again)
* app install event (`$app_install`)
* app update event (`$app_update`)&#x20;

The install and update events are automatically calculated on server side and you don't have to send them :

* The install event (`$app_install`) is triggered the first time an app open event is received for a user, regardless if the user is new or existing.
* The update event (`$app_update`) is triggered when the SDK version, app version or OS version changes from one open to the next.

## Mobile application tracking - UserActivity formatting

In the context of mobile app tracking, you should adapt some fields of the UserActivity. Here are the fields to look out for :

| Field            | Type              | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ---------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| $type            | String enum       | The activity type should only be `APP_VISIT`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| $session\_status | String enum       | <p>The sessions status should be:<br><code>IN\_SESSION</code>: This value should be used if you’re making one API call per tracked event (recommended way). The platform will automatically aggregate all the events of a session sent through many API calls when this value is used.<br><code>CLOSED\_SESSION</code>: should be used only if you do <strong>a single API call</strong> per session at its end. In this case, you should provide ALL the events of the session in the <code>$events</code> array in the call. Each API call with this value will generate a new User Activity in the Platform.</p> |
| $user\_agent\_id | String (Optional) | The [user agent identifier](/user-points/user-identifiers/userdevicetechnicalid.md#user_agent_id-formatting-mobile-application-identifiers) of the user device containing a unified representation of an identifier                                                                                                                                                                                                                                                                                                                                                                                                 |
| $app\_id         | String            | The mobile app id (previously created through Navigator / API)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |

## CTV application tracking - UserActivity formatting

In the context of CTV app tracking, you should adapt some fields of the UserActivity. Here are the fields to look out for :

| Field            | Type              | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ---------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| $type            | String enum       | The activity type should only be `CTV_VISIT`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| $session\_status | String enum       | <p>The sessions status should be:<br><code>IN\_SESSION</code>: This value should be used if you’re making one API call per tracked event (recommended way). The platform will automatically aggregate all the events of a session sent through many API calls when this value is used.<br><code>CLOSED\_SESSION</code>: should be used only if you do <strong>a single API call</strong> per session at its end. In this case, you should provide ALL the events of the session in the <code>$events</code> array in the call. Each API call with this value will generate a new User Activity in the Platform.</p> |
| $user\_agent\_id | String (Optional) | The [user agent identifier](/user-points/user-identifiers/userdevicetechnicalid.md#user_agent_id-formatting-ctv-identifiers) of the user device containing a unified representation of an identifier.                                                                                                                                                                                                                                                                                                                                                                                                               |
| $ctv\_id         | String            | The ctv app id (previously created through Navigator / API)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |

{% hint style="info" %}
For CTV application tracking, we allow automatic capture of IP addresses.[ Learn more](/user-points/user-identifiers/networks-ids/device-based-network-ids/ip-address.md)<br>
{% endhint %}

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.mediarithmics.io/data-streams/data-ingestion/real-time-user-tracking/application-tracking.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
