Documentation

Support

Analytics

Analytics

Get started with Analytics

Follow this workflow to install the Analytics SDK, configure data collection, and begin tracking player behavior.
Read time 3 minutesLast updated a month ago

To start using Analytics, perform the following actions:

Prerequisites

Before you begin, make sure you meet the following requirements:
  • You've completed the steps outlined in Get started with UGS.
  • You're using a project with Unity 2021.3 or above.

Install the Analytics package

To begin using the Analytics SDK, install the Analytics package:
  1. In the Unity Editor, navigate to Window > Package Manager.
  2. Select Unity Registry.
  3. Search for Analytics (or com.unity.services.analytics).
  4. Select the package, then select Install.
You can now start using the Analytics SDK.

Manually start the Analytics SDK to begin collecting data

The process for enabling the Analytics SDK to collect data differs depending on which version of Unity and the Analytics SDK you use. To find the setup steps for the versions you use, refer to their respective section:

Unity 6.2 and later with Analytics SDK 6.1 and later

To enable the Analytics SDK to collect data in Unity 6.2 and later with Analytics SDK 6.1 and later, do the following:
  1. Call the
    UnityServices.InitializeAsync()
    function at the start of your game to initialize the Analytics SDK and any other UGS SDKs that you use.
  2. After you confirm that you have player consent, use the Developer Data framework
    EndUserConsent.SetConsentState(...)
    method to set
    AnalyticsIntent
    to
    Granted
    .
The following code block provides an example implementation:
using UnityEngine.UnityConsent;EndUserConsent.SetConsentState(new ConsentState { AnalyticsIntent = ConsentStatus.Granted, AdsIntent = ConsentStatus.Denied});
For the Analytics SDK to collect data, you must first confirm user consent for Analytics. In Unity 6.2 and later, the Developer Data framework controls Analytics SDK data collection according to the player consent status:
  • If consent is granted after initialization, the SDK begins collecting data immediately.
  • If consent was granted in a previous session, the SDK begins collecting data during Unity Services initialization.
  • If consent is denied at any time, the SDK ceases collecting data.
To delete player data, deny consent using the
EndUserConsent.SetConsentState(...)
and then call the
AnalyticsService.Instance.RequestDataDeletion()
method. If you request data deletion while consent is still granted, the SDK throws an exception and does not make the request.
For more information about managing privacy and obtaining player consent for data collection with the Developer Data framework, refer to User consent.

Unity 6.1 and earlier, or Analytics SDK 6.0 and earlier

To enable the Analytics SDK to collect data in Unity 6.1 and earlier, or using Analytics SDK 6.0 and earlier, do the following:
  1. Call the
    UnityServices.InitializeAsync()
    function at the start of your game to initialize the Analytics SDK and any other UGS SDKs that you are using.
  2. After you confirm that you have player consent, call
    AnalyticsService.Instance.StartDataCollection()
    to enable data collection.
For the SDK to collect data, you must confirm that the user has consented to the use of Analytics. For more information about managing privacy and obtaining player consent, refer to Manage data privacy with the SDK.

Change player consent status

You can change a player's consent status using the following methods:
  • To opt a player out of data collection, call the
    StopDataCollection()
    method.
  • To delete player data, call the
    RequestDataDeletion()
    method.
  • To opt a player in for data collection (again), call the
    StartDataCollection()
    method.

Set up Analytics

To set up and manage Analytics from the Unity Dashboard, do the following:
  1. In the Unity Dashboard, select the Products tab from the sidebar.
  2. Under Gaming Services, go to Analytics and select Launch.
When you launch Analytics for the first time, it appears in the Shortcuts section on the sidebar and opens the Game Performance page.

Next steps

After you enable data collection, the SDK begins collecting events and uploading them at a regular cadence of every 60 seconds while your game is running. The SDK automatically records some events, enabling you to directly access Analytics in the Unity Dashboard for data analysis. For a list of which events are sent automatically and which require manual configuration, refer to Standard Events. To learn how to build and record your own events, refer to the following tutorials: