AnalyticsKit for Swift is designed to combine various analytical services into one simple tool.

Overview

🦋 AnalyticsKit

Build Status Build Status

AnalyticsKit for Swift is designed to combine various analytical services into one simple tool.

To send information about a custom event to a dozen analytics providers at once, one line is enough. Like this!

analytics.sendEvent(.appear, from: .order)

🌱 Getting started

Method calls happen in the AnalyticsKit class, you need to instantiate it. Passing your implementation of the protocols

  • AnalyticsModuleProtocol
  • AnalyticsEventProtocol
  • AnalyticsParamProtocol
let analytics = AnalyticsKit<Module, Event, Param>()

Your implementation of the punctures should provide the AnalyticsKit with the text data that will be passed to the providers. The most convenient way to do this is through an enum:

String { switch self { case .order: return "Order" } } } enum Event: AnalyticsEventProtocol { case appear case buy func name(for provider: ProviderProxy) -> String { switch self { case .appear: return "_Appear" case .buy: return "_Buy" } } } enum Param: AnalyticsParamProtocol { case name case price func name(for provider: ProviderProxy) -> String { switch self { case .name: return "name" case .price: return "price" } } } ">
// A "Module" refers to a user interface or screen.
// Most likely your implementation consists of several classes,
// so the definition of "Module" seems correct.
enum Module: AnalyticsModuleProtocol {
    case order
    func name(for provider: ProviderProxy) -> String {
        switch self {
        case .order: return "Order"
        }
    }
}

enum Event: AnalyticsEventProtocol {
    case appear
    case buy
    func name(for provider: ProviderProxy) -> String {
        switch self {
        case .appear: return "_Appear"
        case .buy: return "_Buy" 
        }
    }
}

enum Param: AnalyticsParamProtocol {
    case name
    case price
    func name(for provider: ProviderProxy) -> String {
        switch self {
        case .name: return "name"
        case .price: return "price"
        }
    }
}

Before sending an event, you need to register an analytics provider. AnalyticsKit contains some predefined values, but you can add a new provider as well.

analytics.register(.cleverTap)
analytics.register(.other(_ provider: ProviderProtocol))

⚠️ Important

It is important that for correct operation, it is required that the AnalyticsKit instance is not removed from memory during the life cycle of the application. Otherwise, the list of providers that you registered earlier will be cleared, and the events sent will simply have nowhere to go.

Alternatively, you can use the Singleton pattern or use a dependency manager convenient for you, for example Swinject

📨 Sending data

You have created events and parameters, now is the time to send information about custom actions to all your analytics providers at once! 🤩

// An event named "Order_Appear" will be sent without additional parameters.
// Note that AnalyticsKit glues the event name and the module name.
analytics.sendEvent(.appear, from: .order)

// An event with the name "Buy_Order" will be sent with the parameters:
// name = "Pizza"
// price = "10 $"
var params: [AppAnalyticsParam : Any] = [:]
params[.name] = "Pizza"
params[.price] = "10$"
analytics.sendEvent(.buy, with: params, from: .order)

// If you don't like the fact that the event name is composed of two halves, just do not pass the module name to the function sendEvent().
analytics.sendEvent(.buy)

🎨 Fine tuning

You can customize the names of events and parameters for different providers, according to the requirements of your analysts

func name(for provider: ProviderProxy) -> String {
    switch self {
    case .buy:
        switch provider {    
        case .cleverTap     : return "_Buy"
        case .google        : return "_User_Click_Buy_Button"
        case .amplitude     : return "ClickBuy"
        default             : return "buy"
        }
    }
}

You can choose which events to send to one and not send to another provider. For this, the function has been created getPermissionToSentEvent(_:from:for:)

// For example, such an implementation will prohibit sending the Appear_Order event to any provider.
func getPermissionToSentEvent(_ event: AnalyticsEventProtocol, from module: AnalyticsModuleProtocol?, for provider: ProviderProxy) -> Bool {
    guard let event = event as? Event, let module = module as? Module else { return false }
    if case event == .appear, case module == .order {
        return false
    }
    return true
}

// To allow dispatch of all events, just return true
func getPermissionToSentEvent (_ event: AnalyticsEventProtocol, from module: AnalyticsModuleProtocol?, for provider: ProviderProxy) -> Bool {
    return true
}
You might also like...
Minimalist library to manage one-off operations.

Once(简体中文) Once allows you to manage the number of executions of a task using an intuitive API. Highlight Safe Efficient Persistent Usage Token Token

🚘 A simple tool for updating Carthage script phase
🚘 A simple tool for updating Carthage script phase

Do you use Carthage? Are you feel tired of adding special script and the paths to frameworks (point 4, 5 and 6 in Getting Started guide) manually? Me

🌤 Swift Combine extensions for asynchronous CloudKit record processing

Swift Combine extensions for asynchronous CloudKit record processing. Designed for simplicity.

A Swift Encoder for encoding any Encodable value into an array of URLQueryItem.

URLQueryItemEncoder A Swift Encoder for encoding any Encodable value into an array of URLQueryItem. As part of the SE-0166, Swift has a foundation for

