Front-End Web & Mobile
Adding User Analytics to Your Mobile App
Having a single cloud provider as the backend to your mobile app has many advantages. One of these advantages is the tight integration of features between two or more AWS Cloud services. In this blog post, we show the benefits from the recent Amazon Cognito integration with Amazon Pinpoint for user analytics. You can now seamlessly collect user attributes like email and phone number automatically upon sign-up, track real-time user sign-up and sign-in activity, and then immediately engage your authenticated mobile users via push notification, email, and SMS based on demographics and user activity.
Do you want to engage users with a “welcome” message upon sign-up? Now you can.
Do you want to contact a user after X number of failed sign-ins? By tracking sign-in failures, you can contact users with instructions for resetting their password or provide additional help to get them going again.
First, let’s explore why this integration is useful for tracking and engagement and then we walk through the steps you can take to enable and start tracking mobile user authentication activities.
What does this integration provide mobile developers?
After the integration, all mobile user sign-ups, sign-ins, and authentication failures through Amazon Cognito User Pools are tracked and aggregated by Amazon Pinpoint. In addition to user activity tracking, authenticated user attributes (such as user email and phone number) are collected by your app client upon sign-up and shared with Amazon Pinpoint. These user attributes allow you to immediately engage your authenticated users through SMS, email, and push notification channels in Amazon Pinpoint.
Let’s get started
This integration requires a few actions for tracking to start.
Requirements
- (Cloud) New or existing Amazon Cognito User Pool and Amazon Pinpoint app
- (Mobile client) AWS Mobile SDK for iOS or Android (Android 2.6.2+ or iOS version 2.6.3+)
Step #1 Create an Amazon Pinpoint application ID
If you already have an Amazon Pinpoint app, proceed to Step 2.
If you don’t have an Amazon Pinpoint application, create a new project in the AWS Mobile Hub console. When you create an AWS Mobile Hub project, an Amazon Pinpoint app is created by default.
Step #2 Update general settings in your Amazon Cognito user pool
Sign in to the Amazon Cognito console.
- Choose Manage your User Pools.
- Choose an existing user pool to edit or choose the Create a user pool button.
- Choose the Analytics tab from the left navigation pane.
- Choose Add analytics and campaigns.
- Choose an Amazon Cognito app client (1) and Amazon Pinpoint project (2) and select Share user profile data with Amazon Pinpoint. (3). Manually type a name for the IAM role to be created and choose Create role. Amazon Cognito creates a new IAM role, which allows Amazon Cognito to submit events to Amazon Pinpoint on your behalf. (4). Choose Save changes (5)
Step #3 Update AWS Mobile SDK for Android or iOS
Yes. Unfortunetely you DO need to update your AWS Mobile SDK for Android and iOS.
- Android v 2.6.2+
- iOS v 2.6.3+
Step #4 Add your Amazon Pinpoint application ID to the CognitoUserPool setting in the client configuration file
Update your backend service configuration file (awsconfiguration.json) in your mobile project by adding your Amazon Pinpoint AppId to the CognitoUserPool setting as shown. The syntax is the same for iOS and Android projects.
Note: This platform independent file is generated per project by AWS Mobile Hub and identifies all your cloud backend resources (endpoints and configuration) that is used by the AWS Mobile SDKs.
- [Android] AWS Mobile SDK for Android configuration.json file is under the res/raw folder in your Android Studio project.
- [iOS] AWS Mobile SDK for iOS configuration.json file is typically located in the same root folder as your info.plist in your Xcode project.
[awsconfiguration.json]
Now build the app in your IDE, launch the app, and sign-up or sign-in to the app using the built-in native sign-up UX. Within a few minutes, you can track the built-in user activity in the Analytics section of the Amazon Pinpoint console. The tracking of the user activity looks like this.
Results, please!
Now that you are collecting and tracking user sign-up and sign-in activities in your app, you can easily engage with those users via Amazon Pinpoint. First, create a new segment in the Amazon Pinpoint console and choose one of the channels (mobile push, email, or SMS) of your registered users. You will see the number of users registered with your mobile app with that channel. You can then select various attributes collected by your app and immediately engage with these users by using an Amazon Pinpoint campaign. For more information, see Amazon Pinpoint Campaigns in the Amazon Pinpoint User Guide.
Stay engaged!