Avoid Simulator, Emulator and Testing statistics in Visual Studio Mobile Center

When tracking usage statistics and crashes with Visual Studio Mobile Center, you usually only want real-world data in there and filter out data that gets generated while developing or testing the app. To avoid sophisticated insights like those in the screenshot below, developers need to define, when Visual Studio Mobile Center should track data and when it should not.

Visual Studio Mobile Center's Analytics tabs shows development data

Analytics and crash data usually should not impact those statistics, when an app is

  • Running in Debug Mode
  • Running on a Simulator or Emulator
  • Running in the Xamarin Test Cloud

Before starting the client analytics using the MobileCenter.Start() method, we should scan the environment to decide whether to run this command or not. For this, we implement a method on each platform, that scans if the current app environment is a real-world scenario.

Debug Mode can be checked easily using the #if DEBUG compiler directive. Even when not running on .NET, most other frameworks should have an equivalent for this.

If the app is running in a Simulator or Emulator can be detected by checking the current runtime architecture with Runtime.Arch on iOS or Fingerprint with Build.Fingerprint on Android.

The Xamarin Test Cloud sets specific environment variables on its devices, that can get examined using Environment.GetEnvironmentVariable().


Creating an interface for the small Environment Service helps to unify its implementations and usage within Dependency Injection.

iOS implementation

On Apple’s platforms, an easy architecure check tells us, if the app is running or a simulator or real device.

Android implementation

Android does not have the concepts of Simulators and uses full Hardware Emulation instead, which means we have to check the real or emulated devices’ fingerprints. There are multiple Android Emulators out there but looking for "vbox" or "generic" did the trick for me.

Add the real-world check before starting to track analytics

Before starting the MobileCenter service now, we can simply fire an EnvironmentService.IsRunningInRealWorld() check and only proceed if it is positive.

When using Xamarin.Forms, just add [assembly: Xamarin.Forms.Dependency(typeof(EnvironmentService))] to the platform implementations and call them using Xamarin.Form’s built-in Dependency Service.

This should avoid having sophisticated Development and Testing data in you Visual Studio Mobile Center Analytics and Crashes section. Enjoy the cleaned up dashboards!

One Comment on “Avoid Simulator, Emulator and Testing statistics in Visual Studio Mobile Center

  1. Pingback: Dew Drop - September 18, 2017 (#2563) - Morning Dew

Leave a Reply