When tracking usage statistics and crashes with Visual Studio App 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 App Center should track data and when it should not.

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 AppCenter.Start() method, we should scan the current 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.

You might want to check if the app is running on a Test Cloud device to avoid messed up UI Test from the Distribution Dialog and Denmark (where the Test Cloud devices live) as you most popular country in the statistics!

The App Center Test Cloud (formerly known as Xamarin Test Cloud) sets specific environment variables on its devices, that we can examine and use to check if the app is running on a test device.


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

iOS implementation

Android implementation

Add the real-world check before starting to track analytics

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


If you are using Xamarin.Forms, just register the platform implementations at the built-in Dependency Service.

Now you can call the environment service in the App.xaml.cs like below.

This should avoid having sophisticated Development and Testing data in you Visual Studio Mobile Center Analytics and Crashes section.

Enjoy the cleaned up dashboards!

Robin-Manuel Thiel

At daylight, Robin-Manuel talks about new IT trends and development. But at night he turns into a tinker and developer which sometimes leads to insufficient sleep. He loves cool technologies, cross-platform and everything with a power-plug or IP address.


Dominik · May 4, 2018 at 14:50

Hi Robin, have you tried running this code in App Center Test (as opposed to Xamarin Test Cloud)? The XAMARIN_* environment variables seem to be not available when running in App Center Test :(

Dew Drop - September 18, 2017 (#2563) - Morning Dew · September 18, 2017 at 12:26

[…] Avoid Simulator, Emulator and Testing statistics in Visual Studio Mobile Center (Robin-Manuel Thiel) […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.