How to track metrics on your game's levels using Unity Analytics

Here I show how and why you might use Unity analytics in your game.

It has never been easier to get insightful data from your players and beta testers for your game. It’s so easy, you’d be foolish not to implement it - it will take you less than a day!

At Squingle Studios, we use Analytics not only to track the number of users per day/month, but also to track which levels players give up at, how users perform in levels, where they die most frequently, and other vital information.

By sending data points with multiple parameters, you can then plot parameters against each other, giving deep insights to help improve your game.

Below shows the Unity Analytics Dashboard, where I’m plotting how many stars, items, deaths, and the completion time averages of each level. Those levels where people are dying a lot may need adjusting.

Below is some data from the Beta of our psychedelic casual VR game Squingle. We’d love for you to get involved and join the Beta here! Please follow us:

A spiraling psychedelic adventure – Squingle is a game of precision, rhythm and satisfaction. Guide revolving orbs through pearlescent puzzles that react to you like liquid crystal – but be careful! Navigate complex geometries and avoid a choreograp…

A spiraling psychedelic adventure – Squingle is a game of precision, rhythm and satisfaction. Guide revolving orbs through pearlescent puzzles that react to you like liquid crystal – but be careful! Navigate complex geometries and avoid a choreography of obstacles along the way.

unity analytics.jpg

I can also see the ‘conversion rate’ of the rate of players going on to the each level.

unity analytics conversion.jpg
 

Setting up Unity Analytics

1) Open Unity

Make sure you are logged into your account (note you do not need a Unity Pro license to do this)

2) Enable Unity Analytics

Go to Window > General > Services (or Ctrl+0) to bring up the Services window. Then click on and enable ‘Analytics’! Hey presto - this is all you need to do to track daily and monthly users. You can then click the ‘go to dashboard’ to see analytics data for your game. Note that analytics data takes up to 12 hours to populate the dashboard after it has been sent from instances of your game (either in the editor or in builds) to the Unity Analytics server.

3) Create custom events

These can be used to track specific details of your game, such as deaths on each level. A (significant) limitation of Unity Analytics is that you can only send maximum of 100 bits of data per hour per user to the server. So send data at key events such as when a level is complete, which in my case happens about every 2 minutes or so.

Creating Custom Events

Sending data to Unity Analytics is as simple as calling the method in the class below. (Create new C# script called ‘UnityAnalyticsManager.cs’, add it to a GameObject.)

Here, the if-statement in the Update() method will trigger sending the ‘test_event’ to Unity Analytics when clicking the mouse in play mode. The result of the attempt to send the data, ‘analytics result’, will tell you if the data was send ‘Ok’ or may give an error, eg if not connected, or if you have sent too many events already (over 100 per hour).

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Analytics; //don't forget to include this!

public class UnityAnalyticsManager : MonoBehaviour
{
    public void TriggerTestAnalyticsEvent()
    {
        AnalyticsResult analytics_result = Analytics.CustomEvent("test_event");
        Debug.Log("Analytics result " + analytics_result);
    }
}
void Update()
{
    if (Input.GetMouseButtonDown(0))
    {
            TriggerTestAnalyticsEvent();
    }
}

Sending Events with Multiple Parameters

To be able to look at, for example, how many deaths someone made before they completed a level, we’ll need to send more detailed information with multiple parameters, such as ‘level number’, ‘number of deaths that level’ and probably, ‘game version number’ so we don’t muddle what data is coming from old beta versions of our game.

In the below, I’ve made the method a public static method, so I can easily call it from my game code with just UnityAnalyticsManager.LevelComplete([input parameters]); Be sure to put ‘using UnityEngine.Analytics;’ at the top, else you will get an error.

This method will achieve what we are looking for, and allow us to set up a ‘funnel’ on the Unity Analytics Dashboard to track how players perform on each level.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Analytics; //don't forget to include this!

public class UnityAnalyticsManager : MonoBehaviour
{
    public string game_version = "v0.2.3";

    public static void LevelComplete(int level, int deaths, int time, int stars)
    {
      //Unity Analytics is limited to a max 10 parameters per event.  Below I am using only 4. You can send an int, float, or string.
        Dictionary<string, object> analyticsData = new Dictionary<string, object>
            {
                {"Level", level },
                {"Deaths", deaths },
                {"Time", time },
                {"Stars", stars }
            };

        AnalyticsResult aa = Analytics.CustomEvent(("LevelComplete_" + game_version), analyticsData);

        Debug.Log("Analytics Result (level complete): " + aa);

    }
}

Setting Up on Unity Analytics

Go to the Unity Analytics Dashboard

In Unity, make sure you are logged on, then open Window > General > Services, then click ‘Analytics’ and then - assuming you have already enabled it - hit ‘go to dashboard’.

Create a funnel

A funnel is designed to track how many players fall off between each level. Most players you hope to complete level 1, then fewer will complete level 2, then less on 3 and so on. By looking at big jumps in how many players are progressing between levels, you can determine where the difficult places are.

You will need to wait up to 12 hours after you have sent your first custom events before they will show up so be patient and have faith. If your event was returning the console log message ‘Ok’ then it should come in due course.

On the dashboard (in the browser), go to ‘Funnel Analyzer’ on the left. Then ‘Create Funnel’. Add steps to the funnel for each level in your game - below you see the event ‘LevelComplete’ selected, and the parameter ‘level’ increasing each step. Unfortunately, you have to do this manually :(. I have added the version number ‘b2’ for ‘beta v2’ to the event name, but you could have put it as a parameter and added a condition to each step, if you want to differentiate data from different game versions.

funnel2.jpg

Look at your wonderful data

Once enough data has come in (remember it takes 12 hours!) you can start to do some analysis.

Conversion (player fall-off between levels)

Click on ‘Funnel Analyzer’ on the dashboard and click your funnel. It will show a graph of ‘conversion’ - the number of your players completing each level. Below shows that people gave up after 12 or so levels… :(. We will see why in the following sections.

funnel3.jpg

Deaths per level

Since we sent custom events with parameters such as ‘deaths’, ‘time’ and ‘stars’ we can look also at how people performed on each level. Here, it seems that my levels 12 and 13 caused 11 and 12 deaths on average - maybe that is why people gave up after that and stopped playing! Note that only one event per level per user is given here - which gives you an impression of how people do the first time only they complete each level.

funnel4.jpg

Time to complete each level

We can also see below that it took players progressively more time to complete levels, maxing out at 209 seconds on the last level before players quit. It goes to show - people have an attention span of about 3 minutes :P.

funnel5.jpg

Conclusions

We’ve highlighted how Unity Analytics can be used very easily to track number of users, progression through your game, and the reasons people might be giving up.

There are many other ways you can use the tool to do analysis, I’ve only focused on a simple use case here - but even this gives powerful insights. I recommend checking out other’s tutorials and youtube videos.

The existing system has some limitations. You can only send max 100 events per hour - so be sure not to dive head-long into setting up detailed events for every little player interaction.

Let me know via the contacts page or in comments below how you have been using Analytics, or if there is anything you feel I should add to this post to make it easier to understand.

Thanks! And do check out our indie VR project Squingle at Steam here!

Be transported on a rhythm puzzle journey in VR.  Visit our website: www.squingle.com

Be transported on a rhythm puzzle journey in VR. Visit our website: www.squingle.com