Welcome to the Particular Audience Quick Start guide! By the end of this tutorial you will have a functioning recommendation UI widget that you can place on your website. Along the way you will also learn more about the PA recommendation system.
In 10 minutes you will build:
💻 Building a simple UI with React
To get started, let’s create a React project.
yarncreatereact-apppa-recommendation-ui
You should now have an empty React JS project.
Let’s now start building!
cdpa-recommendation-uiyarnstart
Adding the PA Sandbox Tag
Let’s go ahead and add in the PA Sandbox Tag. This (to an extent) mimics the production PA Tag that will be given to you. The tag also helps get the CustomerId for you from PA’s servers.
To add the tag, navigate to public/index.htmland add the following script in the head tag.
public/index.html
<script>window.addPAC = function (c, e) { document.cookie = 'PAC=' + c + ';' + e + ';' }</script>
<script src="https://cdn.particularaudience.com/js/sandbox/t.js"></script>
🧙 Tips: The PA Tag does a lot of house keeping work such as track user behaviour data and automatically fetch the CustomerID for you.
Boilerplate React code
Next, let’s go to src/App.js and add some boilerplate code.
Fetching recommendations
There are three key unique IDs to keep in mind when making a GET request to any recommendation endpoint:
WebsiteID: this is an ID given to you, the client, when the tracker is completed
CustomerID: this is the customer ID
ProductID: this is the primary ID of the product, either on a SKU level or item group level depending on how the recommendations were set up for you
🧙 Tips: The Sandbox WebsiteID is 111111-1111-1111-1111-111111111111
🧠 Note:CustomerID vs ProductID based requests
We have customer centric recommendations that require a customer ID such as recently viewed products. On the other hand, we have product based recommendations which depend on what product the user is viewing at the current moment. To get a full idea of all the available tactics, please refer to our API Reference.
If you’re unsure of what tactic or strategy to implement, reach out to your account manager and we can create a plan for you!
For this tutorial, we will use one of the CustomerID specific endpoints that you can see below.
Once you have the CustomerID you are able to make the sandbox request.
🧙 Tips: If you want to use PA Recommendations in your email or SMS campaigns, be sure to save the CustomerID down in your database for future requests.
Enrich recommendation data
The PA Recommendation API returns a list of product IDs. We do not include extra data such as product title, image, price, availability or other pieces of information. This provides flexibility in how you enrich the data with your own up-to-date product information.
In our code sample, we mimic this process with a constant variable called PLACEHOLDER_DATA_STORE which contains the product information.
Display recommendations
The easy part! Now that we have our enriched recommendations, we can display it however we want.