Skip to content

Instantly share code, notes, and snippets.

@mobilequickie
Created August 31, 2018 23:19
Show Gist options
  • Save mobilequickie/6039e81830256a5181054d017dc39c38 to your computer and use it in GitHub Desktop.
Save mobilequickie/6039e81830256a5181054d017dc39c38 to your computer and use it in GitHub Desktop.
AnalyticsService AWS
import Foundation
import AWSCore
import AWSPinpoint
class AWSAnalyticsService : AnalyticsService {
var pinpoint: AWSPinpoint?
init() {
let config = AWSPinpointConfiguration.defaultPinpointConfiguration(launchOptions: nil)
pinpoint = AWSPinpoint(configuration: config)
}
func recordEvent(_ eventName: String, parameters: [String : String]?, metrics: [String : Double]?) {
let event = pinpoint?.analyticsClient.createEvent(withEventType: eventName)
if (parameters != nil) {
for (key, value) in parameters! {
event?.addAttribute(value, forKey: key)
}
}
if (metrics != nil) {
for (key, value) in metrics! {
event?.addMetric(NSNumber(value: value), forKey: key)
}
}
pinpoint?.analyticsClient.record(event!)
pinpoint?.analyticsClient.submitEvents()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment