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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.