Manage data privacy with the SDK

Important: Unity Analytics requires you to implement a privacy solution separate from Unity Ads. If you're using both Unity Ads and Analytics, the Unity Ads opt-out mechanism does NOT apply to both services.

Analytics collects data to help you improve the player experience in your game. Some of that data includes personal data regulated under data privacy laws.

Some regions might require consent to collect personal data by law, while others might require end-user notice and the opportunity to opt-out. However, consent and opt-out requirements extend beyond these use cases and must be applied in any region that requires it. By using these functions, you take responsibility for providing this consent correctly and for all regions.

When a user does not consent to, or opts out of personal data collection and processing under a data privacy regulation (for example GDPR, CCPA, or PIPL), this prevents personal data from being collected about your users and may impact your analytics and key metrics.

For a full breakdown of your responsibilities, please see the privacy overview page.

Important: The Analytics SDK does not manage data privacy compliance in any way. You, the developer, are responsible for determining what data privacy legislation applies to the player and what consent is required before activating the SDK.

Start data collection

As of version 5.0.0, the Analytics SDK does not collect any personal data by default. The SDK initializes in a dormant state, in which it ignores all events. You are responsible for determining what data privacy legislation affects the player and when it is appropriate for you to enable data collection by the SDK (i.e. have the player’s consent for an opt-in legislation, or that the player has not denied consent for an opt-out legislation). If you are not using SDK version 5.0.0 or greater, it is strongly recommended that you upgrade as soon as possible.

Only once you've confirmed that you have the player's consent to collect data, you can activate the SDK by calling AnalyticsService.Instance.StartDataCollection().

If the player has denied or revoked their consent, you can avoid calling StartDataCollection and so leave the SDK inactive.

For specific information about how to start data collection in compliance with the two major kinds of legislation, see these pages:

The methods that the SDK offers to manage consent and privacy scenarios are shown in this diagram:

Privacy URL

If you need to present the user with Unity's privacy policy, the privacy URL is available in the SDK as the AnalyticsService.Instance.PrivacyUrl property. You can use this to open a browser window using this code:

Application.OpenURL(AnalyticsService.Instance.PrivacyUrl);

Opt out

If the user wants to opt out after data collection has been started, use using the AnalyticsService.Instance.StopDataCollection() method.

public void OptOut()
{
	AnalyticsService.Instance.StopDataCollection();
}

Data deletion

Call AnalyticsService.Instance.RequestDataDeletion() to request personal data deletion, which triggers a purge of user data from the server. This will also stop data collection if it has not already been stopped.

public void RequestDataDeletion()
{
	AnalyticsService.Instance.RequestDataDeletion();
}

If there is no internet connection when this request is made, the SDK reattempts the request at regular intervals until it is successful. It will remember this across app restarts using Unity's PlayerPrefs system, so be aware that using PlayerPrefs.DeleteAll() may disrupt this process.

Important: This functionality only applies to Analytics and the Push Notification Service. If you are using other services which collect app user personal data you will need to review those services' documentation for how they handle data deletion requests. To delete the player ID created by the Unity Authentication SDK (if enabled), please use the Authentication API.