Amazon Personalize for Magento 2
Magento Innovation Labs it's a program that allows the community to show creative and innovative solutions for e-commerce, using the Magento platform. Every year a new round is available for the Magento community to create and show how is possible to innovate the e-commerce industry using the flexibility that only Magento has. This integration was developed thinking about the partnership between Magento and Amazon, as one of the recommended solutions that can be integrated with Magento. For more info please check https://magento.com/blog/magento-news/magento-innovations-lab-teams-amazon-web-services-aws
Amazon Personalize is a machine learning service that makes it easy for developers to create individualized recommendations for customers using their applications. According to Amazon, 30% of their orders comes from product recommendation generated by their machine learning algorithms. So, using Personalize we can use the same machine learning algorithms to create product recommendation and to show related products to all of your customers.
Install using composer:
compose require imaginationmedia/aws-personalize-magento2
You will also need to create a new AWS Personalize project in your AWS console, you start using this link.
AWS Personalize will use customers, products and orders to generate exclusive product recommendations for customers, and also to generate related products in the product page, replacing the native related products engine that Magento has. There is a minimum of customers, products and interactions (orders) that are required to use AWS Personalize, please check the docs to make sure your Magento 2 store has enough data to start to use this service. In case you would like to test this service with sample data you can use the Magento internal tool to generate a database with orders, products and customers. Using Magento 2 orders, customers and products we will export all this data to AWS Personalize, it will study and learn using this data and will allow us to call the api requesting products recommendation for a customer.
Once you created a new AWS Personalize project you will need to create three different datasets. Datasets are a database where you import data that's going to be analyzed and learned by a model. This model will be trained and will understand the provided data, understanding how we can use that data. For an e-commerce we will basically study and learn the interaction between products and customers, so, we need to have datasets for customers, for products and for the interactions between the customers and the products.
On Magento admin you will need to first setup the basic configuration, used to create the connection to AWS Personalize.
Profile is the AWS profile that you have in your environment/server that's going to be used to connect to AWS. Check this guide for more info. Version is the web service version that you are going to use. Use latest as the value, to use always the latest version. Region is the region where you created your AWS Personalize instance. campaignARN is the ARN provided by Personalize when you create a new Personalize campaign.
Then we have settings to enable the product recommendation and also the related products block. Product recommendation will be displayed on products page, catalog pages, search, cms, cart, almost in all the pages. It will be displayed only for logged in customers because all the recommendations will be created for each user, using Personalize Machine Learning algorithms.
You will need to also setup a S3 bucket that will be responsible to receive the exported data from Magento. It will stored as csv files on S3 and Personalize will read these csv files to import the data. Once you created the S3 bucket you will need to setup the S3 config on Magento admin for each export profile.
Create a customers dataset using this schema:
{
"type": "record",
"name": "Items",
"namespace": "com.amazonaws.personalize.schema",
"fields": [
{
"name": "ITEM_ID",
"type": "string"
},
{
"name": "PRICE",
"type": "double"
},
{
"name": "NAME",
"type": "string"
},
{
"name": "KEYS",
"type": "string"
},
{
"name": "CATEGORIES",
"type": "string"
}
],
"version": "1.0"
}
Once it's created you have to go to the Magento admin, access the export configuration and choose "customers". Then you have to set up:
- DatasetArn - The ARN generated for this dataset, you can get that information right after you created the dataset, in the AWS console inside the dataset information.
- JobName - A job name that's going to be used to import the dataset data from your Magento store to Amazon AWS.
- RoleArn - The ARN of the IAM role that has permissions to read from the Amazon S3 data source.
You also have to create a dataset for products, you have to use this schema:
{
"type": "record",
"name": "Items",
"namespace": "com.amazonaws.personalize.schema",
"fields": [
{
"name": "ITEM_ID",
"type": "string"
},
{
"name": "PRICE",
"type": "double"
},
{
"name": "NAME",
"type": "string"
},
{
"name": "KEYS",
"type": "string"
},
{
"name": "CATEGORIES",
"type": "string"
}
],
"version": "1.0"
}
Once you created the dataset you also need to setup all the info for this dataset in the Magento admin panel.
We also need a dataset for interactions, interactions will be orders created by customers. You have to create the dataset using this schema:
{
"type": "record",
"name": "Interactions",
"namespace": "com.amazonaws.personalize.schema",
"fields": [
{
"name": "USER_ID",
"type": "string"
},
{
"name": "ITEM_ID",
"type": "string"
},
{
"name": "TIMESTAMP",
"type": "long"
}
],
"version": "1.0"
}
Then you also have to setup the config for this export dataset on Magento admin.
There is a RoleArn for all the datasets configuration on Magento admin. This is the roleArn used to get access to the S3 bucket provided on Bucket Name config. Please read this article if you need more info about that.
Once you have all the configuration set up we can start to export data from Magento 2 to Personalize. We have three ssh command, each one responsible to export data to a profile.
bin/magento aws:personalize:export:customers - It will export the customers data to a csv file, this csv file will be uploaded to the S3 bucket and then imported to the AWS Personalize dataset.
aws:personalize:export:products - It will export the products data to a csv file, this csv file will be uploaded to the S3 bucket and then imported to the AWS Personalize dataset.
aws:personalize:export:interaction - It will export the interactions (orders) data to a csv file, this csv file will be uploaded to the S3 bucket and then imported to the AWS Personalize dataset.
After we push data to Personalize it will take some time to Personalize import, study and learn with this data. You can always see the status in AWS panel. Once this process is completed for all the three datasets we can enable the product recommendation/related products and you will see it in the storefront.
Aws Personalize allow us to also track events, this extension allow us to setup an event to track new interactions (orders).
So, you have to create an event inside your AWS Personalize campaign and then setup this event in Magento admin.