Initial setup

Use the UnityServices.InitializeAsync() code at the start of your game to immediately upload initialized events with the Analytics SDK.

Note: Once the Analytics SDK has been added to a project the events record at any time. Custom fields, such as environment or userID are applied to all recorded events. This includes both before and after initializing the Unity Services.

You will need to check if any privacy consents are required using the AnalyticsService.Instance.CheckForRequiredConsents() method for events to be sent to the service. See Data Privacy for more information.

The example below shows a sample setup method that can be used before calling it into the Analytics SDK.

using UnityEngine;
using Unity.Services.Core;
using Unity.Services.Analytics;
using System.Collections.Generic;

public class InitWithDefault : MonoBehaviour
    async void Start()
            await UnityServices.InitializeAsync();
            List<string> consentIdentifiers = await AnalyticsService.Instance.CheckForRequiredConsents();
        catch (ConsentCheckException e)
          // Something went wrong when checking the GeoIP, check the e.Reason and handle appropriately.

This is the minimum amount of code required to initialize the SDK and to send events. It automatically sends the newPlayer event the first time the SDK is run, the gameStarted and clientDevice event each time the game runs, and the gameRunning event every minute. See Event Manager.

Every event that is sent makes the Analytics SDK automatically populate the userID, sessionID, eventTimestamp, eventUUID, platform and sdkVersion parameters in the code. The eventParams object triggers all parameters added to an event.

The order of the parameters in your JSON event are case sensitive and must match the type defined in the Event Manager. You can inspect the parameters that each event expects, their type, and any formatting in the Event Manager.

Next step: Check the Event Browser in the Dashboard to confirm your events are sent successfully. They take up to 10 minutes to appear.