Skip to content

Instantly share code, notes, and snippets.

@d-date
Last active March 20, 2017 05:29
Show Gist options
  • Save d-date/562d230fd4d833f238af9c0c7019ae79 to your computer and use it in GitHub Desktop.
Save d-date/562d230fd4d833f238af9c0c7019ae79 to your computer and use it in GitHub Desktop.
Example of using Firebase analytics
import Foundation
import Firebase
typealias FIRParamters = [String : NSObject]
protocol EventReportType {
var name: String { get }
var parameters: FIRParamters? { get }
func sendLog()
}
extension EventReportType {
var parameters: FIRParamters? { return nil }
func sendLog() {
FIRAnalytics.logEvent(withName: name, parameters: parameters)
}
}
struct EventReporter {
struct AppOpen: EventReportType {
let name = kFIREventAppOpen
}
struct SignUp: EventReportType {
enum Method: String {
case phone = "phone"
case mail = "mail"
}
let name = kFIREventSignUp
var parameters: FIRParamters? {
var dic = FIRParamters()
dic[kFIRParameterSignUpMethod] = signupMethod.rawValue as NSObject
return dic
}
let signupMethod: Method
}
struct SelectContent: EventReportType {
let name = kFIREventSelectContent
var parameters: FIRParamters? {
var dic = FIRParamters()
if let type = contentType {
dic[kFIRParameterContentType] = type as NSObject
}
if let id = itemID {
dic[kFIRParameterItemID] = id as NSObject
}
return dic
}
let contentType: String?
let itemID: String?
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment