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
GetDataAsync(bool useCache) – Full FetchThis 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.
Use useCache: true for most scenarios. This ensures fast returns once at least one successful fetch has completed.
Example:
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()
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:
WhoAmIData whoAmIData = WhoAmIService.GetDataCache();GetLocationInfoAsync(bool useCache)
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:
LocationInfo locationInfo = WhoAmIService.GetLocationInfoAsync();
//Example of the data returned
/*
{
"LocationInfo":
{
"countryName": "United States",
"countryCode": "US",
"regionName": "Nevada",
"regionCode": "NV"
}
}
*/GetAdjustInfoAsync()
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:
AdjustInfo adjustInfo = WhoAmIService.GetAdjustInfoAsync();
//Example of the data returned
/*
{
"AdjustInfo": {
"AdId": "123",
"AttributionInfo": {
"Campaign": "test_campaign_roas"
}
}
}
*/GetPersistentIdAsync()
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:
string playerId = await WhoAmIService.GetPersistentIdAsync();GetPlatform()
GetPlatform()You can retrieve the current platform as a simple string using:
var platform = WhoAmIService.GetPlatform();android when running on Android
ios when running on iOS
null in other environments (e.g., Unity Editor, Windows, macOS)
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.
Last updated
Was this helpful?