The Suggestions Plugin can be used to implement a standardized version of the Tweakwise suggestions in your platform.
๐ View live demo of Suggestions
Installation
Make sure you have followed the Installation guide.
Initialization
The Suggestions plugin needs to be initialized manually. To do this, copy the following snippet into your HTML.
<script>
window.addEventListener("twn.suggestions.ready", function () {
window.tweakwiseSuggestions({
input: "INPUT",
instancekey: "INSTANCEKEY",
cid: "CID"
});
});
</script>
The only thing that is left is to replace INPUT
, INSTANCEKEY
and CID
with the correct values.
The INPUT
should be replaced with a valid CSS selector leading to an existing search input on the page. This input will be used as the source for the suggestions.
The INSTANCEKEY
should be replaced with your own instance key. You can find it in Tweakwise on the Connectivity > Endpoints page.
The CID
should be replaced with the root category ID of the search results.
If you have multiple input fields where you want to use the Suggestions (for example one for mobile and one for desktop), you can add this script multiple times. Once for each input field you want to use.
Search phrase suggestions
The Suggestions plugin supports search phrase suggestions out-of-the-box. However, when using search phrases grouped by category additional configuration may be required. When the user selects a search phrase with a category, the category id will be added to the query string of the target URL:
/search?q=searchphrase&tn_cid=100012
By default tn_cid
is used to add the category id to the URL. However, it is possible to override this value:
<script>
window.addEventListener("twn.suggestions.ready", function () {
window.tweakwiseSuggestions({
input: "INPUT",
instancekey: "INSTANCEKEY",
cid: "CID",
searchPhrases: {
categoryKey: "tn_cid" // <-- Configure the URL key here
}
});
});
</script>
Category & facet suggestions
Category and facet suggestions are not displayed out-of-the-box. Additional configuration is required. For both types a function should be implemented that navigates to the correct page when the user selects these suggestions:
<script>
window.addEventListener("twn.suggestions.ready", function () {
window.tweakwiseSuggestions({
input: "INPUT",
//..
categories: {
handle(event) {
var suggestion = event.data;
// Handle category suggestion here...
}
},
facetFilters: {
handle(event) {
var suggestion = event.data;
// Handle facet suggestion here...
}
}
});
});
</script>
For detailed examples, see Category suggestion navigation.
Note: if the handle option is not defined, the corresponding type of suggestions will not be shown.
Product suggestions
The Suggestions plugin supports product suggestions out-of-the-box. For this type of suggestions no additional configuration is needed.
Redirects
The Suggestions plugin supports redirects out-of-the-box. Whenever the user selects a search phrase that is associated with a redirect, the user will be redirected to the configured page.
Popular modifications
Some popular modifications related to suggestions: