

# Migrating from Amazon Mobile Analytics to Amazon Pinpoint
<a name="migrate"></a>

On April 30, 2018, the features of Amazon Mobile Analytics were migrated to Amazon Pinpoint.

As with Mobile Analytics, you can use Amazon Pinpoint to measure app usage and revenue. Amazon Pinpoint adds more analytics capabilities by allowing you to segment users based on your data. You can also run targeted messaging campaigns through push notifications, email, and SMS to increase user engagement. For more information, see [Amazon Pinpoint](https://aws.amazon.com/pinpoint/).

With Amazon Pinpoint, you can also export your data in real time through [Amazon Data Firehose](https://aws.amazon.com/kinesis), which provides additional features to transform, encrypt, and deliver raw analytics data. With Firehose *delivery streams*, you can choose various destinations for your data like Amazon Simple Storage Service (Amazon S3), Amazon Redshift, or Amazon OpenSearch Service. 

If you're new to Mobile Analytics, use Amazon Pinpoint instead. If you're currently using Mobile Analytics, migrate from Mobile Analytics to Amazon Pinpoint by April 30, 2018. Your existing Mobile Analytics apps are supported by Amazon Pinpoint, but certain Mobile Analytics workflows require you to switch to the corresponding Amazon Pinpoint features:


| Workflow | Migration details | 
| --- | --- | 
|  Mobile Analytics REST API for events submission  |  Is automatically redirected to the Amazon Pinpoint API. No action is required.  | 
|  Mobile Analytics in the AWS Mobile SDKs.  |  Is supported via Amazon Pinpoint in the AWS Mobile SDKs or JavaScript library. Versions of the Mobile Analytics client in the SDKs will continue to report events, but with limited support for issues. See [Migrating to Amazon Pinpoint in the AWS Mobile SDKs or JavaScript Library](migrate-sdk.md).  | 
|  Mobile Analytics console  |  Is replaced by the Amazon Pinpoint console. See [Migrating to the Amazon Pinpoint Console](migrate-console.md).  | 
|  Mobile Analytics querying API  |  Isn't available after April 30, 2018. You can calculate Mobile Analytics KPIs from raw data from event streams.  | 

**Topics**
+ [Migrating to Amazon Pinpoint in the AWS Mobile SDKs or JavaScript Library](migrate-sdk.md)
+ [Migrating to the Amazon Pinpoint API](migrate-api.md)
+ [Migrating to the Amazon Pinpoint Console](migrate-console.md)

# Migrating to Amazon Pinpoint in the AWS Mobile SDKs or JavaScript Library
<a name="migrate-sdk"></a>

After April 30, 2018, the Amazon Mobile Analytics client in the AWS Mobile SDKs will no longer be updated, and support for existing versions of the client will no longer be offered.

If you're currently using Mobile Analytics with the AWS Mobile SDKs, your apps will continue to report events to Mobile Analytics after this date. This event data will be visible in the Amazon Pinpoint console. However, we strongly recommend that you switch to the Amazon Pinpoint analytics features in the latest AWS Mobile SDKs or JavaScript library, which offer matching functionality. By migrating, you help ensure that you're able to use the latest features and that you receive support for any issues.

Use the steps in this section to migrate your Mobile Analytics app so that it uses Amazon Pinpoint through one of the following:
+ The AWS Mobile SDK for Android
+ The AWS Mobile SDK for iOS
+ The AWS Amplify JavaScript library

If your app currently uses Mobile Analytics through the AWS Mobile SDKs for Unity or Xamarin, you can continue to use these SDKs without migrating until they support Amazon Pinpoint.

To migrate, you use AWS Mobile Hub or the AWS Mobile CLI to:
+ Integrate the latest AWS Mobile SDK or JavaScript library with your app.
+ Create the resources that your app requires to communicate with Amazon Pinpoint.

Then, you customize your app's configuration and IAM permissions so that it reports analytics data to the Amazon Pinpoint project that matches your Mobile Analytics app.

**Topics**
+ [Step 1: Look Up Your Project ID](#migrate-sdk-lookup-id)
+ [Step 2: Integrate SDKs or JavaScript Library](#migrate-sdk-integrate)
+ [Step 3: Enable Analytics](#migrate-sdk-analytics)
+ [Step 4: Delete the Project That Mobile Hub Created](#migrate-sdk-delete-mh-project)
+ [Step 5: Update Your App Configuration](#migrate-sdk-config)
+ [Step 6: Update the IAM Role](#migrate-sdk-app-id-in-iam-role)
+ [Step 7: Build and Test](#migrate-sdk-build-and-test)

## Step 1: Look Up Your Project ID
<a name="migrate-sdk-lookup-id"></a>

The projects that are listed in the Amazon Pinpoint console include the apps that you defined in Mobile Analytics. Look up the project ID for the app that you're migrating. You'll use it in later steps when you customize your app's configuration and IAM permissions.

1. Sign in to the AWS Management Console and open the Amazon Pinpoint console at [https://console.aws.amazon.com/pinpoint/](https://console.aws.amazon.com/pinpoint/).

1. On the **Projects** page, find the app that you're migrating, and note the value in the **ID** column.

## Step 2: Integrate the AWS Mobile SDK or JavaScript Library
<a name="migrate-sdk-integrate"></a>

To connect to Amazon Pinpoint from your app, integrate the AWS Mobile SDK or JavaScript library with your code. 

### For Android or iOS Apps
<a name="migrate-sdk-integrate-android-ios"></a>

For Android or iOS apps, integrate the AWS Mobile SDK for Android or iOS. To integrate, see [Get Started (Android and iOS)](https://docs.aws.amazon.com/aws-mobile/latest/developerguide/getting-started.html) in the *AWS Mobile Developer Guide*. This topic helps you:
+ Create a project with Mobile Hub. The **Messaging & Analytics** feature is enabled by default.
+ Connect your app to the backend AWS resources that Mobile Hub provisions.
+ Integrate the AWS Mobile SDK for Android or iOS with your app.

### For JavaScript Apps
<a name="migrate-sdk-integrate-js"></a>

For web or mobile JavaScript apps, integrate the AWS Amplify library. To integrate, see [Get Started (Web)](https://docs.aws.amazon.com/aws-mobile/latest/developerguide/web-getting-started.html) or [Get Started (React Native)](https://docs.aws.amazon.com/aws-mobile/latest/developerguide/react-native-getting-started.html) in the *AWS Mobile Developer Guide*. These topics help you:
+ Use the AWS Mobile CLI to create a project. Analytics and web hosting are enabled by default.
+ Create backend AWS resources for your app.
+ Connect your app to the backend resources.
+ Integrate the AWS Amplify library with your app.

## Step 3: Enable Amazon Pinpoint Analytics
<a name="migrate-sdk-analytics"></a>

Now that you've integrated the latest version of the AWS Mobile SDK or JavaScript library, you can submit analytics events by using Amazon Pinpoint instead of Mobile Analytics.

### For Android or iOS Apps
<a name="migrate-sdk-analytics-android-ios"></a>

To update your Android or iOS app, see [Add Analytics to your Mobile App with Amazon Pinpoint](https://docs.aws.amazon.com/aws-mobile/latest/developerguide/add-aws-mobile-analytics.html) in the *AWS Mobile Developer Guide*.

### For JavaScript Apps
<a name="migrate-sdk-analytics-js"></a>

To update your JavaScript app, see [Add Analytics (Web)](https://docs.aws.amazon.com/aws-mobile/latest/developerguide/web-add-analytics.html) or [Add Analytics (React Native)](https://docs.aws.amazon.com/aws-mobile/latest/developerguide/react-native-add-analytics.html) in the *AWS Mobile Developer Guide*.

## Step 4: Delete the Amazon Pinpoint Project That Mobile Hub Created
<a name="migrate-sdk-delete-mh-project"></a>

When you created a project in Mobile Hub, a corresponding project was automatically created in Amazon Pinpoint. You aren't using this Amazon Pinpoint project. Instead, you're using the project that matches your original Mobile Analytics app.

1. Open the Amazon Pinpoint console at [https://console.aws.amazon.com/pinpoint/](https://console.aws.amazon.com/pinpoint/).

1. On the **Projects** page, find the project that was created by Mobile Hub. It's named as *mobilehubprojectname*\$1MobileHub.

1. Copy the project ID.

1. Use a terminal to delete the project with the following AWS CLI command:

   ```
   $ aws pinpoint delete-app --application-id project-id
   {
       "ApplicationResponse": {
           "Id": "d2b352520bcc4f5492ddbd7ef05f9147",
           "Name": "amamigrationdocstest_MobileHub"
       }
   }
   ```

   The project is removed from Amazon Pinpoint.

## Step 5: Update the App ID in Your App Configuration
<a name="migrate-sdk-config"></a>

Customize the default configuration for your app so that it reports analytics data to the Amazon Pinpoint project for your Mobile Analytics app.

### For Android or iOS Apps
<a name="migrate-sdk-config-android-ios"></a>

Your app now includes a cloud configuration file that connects it to the backend resources that Mobile Hub creates. After you update the app ID in the file, your app sends analytics data to the Amazon Pinpoint project for your Mobile Analytics app.

1. In your app package, open the `awsconfiguration.json` file.

1. In the `PinpointAnalytics` object, replace the value for `AppID` with the ID that you got from the Amazon Pinpoint console.

   ```
   . . .
   "PinpointAnalytics": {
     "Default": {
       "AppId": "app-id",
       "Region": "us-east-1"
     }
   },
   . . .
   ```

### For JavaScript Apps
<a name="migrate-sdk-config-js"></a>

Configure the AWS Amplify Analytics module in your app code so that your app reports analytics data to the Amazon Pinpoint project for your Mobile Analytics app.

To update your app code, see the [Manual Setup](https://aws.github.io/aws-amplify/media/analytics_guide#manual-setup) instructions for the Analytics module in the AWS Amplify documentation. In the configuration code, for the `appID` parameter, use the ID that you got from the Amazon Pinpoint console.

## Step 6: Update the App ID in the IAM Role
<a name="migrate-sdk-app-id-in-iam-role"></a>

When you created a project by using Mobile Hub or the AWS Mobile CLI, an IAM role was created in your AWS account. This role includes a policy that allows your app to report events and update endpoints with Amazon Pinpoint. The role includes the project ID for your Mobile Hub project. Update this ID so that your app can communicate with the Amazon Pinpoint project for your Mobile Analytics app.

1. Open the Mobile Hub console at [https://console.aws.amazon.com/mobilehub/](https://console.aws.amazon.com/mobilehub/).

1. Choose the project that you created.

1. At the top-right of the console, choose **Resources**.

1. Under **AWS Identity and Access Management Roles**, the console shows the IAM role that was provisioned in your AWS account. Choose the role. 

   The IAM console opens, and the **Roles** page is shown.

1. Under **Permissions**, expand the policy named as *project-name*\$1mobileanalytics\$1MOBILEHUB\$1*mobile-hub-project-id*.

1. Choose **Edit policy**.

1. On the **Edit** page, choose the **JSON** tab.

1. In the JSON editor, where the policy allows the `mobiletargeting:UpdateEndpoint` action, update the value that's assigned to the `Resource` key. Change the app ID to the ID that you got from the Amazon Pinpoint console.

   ```
   . . .
   {
       "Effect": "Allow",
       "Action": [
           "mobiletargeting:UpdateEndpoint"
       ],
       "Resource": [
           "arn:aws:mobiletargeting:*:123456789012:apps/app-id*"
       ]
   }
   . . .
   ```
**Important**  
Remember to keep the wildcard character (`*`) following the app ID.

1. Choose **Review policy**, and then choose **Save changes**.

## Step 7: Build and Test
<a name="migrate-sdk-build-and-test"></a>

Now that you've integrated the latest AWS Mobile SDK or JavaScript library, and have updated your app code, your app reports events to Amazon Pinpoint. As Amazon Pinpoint receives events, it updates the charts on the **Analytics** pages in the console.

1. Build your updated app, and run it on a test device or emulator.

1. Launch your app, and perform other actions in your app that cause it to report events to Amazon Pinpoint.

1. Open the Amazon Pinpoint console at [https://console.aws.amazon.com/pinpoint/](https://console.aws.amazon.com/pinpoint/).

1. On the **Projects** page, choose the project for your app.

1. In the navigation menu, choose **Analytics**.

1. Check the charts to verify whether Amazon Pinpoint is showing the analytics that you expect. For example, the **Sessions** chart indicates how many times you open the app, and the **New endpoints** chart indicates how many test devices or emulators launch the app for the first time. Custom events are shown on the **Events** page. Allow up to 15 minutes for the charts to display an event.

# Migrating to the Amazon Pinpoint API
<a name="migrate-api"></a>

After April 30, 2018, the Mobile Analytics REST API will automatically redirect requests to the Amazon Pinpoint API. Events that your application reports to Mobile Analytics are automatically sent to Amazon Pinpoint.

## Migrating Off of the Mobile Analytics Querying API
<a name="migrate-api-query"></a>

After April 30, 2018, the Mobile Analytics Querying API will no longer be supported. Amazon Pinpoint offers an event streams feature that lets you stream events data in real time to Amazon Kinesis Data Streams or Amazon Data Firehose. Through a Firehose delivery stream, this data can be delivered to Amazon Redshift, Amazon S3, or Amazon OpenSearch Service. You can then access the data and use it to calculate the KPIs that are provided by the Querying API. 

### KPI Metrics Based on Event Data
<a name="migrate-api-query-kpis"></a>

Use the following table for guidance when you're calculating KPI metrics that are based on the event data that's streamed by Amazon Pinpoint.


| Metric | Mobile Analytics KPI | How to calculate with Amazon Pinpoint events | 
| --- | --- | --- | 
| Lifetime user count |  `/kpis/new-users/lifetime-count`  |  Obtain the total unique number of `client_id` values.  | 
|  Daily active users (DAU)  |  `/kpis/dau/count`  |  For each day, obtain the count of events that have an `event_type` of `_session.start` and a unique value for `client_id`.  | 
|  Monthly active users (MAU)    |  `/kpis/mau/count`  |  For each 30-day interval, obtain the count of events that have an `event_type` of `_session.start` and a unique value for `client_id`.  | 
| New users |  `/kpis/new-users/count`  |  For each day, obtain the count of events that have an `event_type` of `_session.start` and a value for `client_id` that wasn't reported previously.  | 
| Session count |  `/kpis/sessions/count`  |  For each day, obtain the count of events that have an `event_type` of `_session.start`.  | 
| Daily revenue |  `/kpis/daily-revenue/sum`  |  For each day, obtain the events that have an `event_type` of `_monetization.purchase`, and compute the sum of the values that are reported for the `_item_price` attribute.  | 
|  Paying daily active users (PDAU)  |  `/kpis/pdau/count`  |  For each day, calculate the DAU metric, but include only those devices that have made one or more purchases in the past. A purchase is indicated by an `event_type` of `_monetization.purchase`.  | 
| Paying monthly active users (PMAU) |  `/kpis/pmau/count`  |  For each day, calculate the MAU metric, but include only those devices that have made one or more purchases in the past. A purchase is indicated by an `event_type` of `_monetization.purchase`.  | 
| Custom events count |  `/events/custom-event-name/count`  |  For each day, obtain the count of events that have an `event_type` that matches the name you that you assigned to the custom event. Calculate max, min, and sum values by parsing the values that are assigned to metrics and custom attributes.   | 
|  Week 1, week 2, and week 3 retention  |  `/kpis/week-1-retention/count` `/kpis/week-2-retention/count` `/kpis/week-3-retention/count`  |  To calculate the retention for a specific day: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/mobileanalytics/latest/ug/migrate-api.html)  | 
|  Day 1, day 3, day 5, and day 7 retention  |  `/kpis/day-1-retention/count` `/kpis/day-3-retention/count` `/kpis/day-5-retention/count` `/kpis/day-7-retention/count`  |  To calculate the retention for a specific day: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/mobileanalytics/latest/ug/migrate-api.html)  | 

### Example Events
<a name="migrate-api-query-example-events"></a>

The following examples demonstrate the JSON attributes that you can parse when you query the data store that holds your event data.

**Example Session Start Event**  

```
{
  "application_key": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
  "account_id": "111122223333",
  "event_type": "_session.start",
  "timestamp": 1517537724812,
  "arrival_timestamp": 1517537778048,
  "unique_id": "A1B2C3D4-E5F6-G7H8-I9J0-K1L2M3N4O5P6",
  "cognito_id": "us-east-1:a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6",
  "cognito_identity_pool_id": "us-east-1:a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6",
  "platform": "iOS",
  "model": "iPhone",
  "platform_version": "11.2.2",
  "make": "apple",
  "locale": "en_US",
  "sdk_version": "2.4.16",
  "sdk_name": "aws-sdk-iOS",
  "app_package_name": "com.example.package",
  "app_version_name": "11.02.0",
  "app_version_code": "28198.0",
  "user_agent": "aws-sdk-iOS/2.4.16 iOS/11.2.2 en_US",
  "app_title": "ExampleApp",
  "attributes": {
    "_clientContext": <client context>,
    "_session.id": "70cf4faf-BAAABA8A-20180202-021524806",
    "_session.startTime": "1517537724811"
  },
  "metrics": {}
}
```

**Example Monetization Event**  

```
{
  "application_key": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
  "account_id": "111122223333",
  "event_type": "_monetization.purchase",
  "timestamp": 1517537662978,
  "arrival_timestamp": 1517537778020,
  "unique_id": "A1B2C3D4-E5F6-G7H8-I9J0-K1L2M3N4O5P6",
  "cognito_id": "us-east-1:a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6",
  "cognito_identity_pool_id": "us-east-1:a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6",
  "platform": "iOS",
  "model": "iPhone",
  "platform_version": "11.2.5",
  "make": "apple",
  "locale": "zh_CN",
  "sdk_version": "2.6.5",
  "sdk_name": "aws-sdk-iOS",
  "app_package_name": "com.example.package",
  "app_version_name": "5.03",
  "app_version_code": "5.03.1",
  "user_agent": "aws-sdk-iOS/2.6.5 iOS/11.2.5 zh_CN",
  "app_title": "ExampleApp",
  "attributes": {
    "_currency": "CNY",
    "_product_id": "product_id",
    "_transaction_id": "123456789012345",
    "_clientContext": <client context>,
    "_session.duration": "152021",
    "_session.id": "e79da94c-9BD1DF63-20180202-021345277",
    "_session.startTime": "1517537625277",
    "_item_price_formatted": "¥128.00"
  },
  "metrics": {
    "_item_price": 76.5811965811966,
    "_quantity": 1.0
  }
}
```

In these examples, *<client context>* is the `x-amz-client-context` request header that you provide when you submit a `PutEvents` request to the Mobile Analytics REST API. For more information, see [PutEvents](PutEvents.md).

# Migrating to the Amazon Pinpoint Console
<a name="migrate-console"></a>

After April 30, 2018, the Mobile Analytics console will automatically redirect to the [Amazon Pinpoint](https://console.aws.amazon.com/pinpoint) console. After this date, the Amazon Pinpoint console will also show all data from apps that report events using the Mobile Analytics client in the AWS Mobile SDKs. In addition to analytics reports, the Amazon Pinpoint console offers functionality to create user segments and set up targeted messaging campaigns. Your campaigns can message your audience through channels for email, mobile push, and SMS. After you launch a campaign, you can monitor its performance through campaign analytics.