> For the complete documentation index, see [llms.txt](https://lionstudios.gitbook.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lionstudios.gitbook.io/readme/features/whoami-service.md).

# WhoAmI Service

### **Initialization**

Initialization runs automatically on startup.

On first session, during this step, the service sends requests to both the **Location API** and the **Adjust API**.

> These network calls may take several seconds to complete. You should wait for them to finish before relying on returned data.

This data typically does not change often. However, a user’s location may change (for example, when traveling or using a VPN), and re-attribution events can occur if the user interacts with new marketing campaigns. For these reasons, the WhoAmI service periodically refreshes its data to ensure accuracy.

After its initial successful fetch (per service), these API calls are performed once per day, regardless of the number of app sessions.

The refresh interval can be adjusted via the SDK settings: `public int FetchRefresh = 86400;`

Note: It will not re-run if the app is left open.

Note: Location is updated with every session for legal restriction checks. It is updated via the global config handler.

***

## Implementation

The following methods are available to use. Each return different information about the player.

#### `GetDataAsync(bool useCache)` – Full Fetch

This method returns the latest fetched data once initialization completes.\
You can pass **true** or **false** to the useCache parameter

* **true** -> Returns cached data immediately if a previous fetch succeeded, otherwise waits for a fresh fetch.
* **false** -> Forces a full refresh from the APIs, ignoring any cached values.

{% hint style="success" %}
Use useCache: true for most scenarios. This ensures fast returns once at least one successful fetch has completed.
{% endhint %}

Example:

```csharp
WhoAmIData whoAmIData = await WhoAmIService.GetDataAsync();

//Example of the data returned
/*
{
  "LastSuccessfulFetch": 1762390275,
  "CustomId": "nakama_123",
  "DeviceId": "8605F947-5B71-588B-8E26-1AFFE2F90480",
  "AdjustInfo": {
    "AdId": "123",
    "AttributionInfo": {
      "Campaign": "test_campaign_roas"
    }
  },
  "LocationInfo": {
    "countryName": "United States",
    "countryCode": "US",
    "regionName": "Nevada",
    "regionCode": "NV"
  }
}
*/
```

#### `GetDataCache()`

Use this to get the last saved info instantly (non-blocking). It will return the most recently cached data, even if the initialization hasn't finished. Some fields may be empty, so it is recommended to use this when you know the cache is available.

Example:

```csharp
WhoAmIData whoAmIData = WhoAmIService.GetDataCache();
```

#### `GetLocationInfoAsync(bool useCache)`

Use this to get location info. This information can return early and and doesn’t require a full fetch to complete (Adjust can be slow to pull).

You can pass **true** or **false** to the useCache parameter

* **true** -> Returns cached data immediately if a previous fetch succeeded, otherwise waits for a fresh fetch.
* **false** -> Forces a full refresh from the APIs, ignoring any cached values.

Example:

```csharp
LocationInfo locationInfo = WhoAmIService.GetLocationInfoAsync();

//Example of the data returned
/*
{
    "LocationInfo": 
    {
        "countryName": "United States",
        "countryCode": "US",
        "regionName": "Nevada",
        "regionCode": "NV"
     }
}
*/
```

#### `GetAdjustInfoAsync()`

Use this to get information retrieved from Adjust. This includes the users `ADID` and also attribution information. Attribution info includes `campaign` and `network` details. This method does not have a timeout due to Adjust long fetch times. If Adjust fails to fetch, then this will return an empty class.

Example:

```csharp
AdjustInfo adjustInfo = WhoAmIService.GetAdjustInfoAsync();

//Example of the data returned
/*
{
  "AdjustInfo": {
    "AdId": "123",
    "AttributionInfo": {
      "Campaign": "test_campaign_roas"
    }
  }
}
*/
```

#### `GetPersistentIdAsync()`

This uses an Id from Adjust that will attempt to be persistent between uninstalls so you it’s safe to use with your backend for authorization.

This value is cached after the first successful fetch, so it’s safe to use even before the next session completes initialization.

In Editor a device Id will always be returned. If you need to use device Id you can get that using: `_whoAmIData.DeviceId`

\
Example:

```csharp
string playerId = await WhoAmIService.GetPersistentIdAsync();
```

#### `GetPlatform()`

You can retrieve the current platform as a simple string using:

```csharp
var platform = WhoAmIService.GetPlatform();
```

`android` when running on Android

`ios` when running on iOS

`null` in other environments (e.g., Unity Editor, Windows, macOS)&#x20;

***

## Advanced Usage

#### Error Handling

WhoAmI automatically retries failed fetches using an exponential backoff strategy, increasing the delay up to a maximum of 64 seconds between attempts. These retries run fully in the background, allowing the game to continue operating normally while the service works toward a successful result.

Any API you call from your scripts such as retrieving location, Adjust data, or the persistent player ID will wait until WhoAmI has successfully completed its fetch. You do not need to implement your own retry logic. Simply await the provided async method and it will resume once the data is available.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://lionstudios.gitbook.io/readme/features/whoami-service.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
