Version: 2020.3
Language : English
Unity Analytics DataPrivacy API
Analytics Metrics, Segments, and Terminology

Unity Analytics and PIPL

China’s National People’s Congress has passed the Personal Information Protection Law (PIPL), to protect the data privacy of Chinese citizens. It is effective starting November 1st, 2021, and requires players in China to provide opt-in consent to their data being processed and opt-in consent to their data being transferred outside of China.

In order to comply with this legislation, Unity must block data collection from players in China until they provide their consent to both opt-ins. This means that from November 1st, 2021, data from players in China will cease to be processed. AnalyticsAbbreviation of Unity Analytics
See in Glossary
reporting and player engagement systems reliant on data will not be available for players in China.

The Analytics Data Privacy plugin contains relevant functionality to communicate the player’s consent for both opt-ins. As a developer, you will need to add the Data Privacy plugin to your game along with reference to the Unity Privacy Policy in order to utilize the consent flow. Once the consent flow is in place, data collection will resume for players in China who opt in.

Unity Analytics Data Privacy plugin

The Unity Analytics Data Privacy plugin gives your players control over the SDK’s data collection. This plugin is part of the Unity Analytics library package. You can use the Package Manager in the Unity Editor (Window > Package Manager) to double-check that the package is enabled in a project.

The plugin does not support the following platforms:

  • Linux
  • Windows Phone
  • Tizen
  • Apple TV
  • Blackberry

Note: For versions of Unity prior to 2018.3, you must use the Unity AnalyticsA data platform that provides analytics for your Unity game. More info
See in Glossary
Data Privacy 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, with the .unitypackage extension. Asset packages are a handy way of sharing and re-using Unity projects and collections of assets. More info
See in Glossary
from the Unity Asset Store. 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
version can be used with Unity 4.7, 5.1+, 2017.1+, 2018.1, and 2018.2.

Presenting consent flows to the player

The Data Privacy plugin includes a Unity UI(User Interface) Allows a user to interact with your application. More info
See in Glossary
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
, which you can place in a suitable location of your user interface. When a player clicks this button, it opens the Player Data Privacy page in a web browser where the player can opt in to the following consents:

1. Consent to collect data for analytics.
2. Consent to transfer data outside of mainland China.

Developers can also provide their own user interfaces and open the Player Data Privacy page using the data privacy API.

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.

Implementing the Unity solution

To implement the Data Privacy plugin-provided UI button:

  1. If you do not already have a 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
    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 your 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
    , you will need to add one. Unity automatically adds an EventSystem when you add the Canvas.
  2. Drag the DataPrivacyButton prefab from the Project windowA window that shows the contents of your Assets folder (Project tab) More info
    See in Glossary
    (in the Packages/Analytics Library/DataPrivacy folder) to the Canvas GameObject in your Scene.
  3. Adjust the position, graphics, and text of the button as needed.
  4. The button is already connected to the data privacy API, so that when a player located in China clicks on it the player’s personal data management page will open in a web browser.

Note: The version of the button prefab under the Packages folder is read-only. You can make changes to the instance of the button in the Scene hierarchy, but you cannot save those changes back to the original prefab.

Implementing a custom solution

If you use a custom interface button, you can request the URL of the user’s data opt-in page, then open that URL in a browser or web view:

  1. Create a UI component that informs the player of their ability to opt-in to data collection and transfer. Note that the Data Privacy plugin includes an icon in the Packages/Analytics Library/DataPrivacy folder. Unity encourages you to use this icon on your data privacy prompt to provide a consistent visual cue for players encountering data privacy controls in Unity games.
  2. When the player elects to opt in or out, call the DataPrivacy.FetchPrivacyUrl() method. This takes an Action<string> object that it invokes when the network request completes. You can optionally pass in a second Action<string> function to handle cases where the network request fails.
  3. In your handler for the FetchPrivacyUrl() request, use the Application.OpenURL() method to open the URL 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.GetMouseButtonUp(0)){
            OpenDataURL();
        }
    }
}

See documentation on the Unity Analytics DataPrivacy API for more information.

Unity Analytics DataPrivacy API
Analytics Metrics, Segments, and Terminology