Disable Visual Studio App Center when running on a Simulator, Emulator or Test Cloud device

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.

Abstraction

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.

Xamarin.Forms

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!


2 Comments on “Disable Visual Studio App Center when running on a Simulator, Emulator or Test Cloud device

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

  2. 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 :(

Leave a Reply

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