AWS Mobile
Developer Guide

Add Analytics to your Mobile App with Amazon Pinpoint


Gather the data that helps improve your app's usability, monetization, and engagement with your users. Mobile Hub deploys your analytics backend when you enable the Messaging and Analytics feature, which uses the Amazon Pinpoint service.

Set up your Backend

  1. Complete the Get Started steps before your proceed.

  2. When you create a project, we enable analytics by default in your backend. You should see a green check mark present on the Analytics tile in your backend, indicating that the feature is enabled. If the check mark is absent, choose Analytics, and then choose Enable.

Connect to your Backend

Use the following steps to add analytics to your mobile app through AWS Pinpoint.

Android - JavaiOS - Swift
Android - Java
  1. Set up AWS Mobile SDK components with the following Basic Backend Setup steps.

    1. app/build.gradle must contain:

      dependencies{ compile 'com.amazonaws:aws-android-sdk-pinpoint:2.6.+' }
  2. Instrument your app to provide basic session data for Amazon Pinpoint analytics. The Amazon Pinpoint SDK gives you full control of when your sessions are started and stopped. Your app must explicitly start and stop the sessions. The following example shows one way to handle this by instrumenting a public class that extends MultidexApplication. StartSession() is called during the OnCreate event.

    1. Add the following to app/build.gradle:

      android { defaultConfig { ... multiDexEnabled = true } }
    2. Add the following to the dependencies section of app/build.gradle:

      compile ''
    3. Add the following to AndroidManifest.xml:

      <application .. android:theme="@style/AppTheme" android:name="com.YourApplication.Application"> .. </application>
    4. Add the following to your activity:

      //. . . import com.amazonaws.mobileconnectors.pinpoint.PinpointManager; import com.amazonaws.mobileconnectors.pinpoint.PinpointConfiguration; //. . . public class MainActivity extends AppCompatActivity { public static PinpointManager pinpointManager; @Override public void onCreate() { super.onCreate(); PinpointConfiguration pinpointConfig = new PinpointConfiguration( getApplicationContext(), AWSMobileClient.getInstance().getCredentialsProvider(), AWSMobileClient.getInstance().getConfiguration()); pinpointManager = new PinpointManager(pinpointConfig); // Start a session with Pinpoint pinpointManager.getSessionClient().startSession(); // Stop the session and submit the default app started event pinpointManager.getSessionClient().stopSession(); pinpointManager.getAnalyticsClient().submitEvents(); } }
iOS - Swift
  1. Set up AWS Mobile SDK components with the following Basic Backend Setup steps.

    1. The Podfile that you configure to install the AWS Mobile SDK must contain:

      platform :ios, '9.0' target :'YourAppName' do use_frameworks! pod 'AWSPinpoint', '~> 2.6.13' # other pods end

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

    2. Classes that call Amazon Pinpoint APIs must use the following import statements:

      import AWSCore import AWSPinpoint
    3. Insert the following code into the didFinishLaunchwithOptions method of your app's AppDelegate.swift.

      class AppDelegate: UIResponder, UIApplicationDelegate { var pinpoint: AWSPinpoint? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { //. . . // Initialize Pinpoint pinpoint = AWSPinpoint(configuration: AWSPinpointConfiguration.defaultPinpointConfiguration(launchOptions: launchOptions)) //. . . } }

Build and run your app to see usage metrics in Amazon Pinpoint.

  1. To see visualizations of the analytics coming from your app, open your project in the Mobile Hub console.

  2. Choose Analytics on the upper right to open the Amazon Pinpoint console.

            |AMH| console link to your project in the Amazon Pinpoint console.
  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.

Learn more about Amazon Pinpoint.

Enable Custom App Analytics

Instrument your code to capture app usage event information, including attributes you define. Use graphs of your custom usage event data in the Amazon Pinpoint console. Visualize how your users' behavior aligns with a model you design using Amazon Pinpoint Funnel Analytics, or use stream the data for deeper analysis.

Use the following steps to implement Amazon Pinpoint custom analytics for your app.

Android - JavaiOS - Swift
Android - Java
import; public void logEvent() { pinpointManager.getSessionClient().startSession(); final AnalyticsEvent event = pinpointManager.getAnalyticsClient().createEvent("EventName") .withAttribute("DemoAttribute1", "DemoAttributeValue1") .withAttribute("DemoAttribute2", "DemoAttributeValue2") .withMetric("DemoMetric1", Math.random()); pinpointManager.getAnalyticsClient().recordEvent(event); pinpointManager.getSessionClient().stopSession(); pinpointManager.getAnalyticsClient().submitEvents(); }
iOS - Swift
func logEvent() { let pinpointAnalyticsClient = AWSPinpoint(configuration: AWSPinpointConfiguration.defaultPinpointConfiguration(launchOptions: nil)).analyticsClient let event = pinpointAnalyticsClient.createEvent(withEventType: "EventName") event.addAttribute("DemoAttributeValue1", forKey: "DemoAttribute1") event.addAttribute("DemoAttributeValue2", forKey: "DemoAttribute2") event.addMetric(NSNumber.init(value: arc4random() % 65535), forKey: "EventName") pinpointAnalyticsClient.record(event) pinpointAnalyticsClient.submitEvents() }

Build, run, and try your app, and then view your custom events in the Events tab of the Amazon Pinpoint console (use your Mobile Hub project / Analytics > Amazon Pinpoint console / Analytics > Events). Look for the name of your event in the Events dropdown menu.

Enable Revenue Analytics

Amazon Pinpoint supports the collection of monetization event data. Use the following steps to place and design analytics related to purchases through your app.

Android - JavaiOS - Swift
Android - Java
import; public void logMonetizationEvent() { pinpointManager.getSessionClient().startSession(); final AnalyticsEvent event = AmazonMonetizationEventBuilder.create(pinpointManager.getAnalyticsClient()) .withFormattedItemPrice("$10.00") .withProductId("DEMO_PRODUCT_ID") .withQuantity(1.0) .withProductId("DEMO_TRANSACTION_ID").build(); pinpointManager.getAnalyticsClient().recordEvent(event); pinpointManager.getSessionClient().stopSession(); pinpointManager.getAnalyticsClient().submitEvents(); }
iOS - Swift
func sendMonetizationEvent() { let pinpointClient = AWSPinpoint(configuration: AWSPinpointConfiguration.defaultPinpointConfiguration(launchOptions: nil)) let pinpointAnalyticsClient = pinpointClient.analyticsClient let event = pinpointAnalyticsClient.createVirtualMonetizationEvent(withProductId: "DEMO_PRODUCT_ID", withItemPrice: 1.00, withQuantity: 1, withCurrency: "USD") pinpointAnalyticsClient.record(event) pinpointAnalyticsClient.submitEvents() }