mixpanel / mixpanel-unity

Official Unity Tracking Library for Mixpanel Analytics
https://mixpanel.com
Apache License 2.0
43 stars 40 forks source link

Ad blockers causing PlayerPrefs to run out of storage on WebGL and Mixpanel to throw exception #127

Closed lourd closed 2 years ago

lourd commented 2 years ago

When using this library in the WebGL build of our Unity application, we've seen a portion of users run into an issue with PlayerPrefs running out of storage:

UnityEngine.PlayerPrefsException: Could not store preference value at UnityEngine.PlayerPrefs.SetString (System.String key, System.String value) [0x00000] in <00000000000000000000000000000000>:0

We debugged this and discovered that the exception is coming from the Mixpanel library. If a user has an ad blocker on that causes the requests to api.mixpanel.com to fail, events continue to be put into PlayerPrefs, eventually blowing the 1MB limit and causing this exception and crashing our application.

We've worked around this by making a HEAD request from our application code to https://api.mixpanel.com/track and using the success or failure of that to determine if we should disable the Mixpanel library, but it would be great if the library handled this better — clearing out the cache when the limit is reached, or some kind of ring buffer, or offering some other way to configure storage thresholds.

It would also be really helpful if the library used a storage interface other than PlayerPrefs, perhaps even allowing that to be configurable if need be, since its 1 MB limit on WebGL builds is so small.

We are also looking into setting up a proxy server for ourselves, like the Mixpanel docs recommend. But the problem would still remain for certain conditions, such as operating offline.

zihejia commented 2 years ago

hi @lourd , now you will be able to set a storage interface other than PlayerPrefs. call SetPreferencesSource to set the data persistence of your choice as long as it follows IPeferences. For example: Mixpanel.SetPreferencesSource(<your own persistence>); I'm closing this one now, but feel free to reopen it if you need further help.