Created
August 30, 2018 21:10
-
-
Save adrianhall/671ca77be3b8229a857c193b00f762a7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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