Unity Analytics Beta Not Initializing in WebGL

Hi guys,

I’ve used Analytics in the past in Unity 2020/2021 with no issue, but with the new game that I’m working on, using 2022.3.4f1, I get this error:

1cf8fdb9-f59f-4d81-92c2-6c976b86e200:10 ServicesInitializationException: The Analytics service has not been initialized. Please initialize Unity Services.
  at Unity.Services.Analytics.AnalyticsService.get_Instance () [0x00000] in <00000000000000000000000000000000>:0

I’m even using ThreadPatcher and am successfully using Tasks in WebGL through other functions.

I do note that somehow, some way it recorded a few events on the 12th of August, with the same error above, but since then, none.

My code is as follows:

    private void Awake()
    {
        // Initialize UGS
        UnityServices.InitializeAsync();
    }

    private void Start()
    {
        // Initiate Analytics
        AnalyticsService.Instance.StartDataCollection();
    }

Any help would be greatly appreciated!

These methods are async and should be called together with the await keyword, like this:

private async void Awake()
{
    // Initialize UGS
    await UnityServices.InitializeAsync();
}

private async void Start()
{
    // Initiate Analytics
    await AnalyticsService.Instance.StartDataCollection();
}

You could also do both calls in the same method, e.g. Start().

I am leaving the discussion of using async void out of scope here.

I feel really silly for missing that :sweat_smile:- That worked beautifully, big thanks

1 Like