Latest 0.0.1
License MIT
Platforms ios 8.0


A Protocol Oriented Analytics Wrapper. For more Information read my article on Medium


To install the AnalyticsManagerService via CocoaPods, simply use the add this in your podfile and then run pod install

pod 'AnalyticsManagerService'


Simply create a subclass of AnalyticsServiceProtocol and AnalyticsEventProtocol for example we’ll use Fabric for the example

// AnalyticsServiceProtocol
class FabricAnalyticsService: AnalyticsServiceProtocol {
    func initialize(application: UIApplication, launchOptions: [UIApplicationLaunchOptionsKey : Any]?) {

    func send(event: AnalyticsEventProtocol) {
        Answers.logCustomEvent(withName:, customAttributes: event.parameters)
// AnalyticsEventProtocol
enum AnalyticsEvent: AnalyticsEventProtocol {
    case userLoggedIn
    case userLoggedOut
    case productSelected(productId: Int)

    var name: String { 
        switch self {
        case .userLoggedIn:     return "User Logged In"
        case .userLoggedOut:    return "User Logged Out"
        case .productSelected:  return "Product Selected"

    var parameters: [String: Any]? {
        switch self {
        case .userLoggedIn:                 return nil
        case .userLoggedOut:                return nil
        case .productSelected(id: let id):  return ["product_id": productId]

    var isTrackedOnAnalyticsServices: [AnalyticsServiceProtocol.Type] { 
        switch self {
        /// will be sent on 2 services 
        case .userLoggedIn:     return [FacebookAnalyticsService.self, FabricAnalyticsService.self]

        /// will not be sent anywhere
        case .userLoggedOut:    return [] 

        /// will be sent on only one service
        case .productSelected:  return [FacebookAnalyticsService.self]

Then we add the service in our UIApplicationDelegate

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    // Add our services
    AnalyticsManagerService.shared.add(service: FacebookAnalyticsService())
    AnalyticsManagerService.shared.add(service: FabricAnalyticsService())

    // Initialize the analytics
    AnalyticsManagerService.shared.initialize(application: application: launchOptions: launchOptions)


Using an event would be as simple as accessing the singleton and using the send(event: _) function

AnalyticsManagerService.shared.send(event: AnalyticsEvent.userLoggedIn)
AnalyticsManagerService.shared.send(event: AnalyticsEvent.productSelected(productId:

Latest podspec

    "name": "AnalyticsManagerService",
    "version": "0.0.1",
    "summary": "A Protocol Oriented Analytics Wrapper",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Zonily Jame Pesquera": "[email protected]"
    "social_media_url": "",
    "platforms": {
        "ios": "8.0"
    "source": {
        "git": "",
        "tag": "0.0.1"
    "source_files": [
    "description": "Reusable Analytics Wrapper",
    "homepage": "",
    "pushed_with_swift_version": "3.0"

Pin It on Pinterest

Share This