Get started with Analytics
To start using Analytics, perform the following actions:
- Meet all the prerequisites.
- Install the Analytics package.
- Manually start the Analytics SDK to start collecting data.
- Set up Analytics.
Prerequisites
Before you continue, make sure you meet the following requirements:
- You have completed the steps outlined in Get started with UGS.
- You are using a project with Unity 2021.3 or above.
Note: Analytics is compatible with the following operating systems and platforms: iOS, Android, Windows, macOS, and WebGL.
Install the Analytics package
To begin using the Analytics SDK, install the Analytics package:
- In the Unity Editor, navigate to Window > Package Manager.
- Select Unity Registry.
- Search for Analytics (or com.unity.services.analytics).
- Select the package, then select Install.
You can now start using the Analytics SDK.
Collect data
To enable the Analytics SDK to collect data:
Unity 6.2 and later with Analytics SDK 6.1 and later
- 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. - Once you confirm you have player consent, use the Developer Data framework
EndUserConsent.SetConsentState(...)
method to setAnalyticsIntent
toGranted
. For more information, refer to Developer Data framework.
The Developer Data framework controls Analytics SDK data collection:
- 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.
Note: For the SDK to collect data, you must confirm user consent for Analytics. To learn about managing privacy and obtaining player consent, refer to User consent.
Unity 6.1 and earlier, or Analytics SDK 6.0 and earlier
- 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. - Once you confirm you have player consent, call
AnalyticsService.Instance.StartDataCollection()
to enable data collection.
Note: 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.
Important: You must call StartDataCollection()
at the start of each session to enable data collection. The SDK doesn’t track player consent status between sessions.
Set up Analytics
To set up and manage Analytics from the Unity Cloud Dashboard:
- Go to cloud.unity.com.
- Select + under Shortcuts in the left panel.
- Search for Analytics and select it to open Analytics. Analytics is now pinned under Shortcuts.
When you launch Analytics for the first time, it appears in the Shortcuts section on the sidebar and opens the Game Performance page.
Note: Only Organization Owners can sign up for Analytics.
Next steps
When you've enabled 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 events sent automatically versus those requiring manual configuration, refer to Standard Events.
Refer to the following tutorials to learn how to build and record your own events:
Note: To learn about how the SDK works, refer to SDK behavior.