Skip to content

Instantly share code, notes, and snippets.

View adrianhall's full-sized avatar

Adrian Hall adrianhall

View GitHub Profile
/**
* Where the preferences are stored on the system
*/
private val preferencesFile: String
get() = "${this::class.java.simpleName}.prefs"
/**
* The name of the custom attribute
*/
private val categoriesAttributeName = "categories"
/**
* Record a successful authentication
*
* @param username the username of the user that was authenticated
*/
override fun recordSuccessfulLogin(username: String) {
// Update the endpoint profile to include the username
val profile = pinpoint.targetingClient.currentEndpoint()
profile.user.userId = username
pinpoint.targetingClient.updateEndpointProfile(profile)
import android.content.Context
import com.amazonaws.mobile.auth.core.IdentityManager
import com.amazonaws.mobile.config.AWSConfiguration
import com.amazonaws.mobile.samples.picturefeed.services.AnalyticsService
import com.amazonaws.mobileconnectors.pinpoint.PinpointConfiguration
import com.amazonaws.mobileconnectors.pinpoint.PinpointManager
class AWSAnalyticsService(context: Context): AnalyticsService {
private var manager: PinpointManager? = null
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
dependencies {
implementation 'com.amazonaws:aws-android-sdk-pinpoint:2.6.27'
implementation ('com.amazonaws:aws-android-sdk-mobile-client:2.6.27@aar') { transitive = true }
}
class LocalAnalyticsService : AnalyticsService {
override fun recordEvent(eventName: String, attributes: Map<String,String>?, metrics: Map<String,Double>?) {
val event = StringBuilder("")
attributes?.let {
for ((k, v) in it) { event.append(", $k=\"$v\"") }
}
metrics?.let {
for ((k, v) in it) { event.append(", $k=${String.format("%.2f",v)}") }
}
if (event.isNotEmpty())
interface AnalyticsService {
fun recordEvent(eventName: String, attributes: Map<String,String>? = null, metrics: Map<String,Double>? = null)
}
import Foundation
import AWSCore
import AWSPinpoint
class AWSAnalyticsService : AnalyticsService {
var pinpoint: AWSPinpoint?
init() {
let config = AWSPinpointConfiguration.defaultPinpointConfiguration(launchOptions: nil)
pinpoint = AWSPinpoint(configuration: config)
target 'MyNotes' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Analytics dependency
pod 'AWSPinpoint'
end
class MasterViewController: UITableViewController {
var analyticsService: AnalyticsService? = nil
override func viewDidLoad() {
super.viewDidLOad()
analyticsService = (UIApplication.shared.delegate as! AppDelegate).analyticsService
// Rest of initialization here
// Record the view load