Introduction

To take advantage of personalized search results, you need to send the enablePersonalization and userToken search parameters. The way to do this depends on your implementation of Algolia, and whether or not you use InstantSearch.

InstantSearch

With InstantSearch, you can enable personalization in two different ways. You only need to choose one of them:

  • during initialization of your InstantSearch instance
  • or by making use of the configure widget.

Either way, you need to use the enablePersonalization parameter. You also have to provide the userToken you’re using to send personalization events.

During Initialization

During the setup of your InstantSearch instance, you can pass (almost) any search parameter, including enablePersonalization. To do this, you can pass an object containing enablePersonalization and userToken keys.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const search = instantsearch({
  indexName: 'instant_search',
  searchClient: algoliasearch(
    'YourApplicationID',
    'YourAdminAPIKey'
  ),
  searchParameters: {
    enablePersonalization: true,
    userToken: 'user-1234',
  }
});

// Add widgets
// ...

search.start();

Using the configure widget

1
2
3
4
5
instantsearch.widgets.configure({
  hitsPerPage: 8,
  enablePersonalization: true,
  userToken: 'user-1234',
});

API Clients

If you’re using one of our API clients, you can use the enablePersonalization parameter in the search method. You also have to provide the userToken that you’re using to send personalization events.

1
2
3
4
$index->search('query', [
  'enablePersonalization' => true,
  'userToken' => '123456'
]);

Did you find this page helpful?