Skip to content

Instantly share code, notes, and snippets.

@adrianhall
Created September 4, 2018 20:28
Show Gist options
  • Save adrianhall/f367fcc41c1cda73127bc662ab2dfab4 to your computer and use it in GitHub Desktop.
Save adrianhall/f367fcc41c1cda73127bc662ab2dfab4 to your computer and use it in GitHub Desktop.
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