Version: 2017.4
Analytics 指标、细分段和术语

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

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

For general information about Unity and GDPR, see

For Unity’s own privacy policy, see

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 game play. Some of that data includes personally identifiable information (PII) regulated under GDPR. Unity provides tools a player can use to opt-out of the PII collection and to manage the personal data collected by Unity as required by the GDPR. Your responsibilities include showing an opt-out button and providing a link to Unity’s privacy policy from your own privacy policy.

If you 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 opt-out mechanism provided by Unity Ads applies to both services.

If you do not use Unity Ads, but do use other Unity services, such as Unity Analytics, IAP, Multiplayer, or Performance Reporting, then you must use the Unity Analytics Data Privacy plugin to provide an opt-out choice to your players. The plugin 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.

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

Best Practices:

Using the Unity Analytics Data Privacy Plugin

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

  • 4.7
  • 5.1+
  • 2017.1+
  • 2018.1+

The plugin does not support the following platforms: 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.

Note: that if your game displays ads from the Unity Ad network, the Unity Ads SDK already handles showing 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 plugin 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 plugin, which gives your players control over Unity Analytics data collection.

To integrate the plugin:

  1. Import the Unity Analytics Data Privacy asset package into your project.

  2. Provide an opt-out choice to the player using a button or other UI control.

The Unity Analytics Data Privacy plugin contains code that automatically queries the Unity Analytics Service to determine the opt-out status of the current player. The plugin then configures Unity Analytics based on the player’s preferences. The plugin 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.

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 can prevent the page from opening.

Importing the Unity Analytics Data Privacy Plugin in a project

To import the plugin into your project:

  1. Go to the Unity Analytics Data Privacy plugin 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 Store window (menu: Window > 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 Plugin.

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

Providing the opt-out choice to the player

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

方法 1:使用 Unity UI

  1. Import the Asset package into your project.

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

  3. If you do not already have a Canvas object in the scene, add one. (An EventSystem is also required and should be added automatically when you add the Canvas.)

  4. Drag the DataPrivacyButton prefab to the Canvas object 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 hooked up to the Data Privacy API so that it opens the player’s personal data management page when clicked. The page opens in a web browser.

方法 2:使用您自己的 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 webview:

  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(). (Initialize() is called automatically on newer versions of Unity.)

  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 is invoked 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, open the URL received in a browser. You can do this with Application.OpenURL().

例如,以下脚本将打开 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 plugin 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 plugin with these older versions of Unity Analytics, but you must initialize the privacy plugin 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 plugin is right after you call UnityAnalytics.StartSDK() to initialize the Analytics plugin:

    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: DataPrivacy.Initialize() is called automatically on Unity 5.2 or later. You do not need to call the function yourself unless you are using the Asset Store package for Analytics support.

Unity Analytics Data Privacy API

CLASS DataPrivacy

The DataPrivacy class configures the Unity Analytics service based on the player’s data privacy management choices.

NAMESPACE: UnityEngine.Analytics

    public class DataPrivacy

The DataPrivacy class automatically fetches the player’s data privacy status and configures the Analytics service accordingly.

使用 FetchPrivacyUrl() 函数来获取玩家个人数据管理页面的 URL。打开该 URL 即可为玩家提供管理其数据隐私设置的选项。


准备 Data Privacy API 以供使用。


    public static void Initialize()


This function creates a hidden GameObject and adds an instance of the DataPrivacy class to it as a component.

On Unity 5.1 or earlier, call Initialize() early in your application startup, ideally, right after you call UnityAnalytics.StartSDK (projectId). Newer versions of Unity call Initialize() automatically.


Fetches the player’s current opt-out status and configures the Unity Analytics service.


    public static void FetchOptOutStatus(Action<bool> optOutAction = null)


  • [optional] Action<bool> optOutAction — The Action object to invoke when Unity has fetched the player’s opt-out status. The boolean parameter passed to your Action is true if the player has opted out of personal data collection and false, otherwise.


The function configures the Analytics service as appropriate for the player’s data collection choices. The status is cached for use when the player’s computer or device is offline.

FetchOptOutStatus() is called automatically when your game launches. You should also call the function when the player returns to your game after you open their data privacy management URL to immediately apply any changes they made while on that page.

You can also use FetchOptOutStatus() to get a player’s opt-out choice by passing an Action<bool> function parameter. The plugin invokes the optOutAction function you provide when the network fetch request is complete. The boolean argument passed to your action is true when the player has opted out and false, otherwise. If the network request for the player’s status fails, your optOutAction function is called with the cached value (or false, if the status has never been set).

    void OnOptOutStatus(bool optOut)
            Debug.Log("Player has opted-out of personal data collection.");

    // ...

FetchPrivacyUrl(Action<String>, Action<String>)

获取玩家个人数据管理页面的 URL。


    public static void FetchPrivacyUrl(Action<string> success, Action<string> failure = null)


  • Action<String> success — 成功获取该 URL 时要调用的 Action 对象。传递给 Action 的字符串包含该 URL。

  • [optional] Action<String> failure — Unity 无法获取该 URL 时要调用的 Action 对象。传递给 Action 的字符串包含失败原因。


Open the URL passed to your success function in a browser or webview to give the player the opportunity to manage their data protection options. You can use Application.OpenURL() to open the page.

该 URL 在短时间内有效。务必在打开 URL 之前即时获取 URL。

Call FetchOptOutStatus() after the player returns to your game to apply any changes immediately. Otherwise, any changes to data collection are applied the next time the player launches your game.

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