Skip to content

Instantly share code, notes, and snippets.

@mobilequickie
Created August 31, 2018 23:13
Show Gist options
  • Save mobilequickie/cfa519c30886f1a2e06244ba0a1aee50 to your computer and use it in GitHub Desktop.
Save mobilequickie/cfa519c30886f1a2e06244ba0a1aee50 to your computer and use it in GitHub Desktop.
AnalyticsService Local
import Foundation
class LocalAnalyticsService : AnalyticsService {
init() {
print("LocalAnalyticsService: session-start")
}
func recordEvent(_ eventName: String, parameters: [String : String]?, metrics: [String : Double]?) {
var event = ""
if (parameters != nil) {
for (key, value) in parameters! {
event += ",\"\(key)\"=\"\(value)\""
}
}
if (metrics != nil) {
for (key, value) in metrics! {
let formattedValue = String(format:"%.2f", value)
event += ",\"\(key)=\(formattedValue)"
}
}
if (event.count > 0) {
event = String(event.dropFirst(1))
}
let df = DateFormatter()
df.dateFormat = "yyyy-MM-dd HH:mm:ss"
let currentTime = Date()
let dateString = df.string(from: currentTime)
print("\(dateString) \(eventName):\(event)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment