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
AnalyticsEventis the model that represents an analytics layer event.Trackersare located in the features modules; they are responsible for creating anAnalyticsEventfrom the data provided from the ViewModel.Analyticsis the interface to sendAnalyticsEvents.EventsSourceis the interface to observeAnalyticsEvent.TrackingProvidersare specific for each analytics provider; they are responsible for subscribing and handling the flow of theAnalyticEvents.AnalyticsFiltersare responsible for filtering the unwantedAnalyticsEventsfor the specific analytics provider.ProviderEventis the specific analytic event of the analytics provider.EventFactoryis responsible for mapping theAnalyticsEventsto theProviderEvent.AnalyticsWrapperis the wrapper around the analytics provider that logs the events provided by theEventFactory.
How add a new analytics provider
To add a new analytics provider:
- Most analytics providers have their own model, if not, create a new model that fits the needs of your analytics provider.
- Create a new implementation of
EventFactory<{AnalyticsModel}>where you map fromAnalyticsEventto your model. - Create a new implementation of
AnalyticsFilterwhere you filter the unwanted events. If you only requireAnalyticsEvent.VERSION_2, you can use the provided filterDefaultAnalyticsFilterV2. - Create a new implementation of
AnalyticsWrapper<{AnalyticsModel}>where you log the event on your provider. - 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. - Call
subscribe()on yourTrackingProvider<{AnalyticsModel}>object in theonCreatemethod of your application.