Using Realm to gather analytics and statistics data in Unity

Hey Stefan, thanks for the well thought out post! Let me try to address some of the points here and pose a few questions.

If I understand correctly, you have two types of data that you want to store in Realm - Analytics (information consumed by you as a developer) and Statistics (information consumed by the player). Do you want the Statistics to be synchronized to the server? This may be useful if you want to allow users to share progress across multiple devices or continue where they left off if they reinstall the game.

And for your questions:

  1. You can convert between local and synchronized Realms using the Realm.WriteCopy method. So theoretically, it’s possible to start out with a synchronized Realm, then convert it a local one, then back to a synchronized one when the user turns back data collection. Note that this doesn’t currently work for flexible sync, but we’re looking at ways to enable it.
  2. You can use a single synchronized Realm for both analytics and statistics. When the player turns data collection off, you can just stop emitting analytics data, while still synchronizing statistics (if that is desirable). If you want to stop sync altogether, you can stop the sync session as soon as the Realm is opened by calling realm.SyncSession.Stop(). This will prevent any synchronization for this Realm until SyncSession.Start is called or the Realm is reopened without stopping the session. If you don’t really need to sync the statistics data, then using a combination of local + synchronized Realm might be best.
  3. Regarding credentials and related to 2. - logging users as anonymous is totally fine. If you want to allow users to share progress across devices, you may consider allowing them to create an account. If they opt to do that, you can link their anonymous credentials with the new credentials they’ve supplied.
  4. For analytics data, we’re in the process of releasing a feature called Asymmetric Sync. This would allow you to more efficiently push unidirectional data (such as analytics) to the server. There’s an open PR for the Unity SDK and we expect to release it in the near future.

Hope this clarifies things a little and happy to continue the conversation. As a big Unity fan, I’m always excited to see what games/projects people are building :smile: