Version: 2020.3
Unity Analytics DataPrivacy API
Analytics 指标、细分段和术语

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. Analytics 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 Analytics Data Privacy asset package from the Unity Asset Store. The Asset Store 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 button prefab, 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 Canvas GameObject in your Scene, you will need to add one. Unity automatically adds an EventSystem when you add the Canvas.
  2. Drag the DataPrivacyButton prefab from the Project window (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.

例如,以下脚本将打开 Player Data Privacy 页面来响应对游戏对象的单击:

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 指标、细分段和术语