How to use Analytics for sending High Score?

I want to see the High score scored by players, how do I achieve this using custom events? High Score is a float (like 10, 200.5 or 480.35).

@surajsirohi1008

Unity Analytics is designed for aggregated data. So it won’t be possible to see the score of an individual player on the Analytics dashboard. (You can use our Raw Data Export to see this data if you are a Pro subscriber.)

However, if you are interested in seeing aggregated data, such as the average score per player, then you can use the following Custom Event as an example:

using UnityEngine;
using UnityEngine.Analytics;
using System.Collections.Generic;

public class TrackHighScore : MonoBehaviour {
    public void SendHighScore(float highScore)
    {
        // Create dictionary to store you event data
        Dictionary<string, object> data = new Dictionary<string, object>();

        //Add the high score to your event data
        data.Add("high_score", highScore);

        // The name of the event that you will send
        string eventName = "High Score";

        //Send the event. Also get the result, so we can make sure it sent correctly
        AnalyticsResult result = Analytics.CustomEvent(eventName, data);
        //Debug.Log(result);
    }

    //This will only be useful if you have a small number of levels
    public void SendHighScorePerLevel(float highScore, int level)
    {
        // Create dictionary to store you event data
        Dictionary<string, object> data = new Dictionary<string, object>();

        //Add the high score to your event data
        data.Add("high_score", highScore);

        // The name of the event that you will send
        string eventName = "Level - " + level;

        //Send the event. Also get the result, so we can make sure it sent correctly
        AnalyticsResult result = Analytics.CustomEvent(eventName, data);
        //Debug.Log(result);
    }
}
2 Likes

Thanks! This will do.

I used Debug.Log(result);

and in the console I get “TooManyRequests”.

What did I do wrong? There is nothing in the Validator.

The Validator was down for a bit this morning, but I think that is unrelated to the problem you are seeing.

Getting a result of “TooManyRequests” means that you have gone over the hourly limit of events. By default, apps can only send 100 events per device per hour.

You can find the full list of possible results in the Scripting Reference:
https://docs.unity3d.com/ScriptReference/Analytics.AnalyticsResult.html

One common cause of hitting this limit too quickly is putting your Analytics calls within an Update method. How are you sending your events and how often are you sending them?

Yes it was in the update function, fixed that. I created a new funnel but when I hit save, it doesn’t save.

Does the page give you any error messages?

No, I click save and it takes me back to create funnel page. How many steps can I add?

I will have to check on the exact limit, but it is possible to make a pretty big funnel (100+ steps). How many steps are you trying to add?

Would you be able to share the console output when this happens? (You can hit F12 in Chrome or Firefox and click on the Console tab).

If possible, could you share a screenshot or video of what is displayed there before, during, and after you click the save button.

I’m adding 20 steps.

This is what I get after clicking on save funnel:

3394448--266953--Screen Shot 2018-02-17 at 11.50.38 AM.png

Or

Or better you can look at my recording:

https://drive.google.com/file/d/1j-ny3sbjPr-qlOAaOyPtQPFVYyW2Vt6W/view?usp=sharing

@surajsirohi1008

Which browser are you using? And do you have any browser extensions that may interfere with javascript running on the page (ad blocker, noscript, etc.)?

@surajsirohi1008

Actually, it looks like your funnels are in our database, they just aren’t being displayed on your funnel list. I have opened a bug report for this issue.

So there’s no problem from my side, right?

@surajsirohi1008

Were you ever able to see your funnels? We are trying to narrow down if it was a recent change that caused this or if this has been an issue for longer.

The funnels aren’t getting processed correctly in the backend and that’s causing a display problem on the front-end. We can fix the front-end bug pretty easily, so you’ll be able to see your funnels without any modification. But the backend changes might take more time and I don’t know when that would be done.

I would recommend you modify the first event you are sending (“50”) to be a string (“<50” or something like that) and that will make sure the event is processed correctly. (Even putting 50 in quotes doesn’t turn it into a string in our system.)

@surajsirohi1008 ,

The funnel bug was fixed this afternoon, so you should now be able to see your funnel list. The funnels are still not processed correctly, so you may still want to recreate them with different custom events.

Yes, funnels are visible now, all of them, thank you.

2 Likes