Unity Analytics can 404 silently and retry events infinitely.

Hi,

We’ve recently migrated from Unity 2019 to Unity 2020 and I guess used Legacy Analytics as it was pretty much auto included. Unity IAP requires the new Game Services, so we are forced to use that instead. After the release we saw significant slow downs and crashes reported from users.

Current Version:
Unity 2020.3.37f1
Analytics Package 4.0.1 (4.2.0 also has the same bug).

I should state we’ve not explicitly signed up to the new Analytics as it says something about billing and therefor I have just skipped over that. We are already running about 4 different Analytics tools (send help please), so it’s not super critical for us.

I looked into the logs and started to get a little concerned about Unity Analytics as the buffer got rather large in the logs. Because it logs a flush Debug.Log() every time in the region of 1mb+. I mean I wish I could turn this log off in general, but I guess it doesn’t harm too much.

Then I enabled UNITY_ANALYTICS_EVENT_LOGS in the editor to see what is happening. I was expecting it to just queue too many events. I found it was throwing 404 errors and then retrying all those events. That sounds scary in general because that will just queue up events forever into a buffer. I think there’s limits to the buffer, but I suspect it is going to have a detriment to performance.

So I looked at the collect url https://collect.analytics.unity3d.com/api/analytics/collect/v1/projects/{0}/environments/{1} and noticed it passes through environment and we initialized the services like this:
await UnityServices.InitializeAsync(new InitializationOptions().SetEnvironmentName("dev"/"live"));

This is the cause as to why the 404 happened, because as soon as I removed the SetEnvironmentName it started sending events.

TL;DR If you specify SetEnvironmentName() with an environment that does not exist it will just 404 forever on any events sent.

I also noticed AnalyticsLifetime runs after scene load and does a nice FindObjectsOfType() with a comment saying this is bad, but if it’s bad why not fix it and remove that check that is only applicable in test mode anyway? There must be better ways.

Please make some fixes to the code and/or documentation to prevent this happening.

Hey there,

I also stumbled into Events failed to upload (code 404) -- will retry at next heartbeat.
However, in my case it doesn’t matter whether I specify an environment or not (when not specified, I understood that it defaults to “production”), I still get code 404.

I’m a bit clueless what to do next, since there’s not much documentation available about this part.

The symbols UNITY_ANALYTICS_EVENT_LOGS and ENABLE_UNITY_SERVICES_CORE_VERBOSE_LOGGING also don’t say anything about it, so this is my last resort.

Did anybody else encounter this?

PS: running Unity 2021.3.0f1 + Analytics 4.3.0 package

Hi Bogdantana,
Apologies for the late reply.
We had an issue where newly created projects were getting this 404 error.
This should be resolved could you confirm at your earliest convenience?

Hello!

I’ve checked again and the 404 issue seems to persist. I’ve also tried to create a new project altogether on the dashboard and link it, but it seems to yield the same result.

Hi Bogdantana,

Thanks for the update. Could you confirm if your project was created around January 11-13?
Could you also send a direct message with your ORGID and possibly projectID?

Look forward to your response.
Best,
Seb

Hello Seb,

I actually have good news. The issue was still happening with a freshly-created project because of environment misconfiguration (leftover code from the original project Id). After taking care of that, it seems to register all events :slight_smile:

Thanks a lot for your help!
Bogdan

PS: The old project Id (created around Jan 11-13) I cannot associate from the editor anymore, not sure if that is an intended outcome of the fix on your side, just wanted to mention it.

1 Like

Hi Bogdantana,
Thanks for sharing. That is a great workaround!
However not intended to work in that fashion, I would prefer the original project began expecting data.

I will bring this news to our team. I am still interested in the ORGID if you have a moment to message me directly.

Thanks again for taking the time and posting your results above.