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
AnalyticsEvent
is the model that represents an analytics layer event.Trackers
are located in the features modules; they are responsible for creating anAnalyticsEvent
from the data provided from the ViewModel.Analytics
is the interface to sendAnalyticsEvents
.EventsSource
is the interface to observeAnalyticsEvent
.TrackingProviders
are specific for each analytics provider; they are responsible for subscribing and handling the flow of theAnalyticEvents
.AnalyticsFilters
are responsible for filtering the unwantedAnalyticsEvents
for the specific analytics provider.ProviderEvent
is the specific analytic event of the analytics provider.EventFactory
is responsible for mapping theAnalyticsEvents
to theProviderEvent
.AnalyticsWrapper
is 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 fromAnalyticsEvent
to your model. - Create a new implementation of
AnalyticsFilter
where 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 theonCreate
method of your application.