Page updated Jan 16, 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

Register the AmazonPersonalizeProvider with the Analytics category: You need the tracking ID of your event tracker. For more information, see Get a Tracking ID.

import { Analytics, AmazonPersonalizeProvider } from 'aws-amplify'; Analytics.addPluggable(new AmazonPersonalizeProvider());
1import { Analytics, AmazonPersonalizeProvider } from 'aws-amplify';
2Analytics.addPluggable(new AmazonPersonalizeProvider());

Configure Amazon Personalize:

// Configure the plugin after adding it to the Analytics module Analytics.configure({ AmazonPersonalize: { // REQUIRED - The trackingId to track the events trackingId: '<TRACKING_ID>', // OPTIONAL - Amazon Personalize service region region: 'XX-XXXX-X', // 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 } });
1// Configure the plugin after adding it to the Analytics module
2Analytics.configure({
3 AmazonPersonalize: {
4
5 // REQUIRED - The trackingId to track the events
6 trackingId: '<TRACKING_ID>',
7
8 // OPTIONAL - Amazon Personalize service region
9 region: 'XX-XXXX-X',
10
11 // OPTIONAL - The number of events to be deleted from the buffer when flushed.
12 flushSize: 10,
13
14 // OPTIONAL - The interval in milliseconds to perform a buffer check and flush if necessary.
15 flushInterval: 5000, // 5s
16 }
17});

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).
Analytics.record({ eventType: "Identify", properties: { "userId": "<USER_ID>" } }, 'AmazonPersonalize');
1Analytics.record({
2 eventType: "Identify",
3 properties: {
4 "userId": "<USER_ID>"
5 }
6 }, 'AmazonPersonalize');

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.

Analytics.record({ eventType: "<EVENT_TYPE>", userId: "<USER_ID>", (optional) properties: { "itemId": "<ITEM_ID>", "eventValue": "<EVENT_VALUE>"} }, "AmazonPersonalize");
1Analytics.record({
2 eventType: "<EVENT_TYPE>",
3 userId: "<USER_ID>", (optional)
4 properties: {
5 "itemId": "<ITEM_ID>",
6 "eventValue": "<EVENT_VALUE>"}
7 },
8 "AmazonPersonalize");

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.

Analytics.record({ eventType: "MediaAutoTrack", userId: "<USER_ID>", (optional) properties: { "domElementId": "MEDIA DOM ELEMENT ID", "itemId": "<ITEM_ID>" } }, "AmazonPersonalize");
1Analytics.record({
2 eventType: "MediaAutoTrack",
3 userId: "<USER_ID>", (optional)
4 properties: {
5 "domElementId": "MEDIA DOM ELEMENT ID",
6 "itemId": "<ITEM_ID>"
7 }
8}, "AmazonPersonalize");