Analytics Module
Provider
The provider of choice is Firebase, which is free to use and provides both real time and persisted analytics events.
Additionally, Firebase via Google Analytics provides access to explorations, like:
- Funnel exploration
- Path exploration
- Free form
Using path explorations you are able to understand at what point of your app users are lost; with funnel explorations you can analyze sequential steps or stages that users go through while interacting with your app. Thse can be very useful for identifying conversion bottlenecks, optimizing user experience, A/B testing, and more.
Extra benefits
To make sure you are not ingesting your testing events, this class checks and avoids logging for:
- Events emitted by Simulator
- Events emitted by your testing device when in debug mode
Addionally, any logged event is automatically complemented with:
- A user session id (randomly generated)
- The user locale
- The app version
Setup
- Step 1. Head over to Firebase
- Step 2. Add a new project
- Step 3. Setup the newly created project:
- Select the app type to be iOS
- Fill up details (bundle identifier - can be found in Xcode or developer.apple.com, app id can be found on developer.apple.com under General > App Information > General Information)
- Step 4. Add Firebase SDK.
- In Xcode, File > Add Package Dependency > search for https://github.com/firebase/firebase-ios-sdk
- Add package might take a few minutes, it’s time to get some coffee
- Of the many options (Package Product) you only need a few, however there is a bug in Xcode that changes selection when scrolling, so add them all and we will clean this up in a later step
- Clean up: head over your target > under General (Frameworks, Libraries, and Embedded Content) remove all Firebase-prefixed dependencies except:
- FirebaseAnalytics
- FirebaseAnalyticsSwift
- Skip any initialization code from the Firebase documentation, we got you covered and just continue to Console
At this point you are all set. Remember, our Analytics module purposely omits logging from simulator and testing devices, so you will not see any real time events. However, if you launch your app on a real device and disconnect it from Xcode, you will see events populating.
Usage
Step 1. Initial Setup In your AppDelegate::didFinishLaunchingWithOptions just adds the following line: AppAnalytics.configureAnalytics()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
AppAnalytics.configureAnalytics()
return true
}
Step 2. Metric emissions Emit metrics from anywhere in your codebase by calling either one of the functions below:
AppAnalytics.logEvent(eventName)
AppAnalytics.logEvent(eventName, parameters: parameters)