1 min read

Analytics layer

The analytics layer is where the analytics events are handled and forwarded to the specific analytics providers configured. The Android Poq SDK provides pre-configured analytics providers, go to integrations to know more about them. The analytics layer is also designed for adding new analytics providers easily.

The analytics layer contains two sets of events AnalyticsEvent.VERSION_1 and AnalyticsEvent.VERSION_2. Version 1 events are deprecated and version 2 are always preferred.

Overview

Analytics layer overview
Analytics layer overview

  • AnalyticsEvent is the model that represents an analytics layer event.
  • Trackers are located in the features modules; they are responsible for creating an AnalyticsEvent from the data provided from the ViewModel.
  • Analytics is the interface to send AnalyticsEvents.
  • EventsSource is the interface to observe AnalyticsEvent.
  • TrackingProviders are specific for each analytics provider; they are responsible for subscribing and handling the flow of the AnalyticEvents.
  • AnalyticsFilters are responsible for filtering the unwanted AnalyticsEvents for the specific analytics provider.
  • ProviderEvent is the specific analytic event of the analytics provider.
  • EventFactory is responsible for mapping the AnalyticsEvents to the ProviderEvent.
  • AnalyticsWrapper is the wrapper around the analytics provider that logs the events provided by the EventFactory.

How add a new analytics provider

To add a new analytics provider:

  1. Most analytics providers have their own model, if not, create a new model that fits the needs of your analytics provider.
  2. Create a new implementation of EventFactory<{AnalyticsModel}> where you map from AnalyticsEvent to your model.
  3. Create a new implementation of AnalyticsFilter where you filter the unwanted events. If you only require AnalyticsEvent.VERSION_2, you can use the provided filter DefaultAnalyticsFilterV2.
  4. Create a new implementation of AnalyticsWrapper<{AnalyticsModel}> where you log the event on your provider.
  5. Create a new object of TrackingProvider<{AnalyticsModel}> with the instances of the implementations created. The recommended way is to create a new named definition with Koin.
  6. Call subscribe() on your TrackingProvider<{AnalyticsModel}> object in the onCreate method of your application.