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

Page updated Apr 29, 2024

Personalized recommendations

Amazon Personalize can create recommendations by using event data, historical data, or a combination of both. The event data can then be used to create recommendations.

To record event data, you need the following:

For more information, see Record Events.

Installation and Configuration

After creating the Amazon Personalize dataset group, you need to add the personalize:PutEvents permission to your Amplify IAM user roles.

An example IAM policy:

"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "personalize:PutEvents",
"Resource": "*"

You need the tracking ID of your event tracker. For more information, see Get a Tracking ID.

Configure Amazon Personalize:

import { Amplify } from 'aws-amplify';
Analytics: {
Personalize: {
// REQUIRED - The trackingId to track the events
trackingId: '<TRACKING_ID>',
// REQUIRED - Amazon Personalize service region
region: 'us-east-1',
// OPTIONAL - The number of events to be deleted from the buffer when flushed.
flushSize: 10,
// OPTIONAL - The interval in milliseconds to perform a buffer check and flush if necessary.
flushInterval: 5000 // 5s

Working with the API

You can use the Identify event type to track a user identity. This lets you connect a user to their actions and record traits about them. To identify a user, specify a unique identifier for the userId property. Consider the following user interactions when choosing when and how often to call record with the Identify eventType:

  • After a user registers.
  • After a user logs in.
  • When a user updates their information (For example, changing or adding a new address).
  • Upon loading any pages that are accessible by a logged-in user (optional).
import { record } from 'aws-amplify/analytics/personalize';
eventType: "Identify",
properties: {
userId: "<USER_ID>"

You can send events to Amazon personalize by calling the record operation. If you already use Identify to track end-user data, you can skip the userId, the SDK will fetch the userId based on current browser session. For information about the properties field, see Put Events.

import { record } from 'aws-amplify/analytics/personalize';
eventType: "<EVENT_TYPE>",
userId: "<USER_ID>", // optional
properties: {
itemId: "<ITEM_ID>",
eventValue: "<EVENT_VALUE>"

You can track iframe and HTML5 media types by using the MediaAutoTrack event type. MediaAutoTrack tracks all media events of the media DOM element that you bind to. MediaAutoTracker will automatically track Play, Pause, Ended, TimeWatched, and Resume in eventType. The duration of the event compared to the total length of the media is stored as a percentage value in eventValue.

import { record } from 'aws-amplify/analytics/personalize';
eventType: "MediaAutoTrack",
userId: "<USER_ID>", // (optional)
properties: {
itemId: "<ITEM_ID>"

Flush events

The recorded events are saved in a buffer and sent to the remote server periodically (You can tune it with the flushInterval option). If needed, you have the option to manually clear all the events from the buffer by using the 'flushEvents' API.

import { flushEvents } from 'aws-amplify/analytics/personalize';