Version: 2018.2 (switch to 2018.3b or 2017.4)
COPPA Compliance
Unity Analytics DataPrivacy API
Other Versions

Unity Analytics and the EU General Data Protection Regulation (GDPR)

The General Data Protection Regulation (GDPR) is a European Union law regulating the data privacy of EU citizens.

Maintaining compliance with GDPR when you use Unity AnalyticsA data platform that provides analytics for your Unity game. More info
See in Glossary
is a shared responsibility. Unity collects data to help you improve the player experience with ads and gameplay. Some of that data includes personally identifiable information (PII) regulated under GDPR. Unity provides the tools to allow a player to opt out of the PII collection, and to manage the personal data that Unity collects about them, as required by the GDPR. Your responsibilities include adding an opt-out button to your ads, and providing a link to Unity’s privacy policy from your own privacy policy.

When your app uses use Unity Ads, Unity displays a notice to the player the first time an ad is shown on their phone, giving them the option to opt in or out of personally identifiable information collection. Subsequent ads also display a button that users can use to manage their data privacy options. For more information about GDPR and the Unity Ads SDK, see Unity Ads Knowledge Base: GDPR Compliance.

If you use both Unity Ads and Analytics, the Unity Ads opt-out mechanism applies to both services.

If you do not use Unity Ads, but do use other Unity services, such as Unity AnalyticsSee Analytics More info
See in Glossary
, IAP, Multiplayer, or Performance Reporting, then you must use the Unity Analytics Data Privacy plug-inA set of code created outside of Unity that creates functionality in Unity. There are two kinds of plug-ins you can use in Unity: Managed plug-ins (managed .NET assemblies created with tools like Visual Studio) and Native plug-ins (platform-specific native code libraries). More info
See in Glossary
to provide an opt-out choice to your players. The plug-in provides a button you can add to your game that opens a Unity web page where players can manage their privacy settings. Players manage their preferences on a per-game, per-device basis. Unity Analytics does not track whether the same player plays more than one game made with Unity, or plays the same game on multiple devices.

The above options cover any data collected by Unity for customizing Ads and player services. However, if you collect personally identifiable information data on your own, you are responsible for protecting and managing that data.

Best practices:

  • Solicit your own legal advice. Nothing in this document should be construed as legal advice.

  • Read and understand the Data Processing Addendum (DPA) [PDF]

  • List Unity as a third-party which collects data in your privacy policy, and include a link to Unity’s privacy policy in your privacy policy.

  • Do not send personally identifiable information to Unity Analytics in Standard or Custom Events.

  • Do not use the Analytics.SetUserGender() or Analytics.SetUserBirthYear() to send gender and age information to Unity Analytics. These APIs are deprecated.

Using the Unity Analytics Data Privacy Plug-in

You can obtain the Unity Analytics Data Privacy plug-in from the Unity Asset Store. The plug-in is available for Unity versions:

  • 4.7
  • 5.1+
  • 2017.1+
  • 2018.1+

The plug-in does not support the following platforms:

  • Linux
  • Windows Phone
  • Universal Windows PlatformAn IAP feature that supports Microsoft’s In App Purchase simulator, which allows you to test IAP purchase flows on devices before publishing your application. More info
    See in Glossary
    (UWP) prior to Unity 5.5
  • Tizen
  • Apple TV
  • Blackberry

The Unity Analytics service now deletes personally identifiable information sent from games running on those platforms automatically. Contact DPO@unity3d.com if you have questions.

If your game displays ads from the Unity Ad network, the Unity Ads SDK already displays a data collection opt-out choice to the player, and configures Unity Analytics based on the player’s data privacy choice. You only need to use the Unity Analytics Data Privacy plug-in when you do not use the Unity Ads service.

Configuring Analytics Data Privacy in Unity

If you do not use Unity Ads, then you can integrate the Unity Analytics Data Privacy plug-in, which gives your players control over Unity Analytics data collection.

To integrate the plug-in:

  1. Import the Unity Analytics Data Privacy AssetAny media or data that can be used in your game or Project. An asset may come from a file created outside of Unity, such as a 3D model, an audio file or an image. You can also create some asset types in Unity, such as an Animator Controller, an Audio Mixer or a Render Texture. More info
    See in Glossary
    package into your Project.

  2. Provide an opt-out choice to the player using a button or other UI(User Interface) Allows a user to interact with your application. More info
    See in Glossary
    control.

The Unity Analytics Data Privacy plug-in contains code that automatically queries the Unity Analytics Service to determine the opt-out status of the current player. The plug-in then configures Unity Analytics based on the player’s preferences. The plug-in also includes a Unity UI button prefabAn asset type that allows you to store a GameObject complete with components and properties. The prefab acts as a template from which you can create new object instances in the scene. More info
See in Glossary
. This button opens a player’s personal data privacy page where they can opt-out of Unity’s data collection and view the data that Unity has collected in the past.

Important: If a player has a browser pop-up blocker enabled, their browser can prevent the data privacy page from opening. Some browsers note that a page has been blocked, but others provide no notice at all. Consider adding a message in your user interface that warns players that a pop-up blocker might prevent the page from opening.

