Get the latest user events with real-time data using Segment and Amazon Personalize

In this recipe, you are going to deploy a sample retail web application using automated deployment. This recipe demonstrates how Amazon Personalize AI service can be deployed and integrated with Segment to deliver real-time events from the web user interface to Amazon Personalize.

James Jory Made by James Jory
Igor Krtolica Made by Igor Krtolica
Kenny Rajan Made by Kenny Rajan
Corey Ching Made by Corey Ching

What do you need?

  • Segment workspace: If you are doing this workshop as part of a live workshop event, ask your moderator how to set up a Segment workspace.

  • AWS Environment: If you are participating in an AWS-led workshop, you will be likely provided with the AWS lab account.

Easily personalize customer experiences with first-party data

With a huge integration catalog and plenty of no-code features, Segment provides easy-to-maintain capability to your teams with minimal engineering effort. Great data doesn't have to be hard work!

On this page

Customers love the feeling of being important to your business. With personalized recommendations, you can suggest highly relevant products to your customers to provide that personal touch. With Amazon Personalize you can deliver unique homepage experiences, help customers discover products faster, refine product recommendations, boost up-sell, and cross-sell products.

Amazon Personalize enables developers to build applications with the same machine learning (ML) technology used by Amazon.com for real-time personalized recommendations – no ML expertise required.

Along with Amazon Personalize, customers can use AWS Partner Solutions like Segment's CDP to maintain real-time datasets that represent the latest user behavior and provide personalized recommendations. Amazon Personalize AI service can be deployed and integrated with Segment to deliver real-time events from the web user interface to Amazon Personalize. 

Chances are, your business doesn’t just cater to one type of customer. Maybe it’s selling to businesses vs consumers, marketers vs engineers, or even merchants vs consumers. Whatever it is, you need to get these different personas activated in different ways. In this recipe, you’ll learn how to setup a real-time events pipeline of customer data for Amazon Personalize. 

These real-time events are also used to create customer profiles with Amazon Personalize recommendations appended, which can then be used via a CDP to push data to marketing tools.

Amazon Personalize provides recipes based on common use cases for training models. These recipes are Amazon Personalize algorithms that are prepared for specific use cases. With recipes, you can create a personalization system without prior machine learning experience.

Amazon Personalize recipes use the following during training:

  • Predefined attributes of your data

  • Predefined feature transformations

  • Predefined algorithms

  • Initial parameter settings for the algorithms

To optimize your model, you can override many of these parameters when you create a solution. For more information, see Hyperparameters and HPO.

Choose a specific recipe based on what you want to accomplish and how familiar you are with the recipes. Each recipe is designed for a specific use case. When creating a solution, choose the recipe that best fits your needs.

You can also use Amazon Personalize recommenders which are optimized to deliver personalized experiences for common use cases in Media & Entertainment and Retail. It is now faster and easier to deliver high performing personalized user experiences in your applications without any ML expertise required. Recommenders reduce the time needed to build and deliver personalized experiences and fully manage the lifecycle of the experience to help ensure you recommend what is most relevant to your users.

Tailoring experiences to users requires different types of recommendations at different points in a user’s journey. Media & Entertainment applications drive greater engagement and retention with personalized recommendations like “Top Picks” for users on the welcome screen and “More Like X” on video detail pages where the context of what a user has watched is critical to discover what to watch next. Retail businesses need recommendations to highlight “Best Sellers” and the items “Frequently Bought Together” to enable customers to more easily build their baskets at check-out. Amazon Personalize’s recommenders simplify the creation and maintenance of these personalized user experiences. Personalize considers the business-specific context and selects the optimal settings for our underlying machine learning models used to serve the recommendations. By fully managing the lifecycle of maintaining and hosting these models, Amazon Personalize makes it easier and faster to deliver these experiences in your application.

Media & Entertainment customers can choose from use cases such as:

  • “Most Popular”

  • “Because You Watched X”

  • “More Like X”

  • “Top Picks For You”

Retail customers can choose from use cases such as:

  • “Best Sellers”

  • “Most Viewed”

  • “Frequently Bought Together”

  • “Customers Who Viewed This Also View”

  • “Recommended For You”

