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, refer to the Privacy overview.
Unity 6.2 and later with Analytics SDK 6.1 and later
Start data collection
In Unity 6.2 and later, the Developer Data framework's EndUserConsent
API controls the Analytics SDK. To start or stop data collection, use this API to set the AnalyticsIntent
consent to Granted
or Revoked
.
For specific information about granting consent with the EndUserConsent
API, refer to Developer Data framework.
Data deletion
Call AnalyticsService.Instance.RequestDataDeletion()
to request personal data deletion, which triggers a purge of user data from the server. In order to make a data deletion request, you must first deny consent using the EndUserConsent
API.
public void RequestDataDeletion()
{
ConsentState consentState = EndUserConsent.GetConsentState();
consentState.AnalyticsIntent = ConsentStatus.Denied;
EndUserConsent.SetConsentState(consentState);
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 application 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 application 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), use the Authentication API.
Unity 6.1 and earlier, or Analytics SDK 6.0 and earlier
Start data collection
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.
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 following diagrams display the methods that the SDK offers to manage consent and privacy scenarios:
If the user wants to opt out after data collection has been started, use 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 application 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 application 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), use the Authentication API.
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. Use the following code to open a browser window with Unity's privacy policy:
Application.OpenURL(AnalyticsService.Instance.PrivacyUrl);