|
| 1 | +// @class CrossSell |
| 2 | +// Accessible via [analytics](#foxapi-analytics) property of [FoxApi](#foxapi) instance. |
| 3 | + |
| 4 | +import * as endpoints from '../endpoints'; |
| 5 | + |
| 6 | +export default class CrossSell { |
| 7 | + constructor(api) { |
| 8 | + this.api = api; |
| 9 | + } |
| 10 | + |
| 11 | + /** |
| 12 | + * @method crossSellTrain(pointsObj: object): Promise |
| 13 | + * @param {Object} pointsObj |
| 14 | + * |
| 15 | + * Sends a collection of "points" to populate a sparse matrix for cross-sell |
| 16 | + * analytics and related product tracking. The POST body is an object with a "points" key |
| 17 | + * and value filled with an array of "Point" objects |
| 18 | + * |
| 19 | + * Example pointsObj |
| 20 | + * |
| 21 | + * ``` |
| 22 | + * { |
| 23 | + * "points": [ |
| 24 | + * { |
| 25 | + * "custID": 1, |
| 26 | + * "prodID": 4, |
| 27 | + * "chanID": 2, |
| 28 | + * } |
| 29 | + * ] |
| 30 | + * } |
| 31 | + * ``` |
| 32 | + */ |
| 33 | + crossSellTrain(pointsObj) { |
| 34 | + return this.api.post(endpoints.crossSellTrain, pointsObj); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @method crossSellRelated(productId: Int, channelId: Int): Promise |
| 39 | + * @param {Int} productId |
| 40 | + * @param {Int} channelId |
| 41 | + * |
| 42 | + * Returns JSON of what products are similar to the productId in the query params. |
| 43 | + * { "products": [ RelatedProduct ] } |
| 44 | + * |
| 45 | + * Score == 1 means these products were purchased by the exact same set of customers. |
| 46 | + * Score == 0 means no customer has purchased both of these |
| 47 | + * |
| 48 | + * Example Request |
| 49 | + * |
| 50 | + * `/v1/public/recommend/prod-prod/3?channel=2 |
| 51 | + * |
| 52 | + * Example Response |
| 53 | + * |
| 54 | + * ``` |
| 55 | + * { |
| 56 | + * "products": [ |
| 57 | + * { |
| 58 | + * "id": 2, |
| 59 | + * "score": 0 |
| 60 | + * }, |
| 61 | + * { |
| 62 | + * "id": 1, |
| 63 | + * "score": 1 |
| 64 | + * }, |
| 65 | + * { |
| 66 | + * "id": 0, |
| 67 | + * "score": 0 |
| 68 | + * } |
| 69 | + * ] |
| 70 | + * } |
| 71 | + */ |
| 72 | + crossSellRelated(productId, channelId) { |
| 73 | + const query = `?channel=${channelId}`; |
| 74 | + const url = `${endpoints.crossSellRelated}${productId}${query}`; |
| 75 | + return this.api.get(url); |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +// @miniclass Point (CrossSell) |
| 80 | +// @field custID: Number |
| 81 | +// CustomerID number |
| 82 | +// |
| 83 | +// @field prodID: Number |
| 84 | +// ProductID number |
| 85 | +// |
| 86 | +// @field chanID: Number |
| 87 | +// Unique Channel ID number |
| 88 | + |
| 89 | +// @miniclass RelatedProduct (CrossSell) |
| 90 | +// @field id: Number |
| 91 | +// RelatedProduct ID number |
| 92 | +// |
| 93 | +// @field score: Number |
| 94 | +// RelatedProduct Similarity score |
0 commit comments