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
var analyticsService: AnalyticsService? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
// Override point for customization after application launch. | |
// Initialize the analytics service | |
analyticsService = LocalAnalyticsService() | |
return true | |
} |
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
class MasterViewController: UITableViewController { | |
var analyticsService: AnalyticsService? = nil | |
override func viewDidLoad() { | |
super.viewDidLOad() | |
analyticsService = (UIApplication.shared.delegate as! AppDelegate).analyticsService | |
self.analyticsService?.recordEvent("loaded", parameters: ["op":"viewDidLoad"], metrics: nil) | |
} |
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
protocol AnalyticsService { | |
func recordEvent(_ eventName: String, parameters: [String:String]?, metrics: [String:Double]?) -> Void | |
} |
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 | |
class LocalAnalyticsService : AnalyticsService { | |
init() { | |
print("LocalAnalyticsService: session-start") | |
} | |
func recordEvent(_ eventName: String, parameters: [String : String]?, metrics: [String : Double]?) { | |
var event = "" | |
if (parameters != nil) { |
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
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 |
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) |
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
// Updated April 8 for iPad Mini 5th gen, iPad Air 3rd gen, and all Apple Watch to gen 4. | |
// Updated Oct 9 for iPhone XS, iPhone XS Max, and iPhone XR | |
// Call this from any class that needs it: let modelName = UIDevice.current.modelName | |
// More here: https://gist.github.com/adamawolf/3048717 | |
// Source of internal names came from this wiki: https://www.theiphonewiki.com/wiki/ | |
import UIKit | |
public extension UIDevice { | |
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
// Send custom model and platformVersion for this device to Amazon Pinpoint | |
func recordCustomProfileDemographics() { | |
let profile: AWSPinpointEndpointProfile = (pinpoint?.targetingClient.currentEndpointProfile())! | |
// Call our DeviceUtility class for readable Apple model type and iOS version for this device | |
profile.demographic?.model = UIDevice.current.modelName | |
profile.demographic?.platformVersion = UIDevice.current.systemVersion | |
pinpoint?.targetingClient.update(profile) | |
} |
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
{ | |
"ChannelType": "SMS", | |
"Address": "+12065551212", | |
"Demographic": { | |
"AppVersion": "1.0", | |
"Make": "apple", | |
"Model": "iPhone", | |
"ModelVersion": "iPhone X", | |
"Platform": "ios", | |
"PlatformVersion": "12.0", |
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
//Get the Amazon Pinpoint EndpointId from the device | |
let profile: AWSPinpointEndpointProfile = (pinpoint?.targetingClient.currentEndpointProfile())! | |
print("EndpointId: \(profile.endpointId)") |
OlderNewer