See Unity Analytics DataPrivacy API for more information.

Importing the Unity Analytics Data Privacy Plug-in into a project

To import the plug-in into your project:

  1. Go to the Unity Analytics Data Privacy plug-in page on the Unity Asset Store.

  2. Click the Add to My Assets button on the page.

  3. In your Unity project, open the Asset StoreA growing library of free and commercial assets created by Unity and members of the community. Offers a wide variety of assets, from textures, models and animations to whole Project examples, tutorials and Editor extensions. More info
    See in Glossary
    window (menu: Window > General > Asset Store).

  4. Click the Downloads icon at the top of the window.

  5. Select My Purchased.

  6. Click the Download button for the Unity Analytics Data Opt-Out Plug-in.

  7. On the Import Unity Package window, click Import.

Providing the opt-out choice to the player

The plug-in includes a Unity UI button prefab. When a player clicks this button, the Player Data Privacy page opens in a web browser. You can also provide your own user interface and open the Data Privacy page manually.

Method 1: Using Unity UI

  1. Import the Asset packageA collection of files and data from Unity Projects, or elements of Projects, which are compressed and stored in one file, similar to Zip files. Packages are a handy way of sharing and re-using Unity Projects and collections of assets. More info
    See in Glossary
    into your project.

  2. If you are building your project with Unity 5.1 or earlier, you must call DataPrivacy.Initialize(). Newer versions of Unity call Initialize() call automatically.

  3. If you do not already have a Canvas GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
    See in Glossary
    in the SceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
    See in Glossary
    , add one. Unity automatically adds an EventSystem when you add the Canvas.

  4. Drag the DataPrivacyButton prefab to the CanvasThe area that contains all UI elements in a scene. The Canvas area is shown as a rectangle in the Scene View. More info
    See in Glossary
    GameObject in the Scene. Find the prefab in the Project window, in the DataPrivacy/Runtime folder.

  5. Adjust the position, graphics, and text of the button to suit.

  6. The button is already connected to the Data Privacy API, so that it opens the player’s personal data management page when the player clicks it. The page opens in a web browser.

Method 2: Using you own UI

To use your own user interface for the button, you can request the URL of the user’s data opt-out page and then open that URL in a browser or web view:

  1. Import the Asset package into your project.

  2. Create your own UI control that informs the player of their ability to opt-out of data collection.

    Note: The Data Privacy plug-in includes an icon in the DataPrivacy/Runtime folder. Unity encourages you to use this icon on your data privacy button (or similar control) to provide a consistent graphical cue to players encountering data privacy controls in Unity games.

  3. If you are building your project with Unity 5.1 or earlier, you must call DataPrivacy.Initialize(). Newer versions of Unity call Initialize() automatically.

  4. In response to the player’s click or interaction with this control, call the DataPrivacy.FetchPrivacyUrl() function. This function takes an Action<string> object that invokes when the network request completes. You can optionally pass in a second Action<string> function to handle the failure case.

  5. In your handler for the FetchPrivacyUrl() request, use Application.OpenURL() to open the URL received in a browser.

For example, the following script opens the Player Data Privacy page in response to a click on a GameObject:

using System;
using UnityEngine;
using UnityEngine.Analytics;
    
public class OptOutHandler : MonoBehaviour {

    static void OnFailure(string reason)
    {
        Debug.LogWarning(String.Format("Failed to get data privacy page URL: {0}", reason));
    }

    void OnURLReceived(string url)
    {
        Application.OpenURL(url);
    }

    public void OpenDataURL()
    {
        DataPrivacy.FetchPrivacyUrl(OnURLReceived, OnFailure);
    }
    
    void OnMouseOver(){
        if(Input.GetMouseButtonDown(0)){
            OpenDataURL();
        }
    }
}

Using the Data Privacy plug-in with older versions of Unity and Unity Analytics

Before Unity 5.2, Unity provided Analytics support through a Unity Asset Store asset package. You can use the Data Privacy plug-in with these older versions of Unity Analytics, but you must initialize the privacy plug-in before calling any of its other functions (and before your players have a chance to click the data privacy button). The best place to initialize the plug-in is right after you call UnityAnalytics.StartSDK() to initialize the Analytics plug-in:

using UnityEngine;
using UnityEngine.Cloud.Analytics;
using UnityEngine.Analytics;

public class UnityAnalyticsIntegration : MonoBehaviour {

    void Start () {
        const string projectId = "SAMPLE-UNITY-PROJECT-ID";
        UnityAnalytics.StartSDK (projectId);
        DataPrivacy.Initialize ();
    }
}

Note: Unity 5.2 and later versions call DataPrivacy.Initialize() automatically. You do not need to call the function yourself unless you are using the Asset Store package for Analytics support.

See Unity Analytics DataPrivacy API for more information.


  • 2018–05–18 Page published with limited editorial review
  • Removed Editor menu command for inserting the Data Privacy button. Added the Data Privacy Button prefab.
  • New feature in Unity 2018.1

Did you find this page useful? Please give it a rating:

COPPA Compliance
Unity Analytics DataPrivacy API