Search Unity

Question Custom Events not showing up on dashboard.

Discussion in 'Unity Analytics' started by FoxAdventures, Jan 10, 2022.

Thread Status:
Not open for further replies.
  1. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    I have an AnalyticsManager class in the initial scene and it carries over to every scene. It has these methods.


    Code (CSharp):
    1.  
    2. . . .
    3.         void Start()
    4.     {
    5.         UnityServices.InitializeAsync();
    6.     }
    7.     . . .
    8.     public void OnLevelStart(int level)
    9.     {
    10.         Debug.Log(level + " start saved");
    11.         Analytics.CustomEvent("levelStart" + level);
    12.     }
    13.  
    14.     public void OnLevelComplete(int level)
    15.     {
    16.         Debug.Log(level + " completion saved");
    17.         Analytics.CustomEvent("levelWin" + level);
    18.     }
    19.  
    20.     public void OnLevelFail(int level)
    21.     {
    22.         Debug.Log(level + " fail saved");
    23.         Analytics.CustomEvent("levelFail" + level);
    24.     }
    25.  
    26.     public void OnIteration(int iter)
    27.     {
    28.         Analytics.CustomEvent("iteration" + iter);
    29.     }
    30.  

    And I call these methods in GameManager script, which exists attached to an object in every scene except the first one:

    Code (CSharp):
    1.  
    2. . . .
    3.    private void Start()
    4.     {
    5.         scene = SceneManager.GetActiveScene();
    6.         //level start event
    7.         level = LevelManager.Level_Static;
    8.         try
    9.         {
    10.             AnalyticsManager.instance.OnLevelStart(level);
    11.         }
    12.         catch(System.Exception e)
    13.         {
    14.             print(e.Message);
    15.         }
    16.     }
    17.  
    18.     void Update()
    19.     {
    20.         iter = LevelManager.iteration;
    21.         //level finish event
    22.         if (levelMan.IsLevelFinished)
    23.         {
    24.             AnalyticsManager.instance.OnLevelComplete(level);
    25.         }
    26.         //level fail event
    27.         if (uiMaster.failed)
    28.         {
    29.             AnalyticsManager.instance.OnLevelFail(level);
    30.         }
    31.         //iteration finished event
    32.         if (levelMan.iterated)
    33.         {
    34.             AnalyticsManager.instance.OnIteration(iter);
    35.         }
    36.     }
    37.  . . .
    38.  

    And I'm pretty sure I am connected to Unity Analytics, since "standard events" do get registered in the dashboard and whenever I test on an Android phone I can see the data there. But the custom events won't show. I even manually added the first one, "levelStart", to dashboard and added its parameter there but to no avail.
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    The code you shared is for Legacy Analytics but you are describing the Analytics Beta. Can you confirm that the Debug.Log output is showing as expected when you run the game? If so, then you will want to look in the Legacy section of your dashboard for the events. To send events with the Analytics beta, you are correct to define the events first in the dashboard and then the code would be similar to the following:

    Code (CSharp):
    1.         Dictionary<string, object> parameters = new Dictionary<string, object>()
    2.         {
    3.             { "MyParameter", "hello there" }
    4.            
    5.         };
    6.         Events.CustomData("MyEvent", parameters);
     
    gotiobg and unity_Ctri like this.
  3. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78

    Legacy Analytics doesn't work on the dashboard right now - seems to be a server error. And the outputs are showing as expected so, no problem there. I've read in a few places that custom events take 24 hours to register, so, if that is the case I'll just have to wait and see. I'm now doing it the beta way:

    Code (CSharp):
    1. public void OnLevelStart(int level)
    2.     {
    3.         Debug.Log(level + " start saved");
    4.  
    5.  
    6.         Dictionary<string, object> parameter = new Dictionary<string, object>()
    7.         {
    8.             { "Level", level }
    9.  
    10.         };
    11.  
    12.         Analytics.CustomEvent("levelStart" + parameter);
    13.  
    14.  
    15.     }
    I hope this works!
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    The code that you just shared is not the "beta way", that's the legacy syntax. Yes, we are experiencing some dashboard delays right now.
     
  5. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    Now it has been about 12 hours since I first started the integration. There seem to be no custom events listed in the Legacy dropdown menu. I thought when you said

    and wrote a dictionary, I thought you were showing the beta syntax, not the legacy syntax?

    Edit: Realized that your code says "Events.CustomData" my bad! Will try another build with the new script. Then I guess I'll wait another day. Just hope this one works. Here's what it looks like now:

    Code (CSharp):
    1.  public void OnLevelStart(int level)
    2.     {
    3.  
    4.  
    5.         Dictionary<string, object> parameter = new Dictionary<string, object>()
    6.         {
    7.             { "level", level }
    8.  
    9.         };
    10.  
    11.         Events.CustomData("levelStart", parameter);
    12.         Debug.Log(level + " start saved");
    13.  
    14.  
    15.     }
    16.  
    17.  
    18.     public void OnLevelComplete(int level)
    19.     {
    20.         Debug.Log(level + " completion saved");
    21.  
    22.         Dictionary<string, object> parameter = new Dictionary<string, object>()
    23.         {
    24.             { "level", level }
    25.  
    26.         };
    27.  
    28.  
    29.         Events.CustomData("levelWin" , parameter);
    30.     }
    31.  
    32.     public void OnLevelFail(int level)
    33.     {
    34.  
    35.         Debug.Log(level + " fail saved");
    36.  
    37.  
    38.         Dictionary<string, object> parameter = new Dictionary<string, object>()
    39.         {
    40.             { "level", level }
    41.  
    42.         };
    43.  
    44.         Events.CustomData("levelFail" , parameter);
    45.  
    46.     }
    47.  
    48.     public void OnIteration(int iter)
    49.     {
    50.  
    51.  
    52.         Dictionary<string, object> parameter = new Dictionary<string, object>()
    53.         {
    54.             { "iter", iter }
    55.  
    56.         };
    57.  
    58.         Events.CustomData("iteration" , parameter);
    59.  
    60.  
    61.     }
     
    Last edited: Jan 11, 2022
  6. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    Just to be sure, because I could not find definitive answer on this online, when my game is played on an Android phone all of the data flows in just fine, including standard events. But since what I need are custom events, and they're going to be loaded for the first time, that's why they'll take up to a day? Or will custom events always take a day to show on dashboard? Thanks in advance!
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Beta events will show up in minutes. Last time I tested, they showed up in less than 2 minutes. Legacy analytics takes awhile, generally 8-16 hours up to a couple of days. Also, your Debug.Log statements will show in the Android logcat device logs, a great way to debug your live code.
     
    gotiobg likes this.
  8. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    Then I am at a complete loss as to why they are not showing up. I did the set up, all of the data are flowing in including the standard events, but not custom events. I must be setting them up wrong somehow, but from what little instructional videos I could find online everything looks perfectly fine.
     
  9. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You've confirmed that you are seeing your Debug.Log statements? Please send me a private message on here with your Unity ProjectID and I'll take a look.
     
    FoxAdventures likes this.
  10. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    Thank you, just sent you a PM regarding the Debug.Log statements and my project ID.
     
  11. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    The Debug.Log statements will also show in the Console when testing the game in the Editor. I viewed your dashboard, and I see you have defined the parameters as an Integer but you are sending a String. I might expect them to show in the Invalid Events report but I'm not seeing them there either. Before I check with engineering, can you confirm that you are seeing your Debug.Log statements for levelStart (for example) when running in the Editor?
     
  12. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    I attached the screenshot of the console below. This is the method in the script:

    Code (CSharp):
    1.     public void OnLevelStart(int level)
    2.     {
    3.  
    4.         Dictionary<string, object> parameter = new Dictionary<string, object>()
    5.         {
    6.             { "level", level }
    7.  
    8.         };
    9.  
    10.         Events.CustomData("levelStart", parameter);
    11.         Debug.Log(level + " start saved");
    12.  
    13.  
    14.     }
     

    Attached Files:

  13. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Oh wait, my bad. It is defined correctly, string and object (Integer). We are checking here
     
    FoxAdventures likes this.
  14. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    I'll be looking forward to any updates on the matter, thank you for everything you've done so far!
     
  15. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    We are seeing your events now in the Event Browser, levelStart so far.
     
  16. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    Thanks a ton! What was I doing wrong?
     
  17. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    Hello Jeff, I did another test and it is not working again.
     
  18. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please be specific. You just need to wait a bit for the events to arrive. It might take a couple of hours, I've seen events in minutes. Like last time, if you didn't do anything differently, then you would just need to wait.
     
  19. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    The standard events do show, but none of the custom events are present. Do they normally take different times?
     
  20. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Not sure about timing, I will check. So you are seeing Standard events with a UTC timestamp at the same time you sent Custom Events, and you saw the Debug.Log associated with the event?
     
  21. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    Yes I did. The test was run at around 19:17 and none of the custom events were shown on it.
     
  22. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Got it, I'm still checking here. But like last time, I suspect we just need to give it more time.
     
  23. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @FoxAdventures Can you add the following code after Events.CustomData(..) and try the test again? We believe the custom events may be cached on the client but still sending the Standard events, which is what we are seeing on your dashboard.

    Events.Flush();
     
  24. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    After adding the code after every line Events.CustomData() is called, I am now met with an error message in the console which I have attached to this message.
     

    Attached Files:

  25. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    The test's results are in on the dashboard. At first, it just said levelFail for the whole 100 event slots. When I filtered the events browser to show levelWin, all of the slots now showed only levelWin. After a while it started to show some other standard events but not what I needed. The screenshots are attached below. (the last screenshot is what it looks like at the time of me posting this comment.)
     

    Attached Files:

  26. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    I think I now understand why they are spamming. uiMaster.failed is a bool, so as long as that returns true, the system would keep spamming the custom event, right? I thought it'd only register once. I will try it the other way. But I still don't know why it gives the error message at all.
     
  27. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Sorry, what is uiMaster.failed? And can you be a bit more specific, what do you mean "keep spamming" do you have a loop in your code? Make sure you don't send any events in Update() or FixedUpdate(), these callbacks can be called up to 100 times per second or more. Please compare your project to the attached (working) project and then link it to a new ProjectID in the Services window. Then define MyEvent and MyParameter in the Dashboard. Open MyScene, and click on the button in the running game to send the event.
     

    Attached Files:

    FoxAdventures likes this.
  28. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    Yes, sorry about the ambiguity. I tried putting them all in try-catch blocks because I thought that might help somehow. It sometimes does. Anyway, I then tried this:
    Code (CSharp):
    1. . . .
    2. bool failOnce, winOnce, startOnce, iterateOnce;
    3.  
    4. . . .
    5.  
    6.   try
    7.             {
    8.             if (levelMan.IsLevelFinished && !winOnce)
    9.             {
    10.                 winOnce = true;
    11.                 AnalyticsManager.instance.OnLevelComplete(level);
    12.             }
    13.             }
    14.             catch (Exception e)
    15.             {
    16.                 print(e.Message);
    17.             }
    18.  
    19. . . .
    which didn't work at all in the further tests. And I was always calling them in the Update method. I will now try to assign them to a button, and if that doesn't work either, I will PM you with the project file. Will keep you posted ASAP.
     
  29. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @FoxAdventures Correct, never send events in Update(). Only send them once when the level starts or finishes, for example. Otherwise you are unnecessarily sending thousands of duplicate events. Please review my project before sending yours.
     
    FoxAdventures likes this.
  30. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    I just played your project both in editor and as a build. The events that are displayed are attached below - none of them are the custom event "MyEvent". Does this mean the problem is with my account somehow?
     

    Attached Files:

  31. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Did you generate a new ProjectID, then define MyEvent and MyParameter on your Dashboard? And you clicked the Test button several times? Edit - I located the new project and the events are listed under Invalid Events. It looks like you are already working on it.
     
    YousafGrewal likes this.
  32. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    I did but I wrote the parameter name wrong. My bad! Tried it again, waited about 10 mins, and here are the results. Still no custom events and they are weirdly out of order.

    edit: Since I put the parameter name wrong in my previous test, MyEvent is listed there as invalid. But after fixing the parameter, it is not listed as valid. This does not make sense to me.
     

    Attached Files:

  33. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You need to send a new event if you change anything. Yes it makes sense. First you hadn't defined MyEvent, then you hadn't defined MyParameter. Now you have. Now you need to send the event again, and it should show. Ensure to always properly define your event and parameters before you send any events.
     
    YousafGrewal likes this.
  34. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    I have sent the event though, that's why it didn't make sense to me ! Haha. After I fixed the parameter, I rebuilt the game and played it on my computer. I had defined MyEvent since the start. Rebuilding it now again just to be sure.
     
    YousafGrewal likes this.
  35. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You can just run in the Editor too, no need to build for testing.
     
    YousafGrewal and FoxAdventures like this.
  36. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    Right. Well, I'm honestly done with this problem. I couldn't fix it, obviously, the analytics aren't working right, but alas. This is my graduation project for uni and I'll just tell my professor to grade me accordingly and lower my grade 20% or something fair like that. I'd like to thank you for helping me these past few days though Mr. Jeff, we at least made some good progress.
     
    YousafGrewal likes this.
  37. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you elaborate? Your events are all showing in the dashboard now. Select MyEvent in the EventName dropdown and select Filter in the Event Browser. You sent "hello there" as the parameter value. So far, I'm not seeing any issues, the service looks to be working as expected
     
    YousafGrewal and FoxAdventures like this.
  38. FoxAdventures

    FoxAdventures

    Joined:
    Jan 31, 2018
    Posts:
    78
    Events look completely out of order. I don't know if it normally works that way? If it does, it's all good. For example the first event is "levelStarted" and its parameter is 4. It says level 4 started before it even says level 1 started. Anyway, if it's working correctly, then I'm happy with it!
     
    mprimo and YousafGrewal like this.
  39. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Great! Lessons learned here include to define your events and parameters first on your dashboard with the proper datatype before sending events, and give events a few hours to show. Good luck on your project. I will go ahead and lock this thread now to avoid further confusion.
     
Thread Status:
Not open for further replies.