-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1162 from searchspring/recs-fixes
Recs Fixes
- Loading branch information
Showing
15 changed files
with
601 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,17 +11,20 @@ It is recommended to utilize the [`RecommendationInstantiator`](https://github.c | |
</script> | ||
``` | ||
|
||
The `RecommendationInstantiator` will look for these elements on the page and attempt to inject components based on the `profile` specified. In the example above, the profile specified is the `recently-viewed` profile, and would typically be setup to display the last products viewed by the shopper. These profiles must be setup in the Searchspring Management Console (SMC) and have associated Snap templates selected. | ||
The `RecommendationInstantiator` will look for these elements on the page and attempt to inject components based on the `profile` specified in the script attribute. In the example above, the profile specified is the `recently-viewed` profile, and would typically be setup to display the last products viewed by the shopper. These profiles must be setup in the Searchspring Management Console (SMC). | ||
|
||
|
||
## Recommendation Context Variables | ||
Context variables may be applied to individual recommendation profiles similar to how they are done on the integration script tag. Variables here may be required depending on the profile type utilized, and can be used to alter the results displayed by our recommendations. | ||
Profile configurations are applied to recommendation via script context variables. The variables here may be required depending on the profile type utilized, and can be used to alter the results displayed by our recommendations. When multiple recommendation integration script blocks are found, a batch will be created by default, and any profile configurations NOT in the `options` variable are applied globally to all profiles. | ||
|
||
| Option | Value | Page | Description | | ||
|---|---|:---:|---| | ||
| products | array of SKU strings | product detail page | SKU value(s) to identify the current product(s) being viewed | | ||
| cart | array (or function that returns an array) of current cart skus | all | optional method of setting cart contents | | ||
| options.siteId | global siteId overwrite | all | optional global siteId overwrite | | ||
| products | array of SKU strings | product detail page | SKU value(s) to identify the current product(s) being viewed (global) | | ||
| cart | array (or function that returns an array) of current cart skus | all | optional method of setting cart contents (global) | | ||
| blockedItems | array of strings | all | SKU values to identify which products to exclude from the response (global) | | ||
| filters | array of filters | all | optional recommendation filters (global) | | ||
| shopper.id | logged in user unique identifier | all | required for personalization functionallity if not provided to the bundle context (global) | | ||
| options.siteId | siteId overwrite | all | optional siteId overwrite (will force a new batch) | | ||
| options.categories | array of category path strings | all | optional category identifiers used in category trending recommendation profiles | | ||
| options.brands | array of brand strings | all | optional brand identifiers used in brand trending recommendation profiles | | ||
| options.branch | template branch overwrite | all | optional branch overwrite for recommendations template (advanced usage) | | ||
|
@@ -30,16 +33,16 @@ Context variables may be applied to individual recommendation profiles similar t | |
| options.realtime | boolean | all | optional update recommendations if cart contents change (requires [cart attribute tracking](https://github.com/searchspring/snap/blob/main/docs/INTEGRATION_TRACKING.md)) | | ||
| options.blockedItems | array of strings | all | SKU values to identify which products to exclude from the response | | ||
| options.batched | boolean (default: `true`)| all | only applies to recommendation context, optional disable profile from being batched in a single request, can also be set globally [via config](https://github.com/searchspring/snap/tree/main/packages/snap-controller/src/Recommendation) | | ||
| options.dedupe | boolean (default: `true`) | all | specify wether or not the profile should deduplicate products when in a batch | | ||
| options.order | number | all | optional order number for recommendation params to be added to the batched request. Profiles that do not specify an order will be placed at the end, in the occurrence they appear in the DOM. | ||
| options.limit | number (default: 20, max: 20) | all | optional maximum number of results to display, can also be set globally [via config globals](https://github.com/searchspring/snap/tree/main/packages/snap-controller/src/Recommendation) | | ||
| shopper.id | logged in user unique identifier | all | required for personalization functionallity if not provided to the bundle (global) context | | ||
|
||
## Batching and Ordering | ||
By default, recommendation profile results are fetched in the same API request (batch), this is done in an effort to prevent the display of duplicate products across multiple profiles. The order of the profiles in the DOM determines the priority of results for de-duplication (best recommendations). If you wish to change the order, an `order` value can be provided (lowest value has highest priority). For some profiles (like product bundles) it is important that they receive the best suggested products prior to de-duplication, for these, the `order` would be set manually so that de-duplication does not occur. | ||
By default, recommendation profile results are fetched in the same API request (batch), this is done in an effort to prevent the display of duplicate products across multiple profiles. The order of the profiles in the DOM determines the priority of results for de-duplication (best recommendations). If you wish to change the order, an `order` value can be provided (lowest value has highest priority). For some profiles (like product bundles) it is important that they receive the best suggested products prior to de-duplication, for these, the `order` should be set manually so that de-duplication does not occur. | ||
|
||
In most cases batching is the best practice, however for profiles like a mini cart (side cart) de-duplication may not be desired. Batching can be turned off per profile with a `batched: false` value. | ||
In most cases batching is the best practice, however for profiles like a mini cart (side cart) de-duplication may not be desired. Using `dedupe` would allow for opting out of deduplication for that profile in the batch. | ||
|
||
The example below shows how to manually specify the order and batching of specific profiles. | ||
The example below shows how to manually specify the order of the profiles and how to dedupe them. In the example the 'bundle' profile in the batch receives the best suggestions because it has the lowest order, and the 'quick-cart' profile is not deduplicating products at all. | ||
|
||
```html | ||
<script type="searchspring/recommend" profile="customers-also-bought"> | ||
|
@@ -63,6 +66,21 @@ The example below shows how to manually specify the order and batching of specif | |
}; | ||
</script> | ||
|
||
<script type="searchspring/recommend" profile="quick-cart"> | ||
products = ['product123']; | ||
options = { | ||
dedupe: false | ||
}; | ||
</script> | ||
``` | ||
|
||
Alternatively, a profile can be placed in it's own batch via the `batched: false` value. The example below shows how to place the 'quick-cart' profile into it's own batch. | ||
|
||
```html | ||
<script type="searchspring/recommend" profile="bundle"> | ||
products = ['product123']; | ||
</script> | ||
|
||
<script type="searchspring/recommend" profile="quick-cart"> | ||
products = ['product123']; | ||
options = { | ||
|
@@ -73,28 +91,28 @@ The example below shows how to manually specify the order and batching of specif | |
|
||
## Additional Examples | ||
|
||
The examples below assume that the `similar` profile has been setup in the Searchspring Management Console (SMC), and that a Snap `bundle.js` script exists on the page and has been configured with a `RecommendationInstantiator`. | ||
The examples below assume that profiles used have been setup in the Searchspring Management Console (SMC), and that a Snap `bundle.js` script exists on the page and has been configured with a `RecommendationInstantiator`. | ||
|
||
A typical "similar" profile that would display products similar to the product passed in via the `product` context variable. | ||
|
||
```html | ||
<script type="searchspring/recommend" profile="customers-also-viewed"> | ||
products = ['product123']; | ||
<script type="searchspring/recommend" profile="similar"> | ||
products = ['sku123']; | ||
</script> | ||
``` | ||
|
||
If tracking scripts are not in place, "also bought" profiles may require the cart contents to be provided. | ||
|
||
```html | ||
<script type="searchspring/recommend" profile="view-cart"> | ||
cart = ['product123']; | ||
cart = ['sku456']; | ||
</script> | ||
``` | ||
|
||
If the shopper identifier is not beeing captured by the `bundle.js` context, it must be provided for proper personalization. | ||
|
||
```html | ||
<script type="searchspring/recommend" profile="view-cart"> | ||
<script type="searchspring/recommend" profile="similar"> | ||
shopper = { | ||
id: '[email protected]' | ||
}; | ||
|
@@ -122,7 +140,7 @@ Having multiple scripts batched using the order context variable | |
``` | ||
|
||
### Filters | ||
The example shown below will filter the recommendations for products matching color: blue, & red, and price range 0 - 20. | ||
The example shown below will filter the recommendations for products matching field `color` with a value `blue` and `red`, as well as a field `price` with a range from `0` to `20`. | ||
|
||
```html | ||
<script type="searchspring/recommend" profile="customers-also-bought"> | ||
|
@@ -146,4 +164,30 @@ The example shown below will filter the recommendations for products matching co | |
] | ||
} | ||
</script> | ||
``` | ||
|
||
The next example shows a global filter being used, this will filter all of the profiles in the batch for products matching the field `onSale` with a value `true`; the 'similar' profile will additionally apply a filter using the field `price` with a range from `0` to `20`. | ||
|
||
```html | ||
<script type="searchspring/recommend" profile="customers-also-bought"> | ||
filters = [ | ||
{ | ||
type: 'value', | ||
field: 'onSale', | ||
value: 'true' | ||
} | ||
]; | ||
</script> | ||
|
||
<script type="searchspring/recommend" profile="similar"> | ||
options = { | ||
filters: [ | ||
{ | ||
type: 'range', | ||
field: 'price', | ||
value: { low: 0, high: 20 } | ||
} | ||
] | ||
} | ||
</script> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.