You can implement Personalization using the REST API and the Search UI Library. For further information and detailed instructions, please continue reading below.
To leverage personalization, it’s essential to have structured data indexed with custom fields. Custom fields might represent product categories, seasonal attributes, or any other property that can capture user preferences. The most straightforward method to include custom fields is by utilizing meta tags on your web pages. Below is an example of a custom field defined using metatags:
<meta name="addsearch-custom-field" data-type="text" content="category=Digital product"/>
When a user clicks on a product within this category, they will subsequently see more digital products in their personalized results. It’s important to note that for personalization to function, custom fields must be of the TEXT type.
To explore further about custom fields and their various applications, check out this supporting article.
The implementation process depends on the installation method utilized. Personalization is currently supported through custom implementations using the REST API and Search UI Library.
The cookies created by the AddSearch UI and client libraries are considered 1st-party cookies because they are set by and directly related to your website, not by a third party.
To add personalization to your Search UI implementation, follow these steps:
This doesn’t enable using cookies by itself, so you can keep personalization enabled if you use it in your implementation.
// Defaults - isEnabled: false, expirationDates: 180 client.enablePersonalizationTracking(isEnabled, expirationDates);
By default, user token storage is disabled. If the user has already consented to cookies or you store cookies unless their usage is explicitly denied, set this to true. Once the user consented to cookies or declined them, you need to call this method once again with the updated value.
// Default: false client.consentAddSearchCookie(true);
AddSearch’s cookie can be classified as a functional/analytics cookie. A user token is generated and saved in a cookie named “addsearchUserToken”.
You need to set the user token by extracting it from the cookie or user’s session and passing to the client.
client.setUserToken(client.getUserTokenInPersonalization());
If you want to use your own token instead of the one generated by AddSearch, you need to call these functions:
client.setUserToken(yourUserToken); client.setStatsSessionId(yourUserToken);
To implement personalization with the REST API, follow these steps:
These tokens are typically stored in cookies. You might already have such a token in place, in this case you can just use it. For instance, if you have Google Analytics integrated on your website, such a token is stored inside the _ga cookie. If you implement user tokens from scratch, you need to make sure your website visitors consent to personalisation cookies usage.
For instance:
https://api.addsearch.com/v1/search/1bed1ffde465fddba2a53ad3ce69e6c2?term=personalisation&userToken=test_user
For instance:
{ "action": "click", "session": "test_user", "keyword": "personalisation", "docid": "abc123", "position": 1 }
With custom fields indexed and personalization integrated into your setup, the next step involves configuration in the dashboard. Navigate to the Personalization section in your AddSearch dashboard and enable the feature. Select a custom field for personalization and assign its weight. We suggest starting with smaller values below 100 and tweaking them in the testing phase.
After setting up personalization, here’s how to test it:
We’re always happy to help with code or other questions you might have. Search our documentation, contact support, or connect with our sales team.