You will learn to connect this dataset to the Personalize dataset as part of pre-requisites section. This will enable your Personalize models to be kept up to date with the latest events your users are performing. To create Retail Demo Store powered by AWS services see the directions outlined in the below pre-requisites section.

Prerequisites: Configure Retail Demo Store in AWS Environment and Amazon Personalize

As a prerequisite for this recipe, we recommend you complete the below labs from the AWS samples for Retail Demo Store to get an understanding of how Amazon Personalize can be used for retail demo store setup.

 

1. Setup the AWS environment by following the lab guidelines or If you do not have an AWS account, please see How do I create and activate a new Amazon Web Services account?

 

2. Access the Getting Started section in the AWS samples for Retail Demo Store section to complete the AWS CloudFormation setup. AWS CloudFormation deployment will take 20-30 minutes to complete. Verify Create Complete message which means the AWS environment is successfully configured.

Create Complete message in AWS retail demo store

3. Access the Amazon Sagemaker from the lap setup and follow the instructions. To access the Sage maker instances for this workshop after the CloudFormation stack has been completed, browse to Amazon SageMaker in your AWS console, and then select Notebook Instances in the AWS console in your AWS account. See AWS SageMaker documentation for instructions.

  • You will see a running Notebook instance. Click "Open JupyterLab" for the Retail Demo Store notebook instance. 

Running notebook instance

4. Here you will find several workshops in a directory structure in the notebook instance. As a prerequisite, access the below workshop 0-StartHere and 1-Personalization and complete the workshop as sequenced.  

Workshop folders in a directory structure in the notebook instance

To run a code snippet within the SageMaker notebook, you can click run option from the menu toolbar. See Amazon SageMaker documentation to learn more.

Running a code snippet within the SageMaker notebook

5. Segment: This module also requires access to a Segment account with Personas . If you are unsure and attending a Segment managed event such as a workshop, check with your event lead. If you are running this workshop independently and do not have a Segment account with Personas provisioned, please contact your Segment representative or follow this link to sign up for Segment.

Step 1:  Segment Real-Time Data + Amazon Personalize

Before you follow the below steps, we assume you have a basic understanding of Amazon Personalize or have completed the above prerequisite section recommended for this recipe. Completing the prerequisite section will give you hands-on experience with major features of Amazon Personalize, and how it can be deployed in an e-commerce application like the Retail Demo Store.

In this section, you are going to be adding the ability to maintain a real-time dataset that represents the latest user behavior for users of the Retail Demo Store. 

  • You will then connect that dataset to the Personalize dataset groups that you built in the first part of the workshop. This will enable your Personalize models to be kept up to date with the latest events your users are performing.

  • This workshop will use the Segment analytics.js library to collect real-time data from the Retail Demo Store, and then feed that event data into the Segment platform, where it can be routed directly to a Personalize Tracker, and then used to maintain the latest behavioral data for your personalization user-item interaction data.

Segment Platform Overview

Segment is a customer data platform (CDP) that helps you collect, clean, and control your customer data. Segment provides several types of Sources which you can use to collect your data, and which you can choose from based on the needs of your app or site. For websites, you can use a javascript library to collect data. 

If you have a mobile app, you can embed one of Segment’s Mobile SDKs, and if you’d like to create messages directly on a server (if you have, for example, a dedicated .NET server that processes payments), Segment has several server-based libraries that you can embed directly into your backend code. With Segment, you can also use cloud sources to import data about your app or site from other tools like Zendesk or Salesforce, to enrich the data sent through Segment. By using Segment to decouple data collection from data use, you can create a centralized data supply chain based on organized and modular data  

Segment platform overview

Setup:

1. From your SageMaker Jupyter notebook instance access the Segment Real-Time Data + Amazon Personalize lab. We will break up the process into multiple labs that are designed to progressively build on top of each other. Therefore, you should complete the labs in the order specified below.

Segment Real-Time Data + Amazon Personalize labs in order

2. Segment uses sources as a way to organize data inputs into the platform. Configuring a source will allow you to collect real-time event data from the Retail Demo Store user interface, and pass that information to Segment. 

3. You need to be signed in to your Segment workspace to begin this process. Once you are signed in to the Segment Console, click on your workspace, and then ‘Connections’ in the upper left-hand corner of the screen. Then, click ‘Add Source’.

