Version: 2019.4
Custom Events
Analytics Event Tracker

Custom Event scripting

Note: Gaming Services Analytics is now available as a preview packageA preview package is in development and not yet ready for production. A package in preview might be at any stage of development, from the initial stages to near completion.
See in Glossary
. Gaming Services AnalyticsAbbreviation of Unity Analytics
See in Glossary
is an improved offering that allows you to easily understand game performance and player behaviors so you can make strategic decisions. Check out the documentation.

As an alternative to using the AnalyticsEventTracker component, you can send Custom Events directly via script by calling AnalyticsEvent.Custom:

// Reference the Unity Analytics namespace
using UnityEngine.Analytics;

//  Use this call for wherever a player triggers a custom event
AnalyticsEvent.Custom(string customEventName, IDictionary<string, object> eventData);

Analytics.CustomEvent Input Parameters

Name Type Description
customEventName string Name of the custom event. The name cannot include the prefix “unity”, which is reserved for internal Unity AnalyticsA data platform that provides analytics for your Unity game. More info
See in Glossary
events.
eventData dictionary Additional parameters sent to Unity Analytics at the time the custom event was triggered. eventData keys cannot include the prefix “unity”, which is reserved for internal Unity Analytics eventsEvents dispatched to the Analytics Service by instances of your applications. Analytics events contain the data that is processed and aggregated to provide insights into player behavior. More info
See in Glossary
.

The following example sends a Custom Event when a player finds a secret location in a level:

public void ReportSecretFound(int secretID){
    AnalyticsEvent.Custom("secret_found", new Dictionary<string, object>
    {
        { "secret_id", secretID },
        { "time_elapsed", Time.timeSinceLevelLoad }
    });
}

  • 2018–03–02 Page published

  • 2018–03–02 - Service compatible with Unity 5.2 onwards at this date but version compatibility may be subject to change

  • New feature in 5.2

  • Standard Events added as Unity package.

Custom Events
Analytics Event Tracker