Product Recommendations JavaScript SDK
📚 JavaScript library for retrieving and displaying product recommendations.
📦 Installation
This SDK can be pulled down from a CDN or installed as a module from NPM.
CDN
The latest version of the SDK is placed in the latest
directory.
<script src="https://sdk.magento-datasolutions.com/latest/index.js"></script>
Specific versions are also published on the CDN under their respective directories.
<script src="https://sdk.magento-datasolutions.com/v0.0.19/index.js"></script>
NPM
npm install @magento/recommendations-js-sdk
🥑 Usage
import RecommendationsClient from "@magento/recommendations-js-sdk"
const client = new RecommendationsClient()
await client.ping()
client.register({
name: "people also viewed",
strategy: "people also viewed",
})
client.register({
name: "people also viewed, under $200",
strategy: "people also viewed",
filter: "base_price.1:<200",
})
client.register({
name: "custom query",
search: [
{
signal: "query",
key: "categories:(159 OR 377)",
boost: 100,
},
],
})
const {status, data} = await client.fetch({
currentSku: "134524",
cartSkus: ["140805", "140294"],
userViewHistorySkus: ["96039", "134103", "137685"],
userPurchaseHistorySkus: ["140307", "94079"],
})
const template = `
<div id="product-recommendation-unit">
{{#results}}
<div id="product-recommendation">
<p>{{name}}</p>
<p>{{price}}</p>
</div>
{{/results}}
</div>
`
const markup = client.render(template, data.units[0])
❓ Questions
If you have questions or need help, there are a few ways you can get in touch.
📧 Email us at magento-product-recs@adobe.com
💬 Join us in the #p-rex channel
🐞 Open an issue in this repository