In this example, we'll adapt both Mixpanel and Google Analytics for Firebase. Let's have a look at how both look, and how to use them:
open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDelegate {
/* ... */
open func track(event: String?, properties: Properties? = nil) {
/* ... */
}
}
It is possible to use Mixpanel to track an event with additional properties:
Mixpanel.mainInstance()
.track(event: "Read Book",
properties: ["name": "Design Patterns with Swift",
"format": "paperback"])
Google Analytics for Firebase, however, exposes the tracking method through a static method from Objective-C:
NS_SWIFT_NAME(Analytics)
@interface FIRAnalytics : NSObject
/* ... */
+ (void)logEventWithName:(NSString *)name
parameters:(nullable NSDictionary<NSString *, id> *)parameters
NS_SWIFT_NAME(logEvent(_:parameters:));
/* ... */
@end
To use this library, you will have to use the following code:
Analytics.logEvent("Read Book",
parameters: ["name": "Design Patterns with Swift",
"format": "paperback"])