Welcome to the Particular Audience (PA) Quick Start guide for Search! By the end of this tutorial you will have a functioning search UI widget that you can place on your website.
The PA Search API is flexible - it allows for a whole range of functionality from a single endpoint. This includes:
Faceted search
Personalised search
Image search
Synonyms
And more
To learn how to trigger all the functionality, please see the Search API reference.
In this example we will just focus on getting a basic faceted search example functioning.
Here’s what you will finish with:
💻 Building a simple UI with React
To get started, let’s create a React project.
yarn create react-app pa-search-ui
You should now have an empty React JS project.
Let’s now start building!
🧙 Tips: We’re using Ant Design as our UI framework. It has nice looking UI components to help us build faster!
cd pa-search-ui
yarn add antd
yarn start
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.
This piece of code contains three key areas:
When our query changes, we want to initiate a search
The PA API is flexible - you are able to aggregate on any field provided to us. Aggregations is how we show the faceted filters on the left hand side of the demo.
To enable aggregations, simply provide an array of attributes you would like to aggregate in your POST request.
🧠 Note: In this demo we are aggregating by “product_type” and “brand” however you are able to aggregate by any field provided to us in the product feed.
Personalized and image search
The sandbox has not been indexed to provide personalized or image search. To enable personalized search simply change the "personalise" boolean parameter to true.
To allow for image search, simply provide a publicly accessible image url in the image_link field.
Filtering results
To filter results, use the scope field in the JSON payload. Scope is a JSON object where the key is the field you’d like to filter and the value is an array of values you’d like to filter by.
Here is an example of filtering by product_type and price: