Getting started

You are currently viewing the AWS SDK for Mobile documentation which is a collection of low-level libraries. Use the Amplify libraries for all new app development. Learn more

You can view the Mobile SDK API reference here.

Collecting analytics data for your app can be accomplished with Amazon Pinpoint or Amazon Kinesis.

Amazon Pinpoint is a fully managed AWS service that you can use to engage with your customers across multiple messaging channels using analytics captured from the device. You can send push notifications, emails, or text messages (SMS), depending on the purpose of your campaign. Features include:

Audience Segments - You can define dynamic segments based on data that's reported by your application, such as operating system or mobile device type. You can also import static segments that you define outside of Amazon Pinpoint.

Messaging Campaigns - A campaign sends tailored messages on a schedule that you define. You can create campaigns that send mobile push, email, or SMS messages. To experiment with alternative campaign strategies, set up your campaign as an A/B test, and analyze the results with Amazon Pinpoint analytics.

Transactional Messages - Keep your customers informed by sending transactional mobile push and SMS messages—such as new account activation messages, order confirmations, and password reset notifications—to specific users.

Analyze User Behavior - You can view trends about your users' level of engagement, purchase activity, and demographics. You can monitor your message traffic with metrics for messages sent and opened. Through the Amazon Pinpoint API, your application can report custom data, which Amazon Pinpoint makes available for analysis.

The Amplify CLI helps setup and configure Pinpoint within your application and connect with the AWS Mobile SDK.

Prerequisite: Install and configure the Amplify CLI

Set Up Your Backend

  1. Use the CLI to add analytics to your cloud-enabled backend and app.

    In a terminal window, navigate to your project folder (the folder contains your app .xcodeproj file), and add the SDK to your app.

    1cd YOUR_PROJECT_FOLDER
    2amplify add analytics
  2. When configuration for analytics is complete, a message appears confirming that you have configured local CLI metadata for this category. You can confirm this by viewing status.

    1$ amplify status
    2| Category | Resource name | Operation | Provider plugin |
    3| --------- | --------------- | --------- | ----------------- |
    4| Auth | cognitoabcd0123 | Create | awscloudformation |
    5| Analytics | yourprojectname | Create | awscloudformation |
  3. To create your backend AWS resources run the following:

    1amplify push

Manually Updating your IAM Policy:

Note The Amplify CLI adds the appropriate policies and permissions for you. The information provided here is provided if you are not using the Amplify CLI in your project.

The Amazon Pinpoint service requires permissions defined in an IAM policy to use the submitEvents API. If you are using long-term AWS credentials attached to an Amazon IAM user, attach the following policies to the role of that IAM user. If you are using temporary AWS credentials vended by Amazon Cognito Identity Pools, then attach the following policies to the Unauthenticated and/or Authenticated IAM roles of your Cognito Identity Pool. The role you attach the policies to depends on the scope of your application. For example, if you only want events submitted when users login, attach to the authenticated role. Similarly, if you want events submitted regardless of authentication state, attach the policy to the unauthenticated role. For more information on Cognito Identities authenticated/unauthenticated roles see here.

1{
2 "Version": "2012-10-17",
3 "Statement": [
4 {
5 "Effect": "Allow",
6 "Action": ["mobiletargeting:UpdateEndpoint", "mobiletargeting:PutEvents"],
7 "Resource": ["arn:aws:mobiletargeting:*:${accountID}:apps/${appId}*"]
8 }
9 ]
10}

Connect to Your Backend

Use the following steps to add analytics to your mobile app and monitor the results through Amazon Pinpoint.

Add Analytics

Set up AWS Mobile SDK components as follows.

  1. The Podfile that you configure to install the AWS Mobile SDK must contain:
1platform :ios, '9.0'
2target 'YourAppName' do
3 use_frameworks!
4
5 pod 'AWSPinpoint'
6 pod 'AWSMobileClient'
7
8 # other pods
9
10end

Run pod install --repo-update before you continue.

If you encounter an error message that begins [!] Failed to connect to GitHub to update the CocoaPods/Specs . . ., and your internet connectivity is working, you may need to update openssl and Ruby.

  1. Classes that call Amazon Pinpoint APIs must use the following import statements:
1/** start code copy **/
2import AWSPinpoint
3import AWSMobileClient
4/** end code copy **/
  1. To send events with Amazon Pinpoint, you'll instantiate a Pinpoint instance. We recommend you do this during app startup, so you can use Pinpoint to record app launch analytics. Edit the application(_:didFinishLaunchingWithOptions:) method of your app's AppDelegate.swift by adding a pinpoint instance property, and initializing the Pinpoint client as shown below:
1class AppDelegate: UIResponder, UIApplicationDelegate {
2
3 /** start code copy **/
4 var pinpoint: AWSPinpoint?
5 /** end code copy **/
6
7 func application(
8 _ application: UIApplication,
9 didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
10 ) -> Bool {
11
12 // Other didFinishLaunching code...
13
14 /** start code copy **/
15 // Create AWSMobileClient to connect with AWS
16 AWSMobileClient.default().initialize { (userState, error) in
17 if let error = error {
18 print("Error initializing AWSMobileClient: \(error.localizedDescription)")
19 } else if let userState = userState {
20 print("AWSMobileClient initialized. Current UserState: \(userState.rawValue)")
21 }
22 }
23
24 // Initialize Pinpoint
25 let pinpointConfiguration =
26 AWSPinpointConfiguration.defaultPinpointConfiguration(launchOptions: launchOptions)
27 pinpoint = AWSPinpoint(configuration: pinpointConfiguration)
28 /** end code copy **/
29 return true
30 }
31}

Monitor Analytics

Build and run your app to see usage metrics in Amazon Pinpoint. When you run the previous code samples, the console shows a logged Session.

  1. To see visualizations of the analytics coming from your app, open your project in the Amazon Pinpoint console by running the following:
1amplify console analytics
  1. Choose Analytics from the icons on the left of the console, and view the graphs of your app's usage. It may take up to 15 minutes for metrics to become visible.

    getting-started-analytics

Analytic events can be grouped into segments, allowing you to engage your users more deeply by tying their app usage behavior to push notification, email, or SMS messaging campaigns. Read more about this in the messaging section or click here to learn more about Amazon Pinpoint.