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.