Version: 2018.2
Unity Analytics DataPrivacy API

Unity Analytics 和欧盟一般数据保护条例 (GDPR)

一般数据保护条例 (General Data Protection Regulation, GDPR) 是欧盟关于规范欧盟公民数据隐私的法律。

Maintaining compliance with GDPR when you use Unity Analytics 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.

如果您同时使用 Unity Ads 和 Analytics,则 Unity Ads 的选择退出机制适用于这两种服务。

如果您不使用 Unity Ads,但使用其他 Unity 服务,例如 Unity Analytics、IAP、Multiplayer 或 Performance Reporting,则必须使用 Unity Analytics Data Privacy 插件为玩家提供选择退出选项。该插件提供了一个可添加到游戏中的按钮,此按钮可打开 Unity 网页,让玩家可在其中管理其隐私设置。玩家根据每个设备管理每个游戏的偏好设置。Unity Analytics 不会跟踪同一玩家是否在玩使用 Unity 制作的多个游戏或者在多个设备上玩同一个游戏。

以上选项涵盖 Unity 收集的用于定制广告和玩家服务的所有数据。但是,如果您自行收集涉及个人身份信息的数据,您有责任保护和管理该数据。


  • 自行征求法律意见。本文档中的任何内容均不应视为法律意见。

  • 阅读并理解数据处理附录 (Data Processing Addendum, DPA) [PDF]

  • 在您的隐私政策中将 Unity 列为收集数据的第三方,并在您的隐私政策中包含 Unity 隐私政策的链接。

  • 请勿在标准或自定义事件中向 Unity Analytics 发送涉及个人身份的信息。

  • 请勿使用 Analytics.SetUserGender()Analytics.SetUserBirthYear() 将性别和年龄信息发送到 Unity Analytics。这些 API 已弃用。

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+


  • Linux
  • Windows Phone
  • Universal Windows Platform (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 if you have questions.

如果您的游戏显示来自 Unity Ads 网络的广告,则 Unity Ads SDK 已经向玩家显示数据收集选择退出选项,并已根据玩家的数据隐私选项配置 Unity Analytics。如果不使用 Unity Ads 服务,您只需要使用 Unity Analytics Data Privacy 插件。

在 Unity 中配置 Analytics 数据隐私

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 Asset package into your Project.

2.使用按钮或其他 UI 控件为玩家提供选择退出选项。

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 prefab. 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.


想了解更多相关信息,请参阅 Unity Analytics DataPrivacy API

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.单击该页面上的 Add to My Assets 按钮。

  1. In your Unity project, open the Asset Store window (menu: Window > General > Asset Store).

4.单击窗口顶部的 Downloads 图标。

5.选择 My Purchased

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

7.在 Import Unity Package 窗口上,单击 Import


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.

方法 1:使用 Unity UI


  1. 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.

  2. If you do not already have a Canvas GameObject in the Scene, add one. Unity automatically adds an EventSystem when you add the Canvas.

  3. Drag the DataPrivacyButton prefab to the Canvas GameObject in the Scene. Find the prefab in the Project window, in the DataPrivacy/Runtime folder.


  1. 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.

方法 2:使用您自己的 UI

要使用您自己的用户界面创建该按钮,您可以请求用户数据选择退出页面的 URL,然后在浏览器或 Web 视图中打开该 URL:


2.创建您自己的 UI 控件,告知玩家可以选择退出数据收集。

**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.
  1. If you are building your project with Unity 5.1 or earlier, you must call DataPrivacy.Initialize(). Newer versions of Unity call Initialize() automatically.

  2. 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.

  3. In your handler for the FetchPrivacyUrl() request, use Application.OpenURL() to open the URL received 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)

    public void OpenDataURL()
        DataPrivacy.FetchPrivacyUrl(OnURLReceived, OnFailure);
    void OnMouseOver(){

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.

想了解更多相关信息,请参阅 Unity Analytics DataPrivacy API

  • 2018–05–18 页面已发布并只进行了有限的编辑审查
  • 删除了用于插入 Data Privacy 按钮的 Editor 菜单命令。添加了 Data Privacy Button 预制件。
  • Unity 2018.1 中的新功能
Unity Analytics DataPrivacy API