Creating an analytics service

In order to use the App Center SDK in our TripLog app, we will want to abstract it into a service, like we did for geolocation. As we saw multiple times in previous chapters, there are numerous benefits to this approach, namely, it loosely couples our ViewModels from the actual code that uses the App Center SDK, making unit testing our ViewModels much simpler and cleaner.

In order to create an analytics service, perform the following steps:

  1. First, create a new interface named IAnalyticsService in the Services folder of the core library:
      public interface IAnalyticsService       {      }
  1. Next, update the IAnalyticsService interface with methods to track usage events and errors:
      public interface IAnalyticsService { ...

Get Mastering Xamarin.Forms - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.