AWS Mobile Hub Developer Guide
Developer Guide

Add Analytics


The following content applies if you are already using the AWS Mobile CLI to configure your backend. If you are building a new mobile or web app, or you're adding cloud capabilities to your existing app, use the new AWS Amplify CLI instead. With the new Amplify CLI, you can use all of the features described in Announcing the AWS Amplify CLI toolchain, including AWS CloudFormation functionality that provides additional workflows.

Basic Analytics Backend is Enabled for Your App


The steps on this page assume you have already completed the steps on Get Started.

When you complete the AWS Mobile CLI setup and launch your app, anonymized session and device demographics data flows to the AWS analytics backend.

To send basic app usage analytics to AWS

Launch your app locally, for instance, if you created your app using create-react-native-app, by running:

npm run android # Or npm run ios

When you use your app the Amazon Pinpoint service gathers and visualizes analytics data.

To view the analytics using the Amazon Pinpoint console

  1. Launch your app at least once.

  2. Open your project in the AWS Mobile Hub console.

    awsmobile console
  3. Choose the Analytics icon on the left, to navigate to your project in the Amazon Pinpoint console.

  4. Choose Analytics on the left.

You should see an up-tick in several graphs.

Add Custom Analytics to Your App

You can configure your app so that Amazon Pinpoint gathers data for custom events that you register within the flow of your code.

To instrument custom analytics in your app

In the file containing the event you want to track, add the following import:

import { Analytics } from 'aws-amplify';

Add the a call like the following to the spot in your JavaScript where the tracked event should be fired:

componentDidMount() { Analytics.record('FIRST-EVENT-NAME'); }

Or to relevant page elements:

handleClick = () => { Analytics.record('SECOND-EVENT-NAME'); } <Button title="Record event" onPress={this.handleClick}/>

To test:

  1. Save the changes and launch your app. Use your app so that tracked events are triggered.

  2. In the Amazon Pinpoint console, choose Events near the top.

  3. Select an event in the Event dropdown menu on the left.

Custom event data may take a few minutes to become visible in the console.

Next Steps

Learn more about the analytics in AWS Mobile which are part of the Messaging and Analytics feature. This feature uses Amazon Pinpoint.

Learn about AWS Mobile CLI.

Learn about the AWS Amplify for React Native library.