Button to add a source on the Segment console

4. Select the ‘javascript’ source type.

Selecting the ‘javascript’ source type on Segment console

5. And click ‘Add Source’.

Button to ‘Add Source’ on Segment console

6. Give your source a name. We recommend ‘retail-demo-store.

Adding a source name on Segment console

7. The next screen confirms that your source was successfully created.

Confirmation screen of successful source creation

8. Now that you are here, set the write key for your new source in the environment variable below. 

  • Copy the string in the analytics.load(“...”) section shown above, and paste it into the variable in the cell below. 

  • You will need this in a few minutes when you enable Segment events collection in the Retail Demo Store.

  • Make sure you run the cell after you paste the key.

Setting the write key for new source in the environment variable

9. Now that you have a working source, let’s wire up our event data to Amazon Personalize. Configure the Segment Personalize Destination. 

  • Segment uses Destinations to route real-time event data to a data consumer application. In this case, you will be using the Segment Personalize destination.

  • This destination will take real-time events from Segment, pass them through an AWS Lambda function, and then into the user-item interactions dataset in your Retail Demo Store.

  • Click ‘Connections’ in the upper left corner of the screen, and then the ‘Add Destination’ button.

Button to add the Segment Personalize Destination

10. In the Segment destinations catalog, type ‘personalize’ into the search text box in the upper left corner of the screen. You will see the Amazon Personalize destination appear in the search results. Click the tile for the destination.

Amazon Personalize destination in search results

11. Then, click the ‘Configure Amazon Personalize’ button.

Button to ‘Configure Amazon Personalize’

12. Select your source from the earlier part of this process; this screen should show the source you created in the steps above and click Next.

Select data source

13. Name the destination as retail-demo-store and save.

Setting destination name as retail-demo-store

14. At this point, you are ready to configure the AWS Lambda function that the destination will need to process events from the Retail Demo Store.

  • The Retail Demo Store deployment in your AWS account will have a pre-configured Lambda function that you can use to configure the destination. This function is deployed to the Retail Demo store during the environment setup steps at the beginning of the workshop.

  • Segment uses a Lambda function as a way to allow you to customize the event names and properties that are sent to Personalize for training purposes. The Cloud Formation Template and code for this Lambda is available for your use if you would like to use this pattern in your own applications.

Configuring the AWS Lambda function

15. Log in to the Lambda service in the AWS Console. You will see a screen that looks like the below image. Find the SegmentPersonalizeEventsDestination and click on it. Keep this tab or window open as you will need it in a few steps when you configure Amazon Personalize.

Lambda service in the AWS Console

16. Get the ARN for the Lambda function. Click the copy link shown above to copy the ARN to the clipboard.

Link to copy the ARN to the clipboard

17. Go back to the Segment console for your Personalize destination Lambda ** section. Paste in the ARN for the Lambda section (see step 14). And click the Save button.

Pasting the ARN for the Lambda section

18. Next, you will give Segment permission to call your Lambda from their AWS account. Click the Role Address** link.

Giving Segment permission to call your Lambda from their AWS account

19. Next, go to your AWS IAM Console and then click on Roles. In the search text box, search for Segment.

 Searching for Segment role in the AWS IAM Console search text box

20. Select the SegmentCrossAccountLambda role, and copy the Role ARN. You can easily copy the whole string by clicking the copy button to the right of the ARN as shown in the screenshot.

Button to copy the Role ARN

21. Go back to the Segment console destination configuration tab or window, and paste in the ARN you just copied and click Save.

Pasting the ARN in the Segment console destination configuration tab or window

22. Next, click the ‘External ID’ link.

Clicking the ‘External ID’ link

NOTE: This external id setup is intended only for lab purposes. As a best practice do not use this pattern in a production application. For this workshop, we hard-code an external ID into the role deployment.

External id intended only for lab purposes

Segment’s integration supports using the write key for the source that is sending data to this destination as the External ID, and you should use this feature instead of a hard-coded external ID.

Enter '123456789' in the External ID field, and click Save

23. Next, you need to set the region for the Lambda that is deployed in your account.

Setting the region for the Lambda that is deployed in your account

