Created
August 31, 2018 23:13
-
-
Save mobilequickie/cfa519c30886f1a2e06244ba0a1aee50 to your computer and use it in GitHub Desktop.
AnalyticsService Local
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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