Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Apr 29, 2024

Integrate your application

In your application directory, you should first install the necessary dependencies for using In-App Messaging.

Install Amplify UI for React

Although Amplify In-App Messaging can be used as a standalone JavaScript library, this guide will show you how to use it together with Amplify UI which currently supports integration with React and React Native to get started quickly.

Learn more about Amplify In-App Messaging UI and how to fully unlock its capabilities here: Amplify UI for In-App Messaging

npm install aws-amplify@^5 @aws-amplify/ui-react@^5 @aws-amplify/ui-react-notifications@^1
import { Amplify } from 'aws-amplify';
import awsconfig from './aws-exports';

Integrate In-App Messaging

Amplify UI provides a Higher-Order Component for ease of integrating the In-App Messaging UI with your application. Simply wrap your application root component in, for example, App.js.

import { withInAppMessaging } from '@aws-amplify/ui-react-notifications';
import '@aws-amplify/ui-react/styles.css';
const App = () => <>In-App Messaging</>;
export default withInAppMessaging(App);

Now your application is set up with Amplify In-App Messaging. To interact with Amplify In-App Messaging APIs, you will first need to import the Notifications category.

import { Notifications } from 'aws-amplify';

The In-App Messaging feature is a subcategory of Notifications. To make it easier to access throughout your application, you can de-structure it.

const { InAppMessaging } = Notifications;

Below is an example of what your entry file should look like:

import React, { useEffect } from 'react';
import { Analytics, Notifications } from 'aws-amplify';
import { Button, View } from '@aws-amplify/ui-react';
import { withInAppMessaging } from '@aws-amplify/ui-react-notifications';
import '@aws-amplify/ui-react/styles.css';
const { InAppMessaging } = Notifications;
// To display your in-app message, make sure this event name matches one you created
// in an In-App Messaging campaign!
const myFirstEvent = { name: 'my_first_event' };
const App = () => {
useEffect(() => {
// Messages from your campaigns need to be synced from the backend before they
// can be displayed. You can trigger this anywhere in your app. Here you are
// syncing just once when this component (your app) renders for the first time.
}, []);
return (
{/* This button has an example of an analytics event triggering the in-app message. */}
onClick={() => {
Record Analytics Event
{/* This button has an example of an In-app Messaging event triggering the in-app message.*/}
onClick={() => {
Send In-App Messaging Event
export default withInAppMessaging(App);

You can now build and run your app in your terminal. If you click on one of the buttons shown in the above example, the in-app message you defined in the Pinpoint console should be displayed in your app.