Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved UGS Analytics custom events not shown

Discussion in 'Unity Analytics' started by Bryarey, Apr 19, 2023.

  1. Bryarey

    Bryarey

    Joined:
    Aug 24, 2014
    Posts:
    23
    Hi there! Having a hard time figuring out UGS Analytics custom events.
    What I have:
    1. project is set up, I see default analytics events.
    2. Set up few custom events with custom parameters, created 2 funnels.
    3. In my code, I am defining a dictionary with arguments. I am not feed default parameters to events - only my custom ones, is it correct?
    4. In both editor and android build I see in the log that my custom event was sent with result AnalyticsResult.Ok
    5. In dashboard, I don't see any custom events in Events Browser nor DataExplorer nor Funnels... Also no Invalid events.

    6. Don't think it can really affect, but I also have GameAnalytics enabled - so maybe t conflicts with UGS analytics?

    What I am doing wrong?

    My code:

    Code (CSharp):
    1.  
    2. public static void LevelStarted(int chapter, int level)
    3. {
    4.     var unityEventData = new Dictionary<string, object>
    5.     {
    6.         {"Chapter", chapter},
    7.         {"Level", level},
    8.         {"PlayerId", UserId}
    9.     };
    10.     SendUnityCustomEvent("LevelStarted", unityEventData);
    11. }
    12.  
    13. private static void SendUnityCustomEvent(string name, Dictionary<string, object> data)
    14.         {
    15.             var result = UnityEngine.Analytics.Analytics.CustomEvent(name, data);
    16.             if (result != AnalyticsResult.Ok)
    17.             {
    18.                 Debug.LogError(">>>>>> Analytics event " + name + " failed with result: " + result);
    19.             }
    20.             else
    21.             {
    22.                 Debug.Log(">>>>>> Analytics event " + name + " sent with result: " + result);
    23.             }
    24.         }
    25.  
     
  2. Julian-Unity3D

    Julian-Unity3D

    Unity Technologies

    Joined:
    Apr 28, 2022
    Posts:
    189
    It seems you are using legacy events.

    See this documentation for UGS Analytics Custom Events: Record Custom Events (unity.com)
    Code (CSharp):
    1. // Send custom event
    2. Dictionary<string, object> parameters = new Dictionary<string, object>()
    3. {
    4.     { "fabulousString", "hello there" },
    5.     { "sparklingInt", 1337 },
    6.     { "spectacularFloat", 0.451f },
    7.     { "peculiarBool", true },
    8. };
    9. // The ‘myEvent’ event will get queued up and sent every minute
    10. AnalyticsService.Instance.CustomData("myEvent", parameters);
    11.  
    12. // Optional - You can call Events.Flush() to send the event immediately
    13. AnalyticsService.Instance.Flush();
    As for your use-case, you could potentially do something like this, however this is untested so may need a little work.
    Code (CSharp):
    1. public static void LevelStarted(int chapter, int level)
    2. {
    3.     Dictionary<string, object> eventData = new Dictionary<string, object>();
    4.     eventData.Add("Chapter", chapter);
    5.     eventData.Add("Level", level);
    6.     eventData.Add("PlayerId", UserId);
    7.  
    8.     // The ‘LevelStarted’ event will get queued up and sent every minute
    9.     AnalyticsService.Instance.CustomEvent("LevelStarted", eventData);
    10. }
    11.  
     
    Last edited: Apr 21, 2023
    VOXELIUM and Bryarey like this.
  3. Bryarey

    Bryarey

    Joined:
    Aug 24, 2014
    Posts:
    23
    Thanks, finally see it works!
     
    Julian-Unity3D likes this.