If you are running this in an AWS-managed workshop, ask your event admin for the region in which you are running the workshop. If you are running the workshop in us-west-2, there is no need to change this setting. Otherwise, use the region in which the workshop is deployed, otherwise, Segment will not be able to invoke your Lambda. 

24. Finally, click the slider button at the top of the screen to enable the destination. You must enable the destination or events will not be sent to Personalize in the following steps.

Slider button at the top of the screen to enable the destination

25. Configure Lambda Parameters and Review Code.

26. Before the destination can send events to your Amazon Personalize events tracker, you will need to tell the destination lambda where to send the events. It looks for an environment variable called 'personalize_tracking_id'.

  • Run the Amazon Personalize tracker code snippet to lookup the relevant Amazon Personalize tracker from the Personalize workbook.

  • We can then set the appropriate value in the destination Lambda.

27. Log in to the Lambda service in the AWS Console. Find the SegmentPersonalizeEventsDestination, and click on it in the list.

Finding the SegmentPersonalizeEventsDestination on the Lambda service in the AWS Console

28. Go to Configuration and Environmental variables. 

Configuration and Environmental variables in the AWS console

29. Then, scroll down to the parameters section. The tracking parameter should be set to the tracker from the first workbook. 

  • Click the edit button, then paste in the tracking ID from the cell above, and click the Redeploy button at the top of the screen.

Pasting the tracking ID in the parameters section
  • Take some time to look at the code that this Lambda uses to send events to Personalize. 

30. Validate that Real-Time Events are Flowing from the Retail Demo Store.

  • You are now ready to send live events to Personalize from the Retail Demo Store.

  • In order to do this, you will need to enable the Segment client-side integration with the Retail Demo Store. 

  • Segment provides a variety of ways to collect real-time events, and a full discussion of how this works is beyond the scope of this document, however, the Retail Demo Store represents a fairly typical deployment for most web applications, in that it uses the Segment analytics.js library, loaded via the Segment CDN, to inject their code into the web application. 

  • Because the Retail Demo Store is a Vue.js application, this code is loaded in the head tag of index.html file:

  • This ensures that the Segment library is available at all times for each user action in the user interface of the Retail Demo Store.

  • Each time a user performs an action in the Retail Demo Store user interface (such as viewing a product, adding a product to a cart, searching, etc.) an event is sent to Segment with the properties associated with that user’s action. 

Note that this code is only loaded if an environment variable is set to define the write key for the Segment source which will accept events from the Retail Demo Store. This will become important in a moment.

let eventProperties = {
  productId: product.id,
  name: product.name,
  category: product.category,
  image: product.image,
  feature: feature,
  experimentCorrelationId: experimentCorrelationId,
  price: +product.price.toFixed(2)
};

if (this.segmentEnabled()) {
  window.analytics.track('ProductViewed', eventProperties);
}
  • This allows you to collect data that is relevant to any tool that might need to be kept updated with the latest user behavior. 

31. Sending Real-Time Events: Since you have already connected Segment to Personalize, let’s test this data path by triggering events from the Retail Demo Store user interface which is deployed in your AWS account.

  • Run the SSM parameter code snippet to set the SSM parameter that holds the Segment write key.​

32.You now have an environment variable that will enable the Segment data collection library in the code in index.html. All we need to do now, is force a re-deploy of the Retail Demo Store. 

  • To do that, go back to your AWS Console tab or window, and select Code Pipeline from the Services search. Then, find the pipeline name that contains WebUIPipeline and click that link.

Finding the pipeline name that contains WebUIPipeline  in the AWS console

33. Then, select the ‘Release Change’ button, and confirm the release once the popup shows up. You will see a confirmation that the pipeline is re-deploying the web ui for the Retail Demo Store.

Confirmation that the pipeline is re-deploying the web ui for the Retail Demo Store
  • This process should complete in a few minutes. Once this is done, you will see the bottom tile confirm that your deployment has been completed:

Bottom tile confirming that deployment has been completed

34. Log in as a Retail Demo Store User

IMPORTANT: Once this is confirmed, tab back to the Retail Demo Store web UI, and refresh the screen to reload the user interface. This will load the libraries you just deployed and will allow your instance of the Retail Demo Store to send events to Segment.

  • In the Personalize workshop, you created an account for the Retail Demo Store. If you are not logged in to that account, log in now.

  • Then, open another tab to the Segment console, and select ‘retail-demo-store’ under the Sources tab:

Selecting ‘retail-demo-store’ under the Sources tab

35. And then click on the Debugger tab.

Debugger tab

36. Here you will be able to see live events coming from the Retail Demo Store:

Live events coming from the Retail Demo Store

37. Go back to the Retail Demo Store web app tab, and click on some categories of products. You should start to see events appear in the Segment debugger at this point. This means that the actions you are performing as a user are now being sent to the training datasets in Personalize.

38. Now that you have events flowing from your web application to Personalize, you can keep the Personalize data sets up to date, and re-train them as required by your application use cases.

Summary: You can finish the workshop here, or learn more about what you can do with Segment’s Customer Data Platform (Personas) and Amazon Personalize in the next section:

Step 2:  Omnichannel Personalization with Segment

This module uses Amazon Personalize to generate and associate personalized product recommendations for users then execute an omnichannel personalization campaign using Segment. 

The content of this workshop is presented with the assumption that you have either completed the Personalization workshop outlined in the prerequisite section or those resources have been pre-provisioned in your AWS environment.  

1. Log in to your Segment WorkSpace (https://app.segment.com).  Once you are signed in to the Segment console (https://app.segment.com), click on your workspace, and then ‘Connections’ in the upper left-hand corner of the screen. 

Adding Amazon WorkSpace on Segment

2. Then, click ‘Add Source’

Adding source on Amazon workspace

3. For this exercise, we are going to start by creating a Python data source within Segment. Find the Python source and click Add Source.  

Adding python source

4. Once you’ve created and named the new Python Source, you will be presented with a write key. 

Write key on python source

5. Copy your write key into the string (segment_write_key) below in your notebook, and run the next cell:

Copying Segment write key into the string

Summary: In the above steps you have configured your data collection infrastructure. In the next steps, we will configure Segment to allow our Python Personalize Source to feed data to Personas. 

Step 2.1: Configure Python Personalize Source to feed data to Personas

Personas is a powerful personalization platform within Segment that enables you to create omnichannel customer profiles, build and enrich audiences, and synchronize user data and audiences across your stack. 

1. First, navigate to Personas by clicking this icon in the navbar:

2. Click get started to begin the process. If this is a workshop session and if it is your first time using Personas, Segment will walk you through a brief setup process.

3. Next, we'll name our Personas Space. Name your space anything you'd like. Spaces are used to isolate user profile sets into separate environments (dev, prod, etc.). Click Enable Personas.   

Naming first space

4. Once you've named your space, click into your newly created space. You can close any pop-ups on the next screen.

5. Click 'Get Started' to begin configuring your space. 

Get started button

6. We will use the out-of-the-box settings. Click Continue   

Using out-of-the-box settings

7. Note in a production environment, this is where you would configure custom identity matching settings. For this recipe choose the below values from the image.

Identity rules setup screen

8. Click finish identity setup process to complete identity setup.                        

9. Once you've finished that process, click the Connect Sources button.

10. Then choose the Python Personalize source and click the Connect Sources button.

Connect Sources button

11. Verify the connected sources. Connected sources are sources that feed into Personas and populate your user list.

Summary: In the above steps you have configured Segment to allow Python Personalize Source to feed data to Personas. In the next steps, pull data from our Personalize demo and send it to Segment.

Step 2.2: Get Recommendations from Amazon Personalize and Send them to Segment

Now that Segment is configured, let’s pull data from our Personalize demo and send it to Segment. 

  1. First, you will need to get the name of the load balancer for the Retail Demo Store recommendations service you deployed at the beginning of the Retail Demo Store workshop as part of AWS CloudFormation. 

  2. Access your SageMaker Notebook created for this lab.

Sagemaker Notebook

3. Click run option from your notebook by selecting the following query. The following code will query the AWS account to get a list of load balancers, and find the one that belongs to the Retail Demo Store (and has the tag recommendations).  This URL will be stored in the recommendations_elb_domain_name variable after you run this code.

Code with query

4. In order to understand how Segment is ingesting these recommendations, it is helpful to take a look at the responses that are returned from the recommendations service.

5. Next, run the following from your notebook. The code below will invoke your recommendations service, and return a response for one of the users that exists in the Retail Demo Store user database. You can change the user_id below to any valid ID.

Note: The return value from the recommendation service should look like this:

[
  {
    "product": {
      "id": "2",
      "url": "http://recs.cloudfront.net/#/product/2",
      "sk": "",
      "name": "Striped Shirt",
      "category": "apparel",
      "style": "shirt",
      "description": "A classic look for the summer season.",
      "price": 9.99,
      "image": "http://recs.cloudfront.net/images/apparel/1.jpg",
      "featured": "true"
    }
  },
  {
    "product": {
      "id": "1",
      "url": "http://recs.cloudfront.net/#/product/1",
      "sk": "",
      "name": "Black Leather Backpack",
      "category": "accessories",
      "style": "bag",
      "description": "Our handmade leather backpack will look great at the office or out on the town.",
      "price": 109.99,
      "image": "http://recs.cloudfront.net/images/accessories/1.jpg",
      "featured": "true"
    }
  },
  
  ...
]

Why Amazon Personalize?

Setting up Amazon Personalize will give you the ability to surface product recommendations directly into Segment which powers other services that require real-time user personalization, such as a mobile application or a web application. 

The recommendation service deployed in the workshop queries a Personalize campaign with the user_id that you provide. Personalize will return a list of recommended product IDs for the user. The service then looks up the catalog ID for each product and decorates the response with the product URL, image, name, etc. These attributes should be available in your catalog management system. 

In the case of the Retail Demo Store, there is a catalog service that provides (simulated) catalog items for the workshop. The advantage of a service like this is that your target services like Segment do not need to do an additional lookup in order to get the information they require in order to surface a recommendation to a user, such as product name, product category, and the image associated with the product.

  1. Next, click run by selecting the next code snippet from the notebook. This lab will use the aforementioned service to pull our demo user recommendations and push them into Segment. We’re going to install Segment’s Python library, then create demo user profiles, and pull in recommendations for each user from Amazon Personalize:

import sys
!{sys.executable} -m pip install analytics-python
import analytics

analytics.write_key = segment_write_key

servicediscovery = boto3.client('servicediscovery')

# Look up the Retail Demo Store users service so we can look up user IDs to send to Segment
response = servicediscovery.discover_instances(
  NamespaceName='retaildemostore.local',
  ServiceName='users',
  MaxResults=1,
  HealthStatus='HEALTHY'
)

users_service_instance = response['Instances'][0]['Attributes']['AWS_INSTANCE_IPV4']
print('Users Service Instance IP: {}'.format(users_service_instance))

for id in range(10, 20):

# Look up the user by their ID in the Retail Demo Store users service
response = requests.get('http://{}/users/id/{}'.format(users_service_instance, id))
retail_demo_store_user = response.json()
name = f'{retail_demo_store_user["first_name"]} {retail_demo_store_user["last_name"]}'
email = retail_demo_store_user['email']
persona = retail_demo_store_user['persona']

# Segment will take an identify() call to map a user to the Retail Demo Store login database
analytics.identify('personalize_user_'+str(id), {
  'email': email,
  'name': name,
  'persona': persona
})

# Get the recommendations for this user
response = requests.get('http://{}/recommendations?userID={}&fullyQualifyImageUrls=1&numResults=10'.format(recommendations_elb_domain_name, id))

# Send a Segment track() call for each product recommendation for this user
for product_recomendation in response.json():
analytics.track('personalize_user_'+str(id), 'Product Recommended', {
  'product_id': product_recomendation['product']['id'],
  'product_url': product_recomendation['product']['url'],
  'product_name': product_recomendation['product']['name'],
  'product_category': product_recomendation['product']['category'],
  'product_style': product_recomendation['product']['style'],
  'product_description': product_recomendation['product']['description'],
  'product_price': product_recomendation['product']['price'],
  'product_image': product_recomendation['product']['image']
})

Summary: In the above steps you executed python codes for recommendations service, and validated return a response from get Recommendations from Amazon Personalize. In the next steps, you will create a user trait for each user in Segment to calculate the most recommended product category in the last 30 days.

Now that our users and their associated Amazon Personalize recommendations are in Segment, let’s inspect a user profile to understand the data structure. 

  1. From the Segment Profile Explorer click into one of the user profiles we’ve created.

Segment Profile Explorer

2. Inspect the user traits and associated events we just created:

User traits and associated events in user profile

Note: In order to leverage these recommendations for omnichannel personalization, add a trait to each user profile that calculates the most recommended category for each user in the last 30 days. Segment calls these Computed Traits. Computed Traits allow you to quickly create user or account-level calculations that Segment keeps up-to-date over time - learn more about Computed Traits here.

3. In Engage, click into the computed traits section, and click New Computed Trait.

4. Select Most Frequent, and click Configure.

Selecting Most Frequent computer trait

5. Then, we will create our computed trait based on the Product Recommended events we’ve generated. 

  • In the select an event name section, choose Product Recommended

  • In the Select an event property section, choose product_category. 

  • Minimum Frequency input 1. A minimum number of times event property needs to occur before trait is computed.

  • Run computation input 30 days.

  • Click Preview

Note: In a production implementation, you may consider selecting a time window of 30 days to ensure the trait remains relevant based on recent Product Recommended events.

6. Preview the trait, and click Select Destinations to continue the creation process. 

Select Destination button

Note: In the live workshop, we don’t have any destinations configured, but this is where you can decide which of Segment’s 300+ integrations you want to sync this Computed Trait and each associated user profile.  

7. Click Review & Create.             

8. Finish creating the Computed Trait by naming it amazon_personalize_affinity_category, checking the box to compute the trait without enabled destinations, and clicking Create Computed Trait.

Summary: In the above steps you created user trait for each user in Segment to calculate the most recommended product category. In the next steps, you will create an audience within Segment to target X affinity category 

Step 2.4: Create an audience within Segment to target X affinity category.

Now that our users and their associated Amazon Personalize recommendations are in Segment, let’s inspect a user profile to understand the data structure. 

Next, we will use these traits to execute an example of a real-world use case. Let’s say we want to run a promotional campaign that targets users with an affinity for houseware. We decided to use Braze for email and push, Google Ads, Facebook Ads, Optimizely for A/B testing, and Amplitude for analytics (as well as make the user profile available via REST API). In this scenario, we can use Segment to define our target audience and keep that target audience synchronized with each of our channel tools and API mentioned above.

  1. Navigate to the audience builder in Personas (personas/spaces/default/audiences) and click the New Audience button.

New Audience button in audience builder in Personas

2. Select users who have a computed trait.

3. Define an audience that targets users with an amazon_personalize_affinity_category computed trait that equals houseware.

Selecting computed trait that equals houseware

4. Click Preview results

5. After clicking Select Destinations, choose your destinations in order to start the synchronization process between Segment and your destinations. 

Selecting destinations

Note: For this exercise, you may not have any destinations hooked up if you’re attending a workshop. If you did have destinations configured, it would look similar to the screenshot below:

Summary: Once defined, Segment will sync your audience with each tool and dynamically add and remove users from the audience in each tool over time. 

Cleanup

  • If you launched the Retail Demo Store in your personal AWS account AND you're done with all workshops, you can follow the Personalize workshop cleanup notebook to delete all of the Amazon Personalize resources created by this workshop. 

  • IMPORTANT: since the Personalize resources were created by this notebook and not CloudFormation, deleting the CloudFormation stack for the Retail Demo Store will not remove the Personalize resources. You MUST run the Personalize workshop cleanup notebook or manually clean up these resources.

  • If you are participating in an AWS-managed event, such as a workshop, and using an AWS-provided temporary account, you can skip the cleanup workshop unless otherwise instructed.

Wrapping up

Here’s what we’ve accomplished in this growth recipe:

1) Provide a tool to demonstrate the capabilities of key AWS services for a Demo Retail store that uses Amazon Personalize to provide similar item recommendations, search re-ranking based on user preferences, and offer product recommendations based on user-item interactions.  

2) Provide an overview of Segment's Customer Data Platform integration with Amazon Personalize to deliver real-time events from the web user interface to Amazon Personalize. These real-time events are also used to create a customer profile with Amazon Personalize recommendations , which can then be used via the CDP to push data to marketing tools.

For reference, if you wanted to synchronize the end tools, we discussed to receive this user audience data, you can follow this documentation:

Getting started is easy

Start connecting your data with Segment.