Implementing Analytics Manager for your iOS app

Reshu Malik
2 min readAug 1, 2022

--

Analytics manager that we are discussing below will act as a wrapper for all different types of analytics sdk’s you are using for data collections as per your product requirement.

First we will start with AnalyticsService, This will define the protocol that all the analytics services (Different service for different sdk/data collection end point).

  • initializeApp will initialize sdk for that service and will pass app and launchOptions as params.
  • trackEvent: It can be called by any of the class from where you can ask analytics service to track an event
  • setUser/unsetUser: To track events as per user properties when loggedIn/LoggedOut
  • trackingEvents: this will return all the events tracked by that service

AnalyticsManager: AnalyticsManager is the shared instance that will be accessible from anywhere in the app, So it is easy to use. For this tutorial we are making this a singleton class but this can also be a simple class and same instance can be injected in all the classes that needs to track events. Since here we are not doing some data manipulation, its safe to use singleton.

Since AnalyticsManager will be used from everywhere to track events, this will also confirm to AnalyticsService and implement all required methods.

AnalyticsEvent is an enum that will keep all the events and their properties wrapped. This will centralise all events used in ur app.

CleverTapAnalytics: for each analytics sdk you want to support you will create a subclass of AnalyticsService and implement methods that are required.

You can override tracking events to specify all events tracked needs to be tracked by cleverTap

--

--