@algolia/recommend-js
v1.16.0
Published
JavaScript package for [Algolia Recommend](https://www.algolia.com/doc/guides/algolia-ai/recommend/).
Downloads
4,012
Maintainers
Keywords
Readme
🙌 From now on you can use Algolia Recommend from InstantSearch, simplifying your integration between the two libraries!
Learn how to migrate following the upgrade guide.
import instantsearch from 'instantsearch.js';
import {
frequentlyBoughtTogether,
relatedProducts,
} from 'instantsearch.js/es/widgets';
import algoliasearch from 'algoliasearch/lite';
const searchClient = algoliasearch('YourApplicationID', 'YourSearchOnlyAPIKey');
instantsearch({
// No need for a recommendClient anymore
searchClient,
indexName,
}).addWidgets([
frequentlyBoughtTogether({
container: '#frequentlyBoughtTogether',
objectIDs: [currentObjectID],
}),
relatedProducts({
container: '#relatedProducts',
objectIDs: [currentObjectID],
}),
]);
@algolia/recommend-js
JavaScript package for Algolia Recommend.
Installation
All Recommend packages are available on the npm registry.
yarn add @algolia/recommend-js
# or
npm install @algolia/recommend-js
Usage
To get started, you need a container for your recommendations to go in—in this guide, one for Frequently Bought Together, and one for Related Products. If you don't have containers already, you can insert them into your markup:
<div id="frequentlyBoughtTogether"></div>
<div id="relatedProducts"></div>
Then, insert your recommendations by calling the frequentlyBoughtTogether
function and providing the container
. It can be a CSS selector or an Element.
The process is the same for relatedProducts
.
/** @jsx h */
import { h } from 'preact';
import {
frequentlyBoughtTogether,
relatedProducts,
} from '@algolia/recommend-js';
import recommend from '@algolia/recommend';
const recommendClient = recommend('YourApplicationID', 'YourSearchOnlyAPIKey');
const indexName = 'YOUR_INDEX_NAME';
const currentObjectID = 'YOUR_OBJECT_ID';
frequentlyBoughtTogether({
container: '#frequentlyBoughtTogether',
recommendClient,
indexName,
objectIDs: [currentObjectID],
itemComponent({ item }) {
return (
<pre>
<code>{JSON.stringify(item)}</code>
</pre>
);
},
});
relatedProducts({
container: '#relatedProducts',
recommendClient,
indexName,
objectIDs: [currentObjectID],
itemComponent({ item }) {
return (
<pre>
<code>{JSON.stringify(item)}</code>
</pre>
);
},
});
Continue reading our Getting Started guide.
Documentation
The documentation offers a few ways to learn about the Recommend library:
- Follow the Building your Recommend UI guide to display recommendations on your website.
- Refer to the API reference for a comprehensive list of parameters and options.