Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to use Analytics for sending High Score?

Discussion in 'Unity Analytics' started by surajsirohi1008, Feb 12, 2018.

  1. surajsirohi1008

    surajsirohi1008

    Joined:
    Jun 21, 2016
    Posts:
    267
    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).
     
  2. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @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:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Analytics;
    3. using System.Collections.Generic;
    4.  
    5. public class TrackHighScore : MonoBehaviour {
    6.     public void SendHighScore(float highScore)
    7.     {
    8.         // Create dictionary to store you event data
    9.         Dictionary<string, object> data = new Dictionary<string, object>();
    10.  
    11.         //Add the high score to your event data
    12.         data.Add("high_score", highScore);
    13.  
    14.         // The name of the event that you will send
    15.         string eventName = "High Score";
    16.  
    17.         //Send the event. Also get the result, so we can make sure it sent correctly
    18.         AnalyticsResult result = Analytics.CustomEvent(eventName, data);
    19.         //Debug.Log(result);
    20.     }
    21.  
    22.     //This will only be useful if you have a small number of levels
    23.     public void SendHighScorePerLevel(float highScore, int level)
    24.     {
    25.         // Create dictionary to store you event data
    26.         Dictionary<string, object> data = new Dictionary<string, object>();
    27.  
    28.         //Add the high score to your event data
    29.         data.Add("high_score", highScore);
    30.  
    31.         // The name of the event that you will send
    32.         string eventName = "Level - " + level;
    33.  
    34.         //Send the event. Also get the result, so we can make sure it sent correctly
    35.         AnalyticsResult result = Analytics.CustomEvent(eventName, data);
    36.         //Debug.Log(result);
    37.     }
    38. }
     
    Fraccas and surajsirohi1008 like this.
  3. surajsirohi1008

    surajsirohi1008

    Joined:
    Jun 21, 2016
    Posts:
    267
    Thanks! This will do.
     
  4. surajsirohi1008

    surajsirohi1008

    Joined:
    Jun 21, 2016
    Posts:
    267
    I used Debug.Log(result);

    and in the console I get "TooManyRequests".

    What did I do wrong? There is nothing in the Validator.
     
  5. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    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?
     
  6. surajsirohi1008

    surajsirohi1008

    Joined:
    Jun 21, 2016
    Posts:
    267
    Yes it was in the update function, fixed that. I created a new funnel but when I hit save, it doesn't save.
     
  7. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    Does the page give you any error messages?
     
  8. surajsirohi1008

    surajsirohi1008

    Joined:
    Jun 21, 2016
    Posts:
    267
    No, I click save and it takes me back to create funnel page. How many steps can I add?
     
  9. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    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.
     
  10. surajsirohi1008

    surajsirohi1008

    Joined:
    Jun 21, 2016
    Posts:
    267
    I'm adding 20 steps.

    This is what I get after clicking on save funnel:

    Screen Shot 2018-02-17 at 11.50.38 AM.png
     
  11. surajsirohi1008

    surajsirohi1008

    Joined:
    Jun 21, 2016
    Posts:
    267
  12. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @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.)?
     
  13. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @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.
     
  14. surajsirohi1008

    surajsirohi1008

    Joined:
    Jun 21, 2016
    Posts:
    267
    So there's no problem from my side, right?
     
  15. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @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.)
     
  16. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @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.
     
  17. surajsirohi1008

    surajsirohi1008

    Joined:
    Jun 21, 2016
    Posts:
    267
    Yes, funnels are visible now, all of them, thank you.
     
    ROBYER1 and ap-unity like this.