Custom user ID support

Use the custom user ID feature on Analytics events sent through the Analytics SDK.

You have the option to set the Analytics user ID at any point during the application lifecycle using the core UnityServices package. Use the code below:

using Unity.Services.Core;

void Start()
{
	UnityServices.ExternalUserId = "some-user-id";
}

Setting a custom user ID is completely optional. When not set, the SDK generates a user ID as it does with existing behavior. If a custom user ID is set while the Legacy Analytics is on, the result is a double count. Turn off Legacy Analytics before using a custom user ID.

Any events recorded after you set a custom user ID uses the given value. Events recorded previously are not updated and retain the original value. Note that changing the user ID contributes a new user to metrics such as Monthly Active User counts, which might affect billing.

Note that the SDK doesn't save the external user ID value. If you want to keep a consistent custom ID for a given user over time, you need to save it manually (for example using PlayerPrefs) and set it each time your app starts.

  • If you want Unity to generate user IDs for Analytics, no action is required.
  • If you want to use a custom ID to match with external data (for example, other analytics sources) then you need to set the ExternalUserId when initializing UnityServices.

Use ExternalUserId to maintain consistent identifiers for your player base across different systems and ensure your internal data is joined to the data provided by the Analytics platform.

GetAnalyticsUserID()

AnalyticsService.Instance.GetAnalyticsUserID()

This enables you to retrieve the ID currently being used for events: either the custom ID that was set or the generated installation ID.