Created
September 4, 2018 20:28
-
-
Save adrianhall/f367fcc41c1cda73127bc662ab2dfab4 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
class AWSAnalyticsService(context: Context, service: AWSService, private val locationService: LocationService) : AnalyticsService { | |
/** | |
* Record a custom event into the analytics stream | |
* | |
* @param name the custom event name | |
* @param [attributes] a list of key-value pairs for recording string attributes | |
* @param [metrics] a list of key-value pairs for recording numeric metrics | |
*/ | |
override fun recordEvent(name: String, attributes: Map<String, String>?, metrics: Map<String, Double>?) { | |
// Add location to the endpoint | |
val endpoint = pinpoint.targetingClient.currentEndpoint() | |
endpoint.location.latitude = locationService.latitude | |
endpoint.location.longitude = locationService.longitude | |
pinpoint.targetingClient.updateEndpointProfile(endpoint) | |
// Work out what the preference | |
val event = pinpoint.analyticsClient.createEvent(name) | |
for ((k, v) in attributes.orEmpty()) { | |
event.addAttribute(k, v) | |
} | |
for ((k, v) in metrics.orEmpty()) { | |
event.addMetric(k, v) | |
} | |
pinpoint.analyticsClient.recordEvent(event) | |
pinpoint.analyticsClient.submitEvents() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment