# 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,
> }
> ```


---

# 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://crunch.gitbook.io/developer-docs/getting-started/android-ios-tracker.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.
