Search Unity

Resolved Custom Event AnalyticsResults always comes back as NotInitialized

Discussion in 'Unity Analytics' started by Shack_Man, Nov 24, 2022.

  1. Shack_Man

    Shack_Man

    Joined:
    Jun 7, 2017
    Posts:
    372
    I've set up Analytics but when trying to send a custom event, the result always comes back as NotInitialized even though analytics state says initialized.


    Code (CSharp):
    1.    async void Start()
    2.     {
    3.         await UnityServices.InitializeAsync();
    4.         Debug.Log(UnityServices.State);
    5.         List<string> consentIdentifiers = await AnalyticsService.Instance.CheckForRequiredConsents();
    6.         if (consentIdentifiers.Count > 0)
    7.         {
    8.             consentIdentifier = consentIdentifiers[0];
    9.             isOptInConsentRequired = consentIdentifier == "pipl";
    10.         }
    11.    
    12.     }
    13.     [ContextMenu("tr")]
    14.     void Trigger()
    15.     {
    16.         AnalyticsResult result = Analytics.CustomEvent("score");
    17.  
    18.         Debug.Log("analyticsResult: " + result);
    19.         Debug.Log(UnityServices.State);
    20.     }


    I tried to add the code in the UGS sample project in an empty scene and it works fine, even if I leave out the Start method and just send the event directly. Analytics events are enabled in the dashboard.

    On a side note, Analytics no longer shows up in the Services Window, I could swear I saw it there just a few days ago. Though I updated everything once the error started.


    And of course no data gets send to the dashboard. Normal events like gameStarted and Ended are being sent just fine, and I can log in the user anonymously and get the ID. So I guess I'm messing something up with the custom event? Just so weird that it works in the sample project without calling any methods before hand.

    upload_2022-11-24_21-49-11.png
     
    Last edited: Nov 24, 2022
    kmowers likes this.
  2. PhilG-Unity

    PhilG-Unity

    Unity Technologies

    Joined:
    Mar 17, 2022
    Posts:
    26
    Hey there,

    Thanks for reaching out with this question.

    Can you tell me what version of the Analytics SDK package you're using? It looks to me like you may be using an older API for sending the Custom Event that is not applicable anymore.

    And as a result your AnalyticsResult variable is not being initialized because the method you're using isn't returning anything.

    When using UGS Analytics with recent versions of the SDK you should be using
    Code (CSharp):
    1. Analytics.Instance.CustomData()
    to send Custom Events, with a Dictionary object containing key value pairs for your custom parameter names & values.

    You can find an example of it documented here:
    https://docs.unity.com/analytics/RecordingCustomEvents.html

    Could you try using the syntax in the example above? Also, just to be sure, you have created the Custom Event named 'score' in your Dashboard's Event Manager? Custom Events need to be defined / created in the Dashboard before they can be sent from code.

    Keep me posted on how it goes.

    Best,
     
    Last edited: Nov 24, 2022
    Ferroni and kmowers like this.
  3. Shack_Man

    Shack_Man

    Joined:
    Jun 7, 2017
    Posts:
    372
    Thanks for the fast reply, it's working now! Things seem to be changing quite fast... I'm using Analytics Version 4.2.0 btw and that is the same version used in the UGS sample package (I cloned today). It just through me off that the old method I posted aboved seemed to work in there (though of course all I had was the AnalyticsResult coming back as "OK".

    Thanks again!
     
    Ferroni and PhilG-Unity like this.
  4. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    Yeah it gets confusing asf, I ran into the same mistake you made when I recently integrated UGS, a lot of Unity's links in many places still point to the old analytics.

    The docs you want to reference are at
    https://docs.unity.com/analytics/RecordingCustomEvents.html
     
    Ferroni likes this.
  5. Shack_Man

    Shack_Man

    Joined:
    Jun 7, 2017
    Posts:
    372
    I always remind myself that this is part of progress and the alternative is using Unity 1.0 :) Good thing we have a forum and Unity folks replying so fast.
     
  6. PhilG-Unity

    PhilG-Unity

    Unity Technologies

    Joined:
    Mar 17, 2022
    Posts:
    26
    Hi Meltdown,

    Sorry to hear you've found the docs confusing. We appreciate the feedback.

    If you can provide links to official Unity UGS Analytics documentation that is still showing the old API I'll do what I can to raise awareness here internally that this content needs to be updated. It's also important to make sure the docs you're looking at are not for Legacy Analytics, our previous (now deprecated) Analytics SDK.

    For third-party content unfortunately there's not much we can do.

    I know we have an offiicial UGS Bootcamp video for getting started with UGS Analytics which was made while the service was still in Beta and it does unfortunately demonstrate the outdated API. The high-level overview of how to work with UGS Analytics in the video is still useful but for code I'd always urge folks to consult the official UGS Analytics documentation.

    Cheers,
     
  7. Shack_Man

    Shack_Man

    Joined:
    Jun 7, 2017
    Posts:
    372

    Videos showing old stuff just happens, good thing there are comments on Youtube where those issues are often discussed and solved.

    I have no idea how easy/fast it is to change it, but I would have appreciated a warning in Visual Studio that the method is deprecated, like when using Transform.RotateAround or something (though unlike UGS events it still works...).

    And as I mentioned above, what confused me was that the old method returned "OK" in the UGS sample project even though the Analytics Package was up to date. And with no deprecation warning in my own project I figured something is wrong with the initialization method so I kept trying all sorts of things...
     
    Meltdown likes this.
  8. alexennerfelt

    alexennerfelt

    Joined:
    Jan 7, 2017
    Posts:
    15
    Since it doesn't work at all anymore, can we at least have it marked as Obsolete?
    It's end of 2023 and I spent 2 hours debugging why my custom events were not being recorded.


    Code (CSharp):
    1. //This is no longer working, yet for some reason not marked as Obsolete
    2. Analytics.CustomEvent(string customEventName)
    3.  
    4. //It has been replaced by this
    5. AnalyticsService.Instance.CustomData(string customEventName)
     
  9. ry511

    ry511

    Joined:
    Jul 24, 2016
    Posts:
    62
    This was super frustrating for me as well. Also there is no result object anymore. I just have to wait a while for the dashboard to pickup the event to see if its working?