Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question Analytics Beta custom events not being tracked

Discussion in 'Unity Analytics' started by hotlabs, Sep 28, 2023.

  1. hotlabs

    hotlabs

    Joined:
    Apr 11, 2021
    Posts:
    20
    I have setup 3 environments (development, production and beta_testing). I encapsulated the tracking code in a GameAnalytics class:

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using System.Threading.Tasks;
    3. using Unity.Services.Analytics;
    4. using Unity.Services.Core;
    5. using Unity.Services.Core.Environments;
    6. using UnityEngine;
    7.  
    8. public class GameAnalytics : Singleton<GameAnalytics> {
    9.  
    10.     private async Task Start() // Changed to async Task
    11.     {
    12.         try
    13.         {
    14.             var options = new InitializationOptions();
    15.             options.SetEnvironmentName("development");
    16.             await UnityServices.InitializeAsync(options);
    17.             // If you want a custom user id
    18.             // UnityServices.ExternalUserId = "some-user-id";
    19.          
    20.             Debug.Log("Analytics service initialised");
    21.         }
    22.         catch (System.Exception ex)
    23.         {
    24.             Debug.LogError($"Failed to initialize UnityServices: {ex.Message}");
    25.         }
    26.     }
    27.  
    28.     public void TrackLevelStarted(int userLevel)
    29.     {
    30.         if (AnalyticsService.Instance == null)
    31.         {
    32.             Debug.LogError("AnalyticsService is not initialized.");
    33.             return;
    34.         }
    35.  
    36.         var parameters = new Dictionary<string, object>
    37.         {
    38.             { "userLevel", userLevel }
    39.         };
    40.  
    41.         AnalyticsService.Instance.CustomData("levelStarted", parameters);
    42.         Debug.Log("Sent event levelStarted:" + userLevel);
    43.     }
    44. }
    45.  
    After running the game, triggering the event a couple of times and waiting for 24h (48h now) I noticed the Analytics dashboard is not showing anything (both in the valid and invalid events section). I'm using the custom levelStarted event defined in the Event Manager section.
    UPDATE: some events are being sent but to the "Production" envinronment, not sure why.
    Looks like the
    Code (CSharp):
    1. options.SetEnvironmentName("development");
    is not working

    Also, no error was reported in the logs, what could be the problem?
    Screenshot 2023-09-28 at 14.58.06.jpg Screenshot 2023-09-28 at 14.58.54.jpg Screenshot 2023-09-28 at 15.04.55.jpg Screenshot 2023-09-28 at 14.58.06.jpg Screenshot 2023-09-28 at 14.58.54.jpg Screenshot 2023-09-28 at 15.04.55.jpg
     
    Last edited: Sep 29, 2023
  2. mdimov

    mdimov

    Joined:
    Oct 22, 2017
    Posts:
    2
    hey @hotlabs were you able to figure this out?
     
  3. SebT_Unity

    SebT_Unity

    Unity Technologies

    Joined:
    Jun 21, 2021
    Posts:
    283
    Hey folks,

    If your projects have an older version of IAP. Make sure to remove the second checkbox.

    "Automatically Initialize Unity Gaming Services"
    upload_2023-11-22_9-55-5.png

    Please try removing that and see if your events correctly show in the environment.
    Calling
    options.SetEnvironmentName("development");
    Should override any other settings. However in older versions of IAP it fails to do so.