---
description: Api EndPoints To Track Events From Android/Ios Apps
---

# Android/IOS Tracker

_For Any Queries Drop a mail at : aman@crunchit.ai_



> Session Id
>
> ```
> Session id is generated when user starts new session.
> ```

> Distinct Id :&#x20;
>
> ```
> Keep distinctid same in different user sessions.It will help in merging event.
> That user produced before user identification.
>
> Keep distinctid it in local Storage and if user clears the local storage.
> Generate the new distinctid for that user using our api(mentioned below).
>   
> ```





_**To Generate Session Id and distinct Id :**_&#x20;

```
curl --location 'https://events-backend-5dzspnb6za-uc.a.run.app/generate-session' \
--header 'project_id;'
```

Headers :&#x20;

```
project_id : apikey (required)
```

> Api Response :&#x20;
>
> ```
> Status Code : 200
>
> {
>     "success": true,
>     "sessionId": "aae5029b9ab1b817c6a42731cc93ba1c3e9d57a0cb27ab7893c7765359b1fcb6"
> }
>
> ```

_**Track Event**_&#x20;

```
curl --location 'https://events-backend-5dzspnb6za-uc.a.run.app/track/event' \
--header 'project_id: ' \
--header 'Content-Type: application/json' \
--data '{
    "activity" : [{
        "distinctId" : "123",
        "id" : "132", 
        "timestamp" : "1695710198415", 
        "userIntent" : "test ios",
        "anyCustomKey" : "anyCustomValue",
        "utmParameter" : {
            "utm_source" : "",
            "utm_medium" : "",
            "utm_campaign" : "",
            "utm_term" : "",
            "utm_content" : ""
        },
        "ipAddress"  : "",
        "userAgent" : ""
    }]
}'
```

> Headers :&#x20;
>
> ```
> project_id : apikey (required)
> ```

> Payload&#x20;
>
> ```
> distinctId - to track user before identification.and merge events to with identified user (required),
> id - session id (required),
> timestamp - event produced time.should be in milliseconds (required), 
> userIntent - event name (required),
> anyCustomKey - custom properties (optional),
> utmParameter - to track from where the traffic is coming { 
>     utm_source : (optional),
>     utm_medium :  (optional),
>     utm_campaign : (optional),
>     utm_term : (optional),
>     utm_content : (optional)
> } - (optional) 
> ipAddress - Geolocate the user (optional),
> userAgent - to detect browser,device etc (optional)
> ```

> Extra Points :&#x20;
>
> 1. keep the object nested level at 1.To add Nested Objects flatten it :&#x20;
>
> ```
> Example : 
> Original Object : 
>     const payload = {
>         "akey" : "aValue"
>         "obj" : {
>             "prop1" : "prop2"
>             ....
>         }
>         ....
>     }
>
> After Flattening : 
>    const payload = {
>         "akey" : "aValue"
>         "obj.prop1" : "prop2"
>         ....
>     }
>
> ```

> Api Response :&#x20;
>
> ```
> Status Code : 201
>
> {
>     "success": true,
> }
>
> ```

_**Identify User**_

```
curl --location 'https://events-backend-5dzspnb6za-uc.a.run.app/add-relation' \
--header 'project_id;' \
--header 'Content-Type: application/json' \
--data '{
    "uniqueIdentifier": "",
    "id": "",
    "email": "",
    "name": "",
    "anycustomKey" : "anyCustomProp"
}'
```

> Headers :&#x20;
>
> ```
> project_id : apikey (required)
> ```

> payload :&#x20;
>
> ```
> uniqueIdentifier : user identifier (required),
> id - session id (required),
> email - emailId (optional),
> name - name (optional),
> anycustomKey - custom properties (optional) 
> ```

> Extra Points :&#x20;
>
> 1. keep the object nested level at 1.To add Nested Objects flatten it :&#x20;
>
> ```
> Example : 
> Original Object : 
>     const payload = {
>         "akey" : "aValue"
>         "obj" : {
>             "prop1" : "prop2"
>             ....
>         }
>         ....
>     }
>
> After Flattening : 
>    const payload = {
>         "akey" : "aValue"
>         "obj.prop1" : "prop2"
>         ....
>     }
> ```

> Api Response :&#x20;
>
> ```
> Status Code : 201
>
> {
>     "success": true,
> }
> ```