Parse iOS mobile provisioning files into Swift models

SwiftyProvisioningProfile This library provides a way to decode a .mobileprovision file into a Swift model. Installation The recommended installation

Handy Combine extensions on NSObject, including Set<AnyCancellable>.
Handy Combine extensions on NSObject, including SetAnyCancellable.

Storable Description If you're using Combine, you've probably encountered the following code more than a few times. class Object: NSObject { var c

Pigeon is a SwiftUI and UIKit library that relies on Combine to deal with asynchronous data.

Pigeon 🐦 Introduction Pigeon is a SwiftUI and UIKit library that relies on Combine to deal with asynchronous data. It is heavily inspired by React Qu

Use this package in order to ease up working with Combine URLSession.

Use this package in order to ease up working with Combine URLSession. We support working with Codable for all main HTTP methods GET, POST, PUT and DELETE. We also support MultipartUpload

Read iOS 15 privacy insight '.ndjson' file into your human brain.
Read iOS 15 privacy insight '.ndjson' file into your human brain.

Insight Read iOS 15 privacy insight '.ndjson' file into your human brain. Written in SwiftUI. Feature Compile records into app summary Relink app info

Comments
  • Change how providers are configured

    Change how providers are configured

    The bottom line is that for a provider, you can pass such a ProviderSettings property with which he “cannot work”

    It is required to do something like an initializer / structure - where would the available parameters for configuring the provider be contained in the method signature

    opened by johnnieWa1ker 0
  • Changed the method of registering providers

    Changed the method of registering providers

    Было:

    Можно было передать в массив settings любое доступное свойство, втч те, с которыми провайдер может работать (example: pushTokenCompletion для cleverTap)

    service.register(
        .cleverTap, with: [
            .accountId(cleverTapAccountId),
            .accountToken(cleverTapAccountToken),
            .networkReporting(true)
        ]
    )
    

    Стало:

    При передаче параметров через associated value однозначно понятно - какие параметры способен принимать тот или иной провайдер

    public enum ProviderSettings {
        case cleverTapSettings(accountId: String?, accountToken: String?, enableNetworkReporting: Bool?, deviceToken: Data?)
        ...
    }
    
    ...
    service.register(
        .cleverTap,
        with: .cleverTapSettings(
            accountId: cleverTapAccountId,
            accountToken: cleverTapAccountToken,
            enableNetworkReporting: true,
            deviceToken: nil
        )
    )
    
    opened by johnnieWa1ker 0
Owner
Broniboy
Rapidly fast last mile delivery service
Broniboy
A simple shake-one-shake, Convenient for us to integrate the shake-one-shake.

MGSwiftShaker Example To run the example project, clone the repo, and run pod install from the Example directory first.

null 3 Nov 21, 2021
Testable Combine Publishers - An easy, declarative way to unit test Combine Publishers in Swift

Testable Combine Publishers An easy, declarative way to unit test Combine Publishers in Swift About Combine Publishers are notoriously verbose to unit

Albert Bori 6 Sep 26, 2022
Merges a given number of PDF files into one file using the PDFKit framework

Titanium iOS PDF Merge Merges a given number of PDF files into one file using the PDFKit framework Requirements iOS 11+ Titanium SDK 9+ API's Methods

Hans Knöchel 6 Jan 26, 2022
Swift APIs for getting book information from popular web services

Swift APIs for getting book information from popular web services

Brian Dewey 1 Sep 25, 2021
A NEWS app which can be used to read,share and bookmark articles of various categories

Scoop A NEWS App for iOS 14 built using Swift which allow the users to read,bookmark and share news articles. Built using MVC architecture Requirement

Sai Balaji 3 Oct 12, 2022
swift-highlight a pure-Swift data structure library designed for server applications that need to store a lot of styled text

swift-highlight is a pure-Swift data structure library designed for server applications that need to store a lot of styled text. The Highlight module is memory-efficient and uses slab allocations and small-string optimizations to pack large amounts of styled text into a small amount of memory, while still supporting efficient traversal through the Sequence protocol.

kelvin 4 Aug 14, 2022
A simple Pokedex app written in Swift that implements the PokeAPI, using Combine and data driven UI.

SwiftPokedex SwiftPokedex is a simple Pokedex app written by Viktor Gidlöf in Swift that implements the PokeAPI. For full documentation and implementa

Viktor G 26 Dec 14, 2022
A framework to provide logic designed to prompt users at the ideal moment for a review of your app/software

ReviewKit ReviewKit is a Swift package/framework that provides logic designed to prompt users at the ideal moment for a review of your app. At a basic

Simon Mitchell 25 Jun 7, 2022
ETFKit - Designed to be a drop-in replacement for JSONDecoder/JSONEncoder

ETFKit Encoder/decoder for Erlang's External Term Format (version 131). Designed to be a drop-in replacement for JSONDecoder/JSONEncoder. Simply repla

Swiftcord 2 Jun 10, 2022
OwO.swift Badges go here in one line for the master branch ONLY.

OwO.swift Badges go here in one line for the master branch ONLY. Badges can also go in the header line. Short description describing the application/l

Spotlight 2 May 28, 2022