Legacy Documentation: Version 5.1
Monetization (recommended)
User Attributes (optional)

Custom Events (optional)

Unity Analytics allows you to track specific events within your game. By configuring a series of Custom Events within your game, you can create your own Funnel Analysis to observe your players’ game behavior. Good places to put custom events include: milestones, new levels, scene transitions, etc.

In addition to tracking custom events, Unity Analytics also allows you to pass in custom dimensions (dictionary) relating to the event. These custom dimensions are primarily useful to know additional specifications about the user at the time the custom event was reached.

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

  Analytics.CustomEvent(string customEventName,
  IDictionary<string, object> eventData);
Name Type Description
customEventName string Name of custom event. Name cannot include the prefix “unity.” - This is a reserved keyword.
Dictionary dictionary Additional parameters sent to Unity Analytics at the time the custom event was triggered. Dictionary key cannot include the prefix “unity.” - This is a reserved keyword.

A few considerations with regards to the custom events:

  • Default limit of 10 parameters per custom event.
    • If there are more parameters passed, the call will fail with a return value of AnalyticsResult.TooManyItems
  • Default limit of 500 characters for the dictionary content.
    • If more than 500 characters are passed, the call will fail with return value of AnalyticsResult.SizeLimitReached
  • Default limit of 100 custom events per hour, per user.
    • If more than 100 events per hour are called, the call will fail with return value of AnalyticsResult.TooManyRequests
  • Consider how parameters are parsed by the Analytics system.
    • All numbers, ints, floats, etc., even if sent as strings, are parsed as numbers.
    • Only strings and Booleans are considered ‘categorizable’.
    • Consequently, if you want something to be summed or averaged, send it as a number (e.g., 51 or ‘51’). If you want it to be categorized, as you would with a level or option, make sure it will parse as a string (e.g., ‘Level51’).

In the example below we are interested in knowing what our user had in their inventory at the time they reached the Game Over scene of our game.

// Reference the Collections Generic namespace
  using System.Collections.Generic;

  int totalPotions = 5;
  int totalCoins = 100;
  string weaponID = "Weapon_102";
  Analytics.CustomEvent("gameOver", new Dictionary<string, object>
  {
    { "potions", totalPotions },
    { "coins", totalCoins },
    { "activeWeapon", weaponID }
  });

Validate Custom Events (optional)

The Unity Editor can act as a test environment to validate the Unity Analytics integration. This means that it is not required that you build and publish your game in order to validate the Basic Integration.

Validate Your Integration

To send test data to our servers and validate your integration, simply play your game by pressing the Play button.

Monetization (recommended)
User Attributes (optional)