Swiftlytics
Getting started
To run the example project, clone the repo, and run pod install
from the Example directory first.
Declare a (global) instance of MultiAnalyticsProvider
import Swiftlytics
let swiftlytics: AnalyticsProvider = MultiAnalyticsProvider(providers: [
FirebaseAnalyticsProvider(priority: 3), //requires GoogleServices.info
FacebookAnalyticsProvider(priority: 2),
AppsFlyerAnalyticsProvider(priority: 1, devKey: "YOUR_DEV_KEY", appId: "YOUR_APP_ID")
])
Pass AppDelegate lifecycle events to your instance
See Example/Swiftlytics/AppDelegate.swift
Define your event
struct MemoryWarningEvent: AnalyticsEventConvertible {
let name = "memory_warning"
let count: UInt
}
Track your event
...
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
count += 1
swiftlytics.trackEvent(MemoryWarningEvent(count: count))
}
Track user properties to qualify events
swiftlytics.setUserId(UUID().uuidString) // your persistent database value in production
swiftlytics.setUserProperty(name: "name", withValue: "Sandy")
Requirements
Tested on Xcode 9.4.1, Swift 4, Cocoapods 1.5.3
Installation
Swiftlytics is available through CocoaPods, and is split into subspecs to avoid bloat from providers that you do not wish to integrate. To install it, simply add the following line to your Podfile:
pod 'Swiftlytics'
pod 'Swiftlytics/Firebase'
pod 'Swiftlytics/AppsFlyer'
pod 'Swiftlytics/Facebook'
Contributing- adding a new provider
Add an entry to Swiftlytics.podspec
s.subspec 'AppsFlyer' do |appsflyer|
appsflyer.source_files = 'Swiftlytics/AppsFlyer/**/*'
appsflyer.dependency 'AppsFlyerFramework'
end
Define a new AnalyticsProvider, implementing all protocol methods
See Swiftlytics/AppsFlyer/AppsFlyerAnalyticsProvider for an example
Add any tests to the Example project
Be sure to import the subspec in Example/Podfile, e.g.:
pod 'Swiftlytics/Facebook', :path => '../'
and then pod install
License
Swiftlytics is available under the MIT license. See the LICENSE file for more info.