Created
August 31, 2018 23:19
-
-
Save mobilequickie/6039e81830256a5181054d017dc39c38 to your computer and use it in GitHub Desktop.
AnalyticsService AWS
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 | |
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