Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Nosto Search uses product and user behavior data from the Nosto Platform, so if you are implementing Nosto Search, first of all, you need to implement Nosto Platform to your website.
Your search engine will be ready after the Nosto representative enables the Search module for your account. Then you will need to integrate Nosto Search to the website.
By using a pre-built template that can be customized to fully match a website's design using built-in code editor directly in https://my.nosto.com/. In the code editor, you can fully customize the pre-built template's JavaScript, HTML, and CSS code. Changes to the template can be implemented either by client’s developers or Nosto team. Frontend integration uses Preact and JSX templates and renders search results page dynamically in website’s frontend, so no additional integration is needed to the backend. When using Nosto services, no development is needed from the client.
API integration - a robust Search GraphQL API allows to implement Nosto Search into any website or app and gives complete flexibility for developers to build frontend and backend features.
For frontend integrations you can also use our JavaScript library. This library wraps the Search GraphQL API and provides its functionality in a programmatic way.
Can be implemented by Nosto team
Yes
No
No
Expected time to launch live
1-3 weeks*****
4-8 weeks
3-6 weeks
Headless compatible
Yes
Yes
Yes
Fully customizable frontend
Yes
Yes
Yes
Customized and managed only in Nosto dashboard
Yes
No
No
Suitable for complex use cases
Sometimes
Yes
Yes
* This estimation is based on the merchant's team building the templates. When Nosto's frontend team builds templates via the Code Editor, this can take longer due to overall bandwidth from the team.
If you are looking for a fast launch without much effort we recommend going with the fully customizable pre-built templates. This type of integration does not support full API access but comes complete with an out-of-the-box search result page and autocomplete templates that can easily be customized to match most website designs and integrate even advanced custom functionality.
If however you need full control over the search frontend or require complex custom functionality we recommend to go with the API or JavaScript integrations. These integrations do not provide out-of-the-box templates but provide direct access to the Search API, allowing you use the data in whatever way is required for your use cases.
To create a search application, call the init
function with your configuration. This will create a new Preact application that renders on the specified contentCssSelector
. It will also bind to the input element identified by the provided inputCssSelector
and execute a search upon form submission.
In the example above, we supply serp query parameters as an object. Additionally, the serpQuery
parameter can also be supplied as a function. The function flavor can be used for building complex query parameters and provides access to other pre-defined configuration parameters. Section below shows an example of serpQuery
supplied as a function which provides the product variation id by accessing the pre-defined variationId
method from the default configuration.
The full list of Configuration options is documented here
When serpPath
parameter is specified, the application will redirect to the specified search page after a search is conducted. Otherwise, the search will be rendered on the same page without changing the URL path.
When serpPathRedirect
parameter is set to true
, the application after search submission will redirect the page to the search page specified in serpPath
and fetch the page. Default behaviour will rewrite browser history only to the specified path, without fetching the page.
To prevent events from firing on an existing input, you need to provide the CSS selector of the form that the input is in to the initialization configuration. When optional fromCssSelector
is passed, it will unbind the form and the elements inside from existing events. Additionally, formUnbindDelay
in milliseconds as value can be passed to delay the unbinding functionality.
The search results page component should render a full search page using the provided app state. A minimal example might look like this:
When the compressUrlParameters
flag is set to true
, it automatically applies the URL parameter compression functions for filters, sort and pagination.
@nosto/preact
library has pre-built functions for changing search url format:
Pagination
Replaces from
parameter with page number.
Before:
/search?products.from=20&q=shorts
After:
/search?page=2&q=shorts
Sorting
Returns shorter sort
parameters.
Before:
/search?q=shorts&products.sort.0.field=price&products.sort.0.order=desc
After:
/search?q=shorts&products.sort=price~desc
Filtering
Compresses filter
parameters. Multiple filter
values are separated by a comma, which is encoded. This is because filter
values can contain non-alphanumeric letters themselves.
Before:
/search?q=shorts&products.filter.0.field=customFields.producttype&products.filter.0.value.0=Shorts&products.filter.0.value.1=Swim&products.filter.1.field=price&products.filter.1.range.0.gte=10&products.filter.1.range.0.lte=30
After:
/search?q=shorts&filter.customFields.producttype=Shorts%7C%7CSwim&filter.price=10~30
In addition to the compressUrlParameters
flag the serpUrlMapping
should be used to control the mapping from URL parameter keys to paths in the internal query object. The default looks like this:
The key is the internal path in the query model and the value is the query parameter name that should be used in the URL.
The stats facet returns the minimum and maximum values of numerical fields from search results. This functionality is especially useful when creating interactive elements such as sliders and range selectors. For instance, a price slider can use these min-max values to define its adjustable range, providing a simple way for users to filter products within a specific price range. Similarly, these values are utilized in the RangeSelector to define the overall scope of range selections, allowing for the configuration of selection precision through the range size parameter.
Range Slider
Utilize the useRangeSlider
hook to generate useful context for rendering range inputs. Additionally, employ the component to generate the interactive slider itself. These tools together facilitate the creation of dynamic and interactive range sliders for your application.
Range Selector
If you require an alternative method where values are selected through radio buttons rather than a slider, consider using useRangeSelector
hook. This tool allows users to choose from predefined range intervals with radio buttons, offering a different interaction style.
The range size parameter in the useRangeSelector
hook specifies the size of each interval in the range and determines the total number of range items displayed. Additionally, it automatically rounds the minimum value down to ensure intervals are aligned with the specified range size.
For example, if the minimum product price in the current catalog is 230, and the maximum product price is 1000, the range size of 200 will adjust the starting point to 200 and create intervals displayed under the "Price" filter as follows:
200 - 400
400 - 600
600 - 800
800 - 1000
The terms facet returns field terms for all products found in the search. This feature analyzes the content of each product and extracts meaningful terms. These terms can then be used to filter or refine search results, providing users with a more accurate and targeted product search.
You can use the toggleProductFilter
function to toggle any filter value. This function will either add the filter value if it's not already applied or remove it if it's currently active, thus providing an efficient way to manipulate product filters in your application.
Use the usePagination
hook to generate useful context for rendering any desired pagination. Utilize the width parameter to adjust how many page options should be visible. Also, remember to scroll to the top on each page change to ensure a seamless navigation experience for users.
Nosto search-templates library provides a simple out-of-the-box solution to implement infinite scroll functionality. Simply wrapping your product rendering with the <InfiniteScroll>
component is generally enough.
As the user scrolls the page down, the wrapper will detect it using the IntersectionObserver
. If it is not supported by the user's browser, a 'load more' button will be shown instead.
When using infinite scroll, consider enabling persistent search cache as well. When this feature is enabled, the latest search API response will be automatically cached and stored in the browser's session storage.
This improves the user experience significantly when the user navigates from a product details page back into the search results using the browser's 'back' function. The data necessary to display the products is already available, and the user will see the products immediately, without waiting for them to load again.
This feature is useful for both paginated and infinite scroll, but the benefits are significantly more visible with the latter.
Since the code editor utilizes the Preact framework, it offers significant flexibility in customizing behavior or integrating the search page with existing elements on your site. For instance, you can implement actions such as 'Add to Cart', 'Wishlist', or 'Quick View'.
Nosto will attempt to display the original search results in case Nosto service is unavailable or can't be reached. In addition, the original products are made available for the SEO crawlers, improving the page's ranking in the search engines. To make it possible, it's recommended to hide the original search results instead of removing or blocking them.
The best approach is to add ns-content-hidden
class name to the same element you are targeting with contentCssSelector
or categoryCssSelector
. This class name will be stripped away by Nosto automatically as soon as the script is initialized.
In addition, you should define CSS to hide the target element:
Search automatically tracks to Google Analytics & Nosto Analytics when using SerpElement
component.
Component parameters:
hit
Product object.
as
Element to render <SerpElement />
as. Recommended to use as="a".
If a element is used, href attribute is added automatically.
onClick (optional)
Additional onClick callback (tracking callback is already implemented in the component).
The SerpElement
component supports any other HTML attribute, e.g. class.
The search page incorporates built-in fallback functionality, allowing users to customize the behavior in case the search service encounters issues. To activate this feature, modify the initialization configuration to include the fallback: true
key-value pair.
To enable fallback functionality, include the following code in the initialization configuration:
Once fallback is enabled, if the search request fails to retrieve data, the search functionality will be temporarily disabled for 10 minutes, and the original content Nosto has overridden will be restored.
The fallback: true
setting only works out of the box if the path is the same for both the dedicated Nosto search page and the native search page, as well as for category pages.
If the paths differ, you must configure the serpFallback
or categoryFallback
function to ensure proper redirection. See: Customizing Fallback Location
If the behaviour described above is undesirable, the configuration supports an alternative option. Fallback mode can be set to fallback: 'legacy'
, in which case the user will see a page reload if the search request fails. After that, Nosto will not attempt to override the original search results or category pages for 10 minutes.
This behaviour has been the default fallback behaviour before August 20, 2024.
Additionally, it's possible to customize the location to which users are redirected when the search functionality is unavailable. This customization involves specifying functions for both the search engine results page (SERP) and category pages.
To redirect users to a specific location when the search engine is down, define a function for serpFallback
. This function accepts one parameter containing information about the current search query, including the query itself.
Similarly, for category pages, define a function for categoryFallback
. This function also accepts one parameter containing information about the current query, including the category ID or Path.
By customizing these fallback locations, you can enhance the user experience by providing them with alternative navigation options if the search functionality is temporarily unavailable.
Nosto Search engine is relevant out of the box and search API can be used without any initial setup. Nosto Dashboard can be used to further tune search engine configuration:
Searchable Fields - manage which fields are used for search and their priorities,
Facets - create facets (filtering options) for search results page,
Ranking and Personalization Ranking and Personalization - manage how results are ranked,
Synonyms, Redirects, and other search features are also managed through Nosto Dashboard (my.nosto.com).
With the Nosto debug toolbar, you can see all the changes made to your website right away. To enable this feature, simply turn on the preview mode. After saving any changes in the code editor, you will be able to see them directly on your website.
Navigate to your website
In the URL, append ?nostodebug=true
to enable the debug toolbar
The Nosto debug toolbar should open up, where you will be asked to log in
Once you have logged in, enable the Preview toggle button at the bottom
You should now be able to view your changes live, via the Search box
Before each deployment search should be manually tested to ensure that everything works correctly.
Autocomplete returns results
Search displays results, facets with counts
You can select multiple facets (on the same field and different fields)
Sorting is working
Pagination is working
Test both mobile & desktop view using Chrome device simulation.
When you finished working on search implementation & carefully tested everything using Nosto debug toolbar, it's time to deploy everything.
Navigate to the Nosto Admin UI
> Search
> Templates
Click on Deploy latest and launch live
It can take up to 15 minutes for deployment to be visible
If the most recent update doesn't work properly, you have the option to revert to any previous update. Reverting won't alter the source, which means you can deploy the latest changes again simply by clicking on the main deployment button.
Navigate to the Nosto Admin UI
> Search
> Templates
Click on the desired deployment, click on ...
and then on Redeploy
If your latest update doesn't work and you don't have a previous working version to go back to, or if you want to completely remove the search function, you can turn off the search templates for a temporary period.
Reverting won't alter the source, which means you can deploy the latest changes again simply by clicking on the main deployment button.
Navigate to the Nosto Admin UI
> Search
> Templates
Click on the Disable Templates
button.
Since Search Templates utilize the Search API under the hood, please also check the Search API FAQ
The functionality enables the sharing of a single instance of search templates across multiple dashboard accounts through linking. This feature proves particularly advantageous in scenarios where there are multiple websites with identical or similar characteristics that necessitate the creation of multiple dashboard accounts (such as supporting multiple languages or environments).
To link multiple accounts contact support!
Even if multiple websites share the same search templates code, we can easily have different logic based on website host or language (or other criteria).
Since it's not possible to target CSS rules by domain, it's recommended to add a special class to the page body and use it to target CSS rules.
By default, the search indexes all SKUs as a single product. Therefore, even when searching by a specific SKU attribute (like SKU color or ID), the search will return the main product along with all SKUs.
However, because the search returns all SKUs, SKU selection logic can be implemented on the frontend side. This is achieved by checking each SKU to see if it contains text from the search query.
These is an example on how to implement SKU selection:
By default, the search API returns 100 values for each facet, and it's not possible to control that limit in the dashboard. However, it is possible to override the facet configuration directly from the code.
The first step is to know the facet ID of the facet you want to overwrite. The facet ID is stored in the dashboard URL. For example, if you open the facet in the facet manager, the URL should be https://my.nosto.com/admin/shopify-123/search/settings/facetManager/6406df867f8beb629fc0dfb9
. This means the facet ID is 6406df867f8beb629fc0dfb9
.
Once the ID is known, it's possible to override any facet setting by specifying overwrite properties in the customFacets
parameter:
Although search engines can understand some JavaScript-rendered code, they often miss search templates. The reason for this is that the rendering of search templates is delayed in order not to hinder the page loading speed.
However, it's still possible to achieve great SEO results while using the code editor:
Category pages - Ensure that the category page already returns the correct meta tags and page title according to SEO recommendations, they bring the biggest impact to the SEO. In category page search templates render only products, so it doesn't significantly impact SEO. Most search engines support structured data (the category page backend should generate these tags using original products). However it does not have any big impact to the SEO. Furthermore, search engines may not favor the discrepancy between structured data and the actual rendered products (cause search engine will see either empty page with loader or nosto search results that are different compared to original).
Search pages - Most search engines don't index search pages, so no optimizations are needed.
If you still have concerns regarding SEO, please consider using API integration.
Category pages can be rendered using search templates over existing category pages.
To render the category page, provide additional configuration parameters to the init
function in the index.js
entry point file. Default configurations for categoryQuery
and isCategoryPage
are already provided. Custom configuration is necessary only if the default settings are not suitable for your application.
The default isCategoryPage
function checks for the presence of an element in the DOM and determines if the page should be considered a category page based on its content.
In the example above, we supply autocomplete query parameters as an object. Additionally, the categoryQuery
parameter can also be supplied as a function. The function flavor can be used for building complex query parameters and provides access to other pre-defined configuration parameters. Section below shows an example of categoryQuery
supplied as a function which provides the product variationId
by accessing the pre-defined categoryId
and categoryPath
methods from the default configuration.
If you want to integrate only Categories without Search or Autocomplete, ensure that the following entries are removed or commented out:
serpComponent
historyComponent
autocompleteComponent
Nosto will attempt to display the original category page products in case Nosto service is unavailable or can't be reached. In addition, the original products are made available for the SEO crawlers, improving the page's ranking in the search engines. To make it possible, it's recommended to hide the original category page products instead of removing or blocking them.
The best approach is to add ns-content-hidden
class name to the same element you are targeting with contentCssSelector
or categoryCssSelector
. This class name will be stripped away by Nosto automatically as soon as the script is initialized.
In addition, you should define CSS to hide the target element:
The isCategoryPage
function should detect whether the current page is a category page. Its result should not be cached, as it needs to dynamically detect the page type since it can change during the app's execution. For example, if the user navigates from a category page to a search page, the function should reflect that change in page type.
The categoryQuery
should generate a category page query based on the current page. It must return either categoryPath
(identical to the categories
field filter) or categoryId
to select the current category. The default implementation extracts the categoryId
and categoryPath
fields from the DOM.
The category component should also be implemented. In most cases, it is the same component as the search page component, except that the search query should not be displayed.
The category page shares a lot of similarities with the search page, so please refer to the search page documentation:
Search automatically tracks to Google Analytics & Nosto Analytics when using the SerpElement
component.
Search Templates allow you to add a search function to your website quickly and easily without the need to use an API. You can customize the design of your search pages and autocomplete boxes to match your brand's look and feel. This saves you a lot of time compared to implementing search functionality through an API.
To get started with Search Templates on your website, navigate to the Search tab under 'On-site' within the Nosto UI. This is where everything for Search can be configured and controlled, including designing the templates for search pages and autocomplete dropdowns, as well as search analytics, query rules and other settings. Synonyms for search queries can also be configured here.
To begin implementing Search, navigate to the Templates tab under Search, and Click on “Open Code Editor”.
You will then be redirected to the Code Editor window, where you can see and edit all project files.
Search Templates ship with a library called @nosto/preact
that contains functionality to interact with the Nosto Search product. API documentation for the library is available here
Project structure has the following requirements:
index.js
- this is application entry point that is used when building project. When building project it will recursively scan this file for imports.
build/
- this directory stores build output that will be used when deploying project.
After saving changes (CTRL + S
) build should be triggered and bundled code should be uploaded to CDN. You can preview final result on your website and deploy it when ready.
Additionally, please refer to for further useful information!
Due to performance optimization, the search function will calculate the total count up to 10,000. In this case the search page should display a count of 10,000+
to indicate that more than 10,000 products were found.
Filters and sorting operations are executed on all found products, even if there are more than this limit. Therefore, it's still possible to find other products if you filter or sort them. This should not affect the user experience in any way because it's unlikely that someone would actually view more than 10,000 products with a single search.
As soon as you use the results delivered by Nosto API, you will see that the listings in categories have a different order than listings delivered by your native shop-system, even if you didn't set up any merchandising rules. The products are mainly delivered as indexed during the data sync, but there is no defined behaviour for this. We recommend to always set up at least one global rule before going live with Nosto category merchandising to create product listings matching your business strategies.
Nosto provides functionality to retrieve all products for a specific category. This is useful when you want to implement category merchandising using the same API as for Search.
Using the category ID is only fully supported for Shopify merchants. Others should use the category path instead to benefit from full functionality.
Provide the API parameter to fetch all products associated with that category. Additionally should be provided for better analytics data.
Depending on your configuration, fetching a parent category will also include products from the child categories. For example, fetching products for the category Pants
would also include products from the categories Pants -> Shorts
and Pants -> Khakis
.
This is an admin-only setting. Please contact your Nosto representative to adjust this setting.
The category page shares a lot of similarities with the search page, so please refer to the search page documentation:
For client-side/frontend integrations, Nosto's JavaScript library can be used to simplify the integration. It provides a programming interface to access the Search & Categories API.
For the most basic search the fields
parameter should be provided to specify what product/keyword fields should be returned. Both products
and keywords
can be used separately and together, depending on the use case. For all parameters, see the .
The api.search
function also accepts the following options:
The function automatically loads session parameters required for personalization & segments in the background.
In order to request custom fields, add the entries "customFields.key"
and "customFields.value"
to the requested product fields. This changes the example above like this
For a search page in most cases the facets
parameter should be provided.
Also redirect
& track
should be enabled to automatically track searches to Nosto analytics & redirect if API returns a redirect request.
isKeyword
should be set to true
if search is submitted by clicking a keyword, suggested in the autocomplete.
track
should be enabled to automatically track searches to Nosto analytics.
Furthermore redirect
& track
should be enabled to automatically track searches to Nosto analytics & redirect if API returns a redirect request.
For some of the search features to work properly, such as personalised results and segments, the search function needs to be able to access information about the user's session from the front-end.
The search function of the JS API already includes session state automatically.
To get all session data the following snippet can be used:
The function accepts the following options:
Tracking search events to analytics can be divided into three parts: search
, search submit
, search product click
. These are user behaviours that should be tracked:
search submit (type = serp
)
faceting, paginating, sorting (type = serp
) or (type = category
)
autocomplete input (type = autocomplete
)
search results product click (type = serp
), (type = autocomplete
) or (type = category
)
autocomplete keyword click (type = autocomplete
)
category merchandising results (type = category
)
JS API library provides tracking helpers for all of these cases.
User actions that lead to search results should be tracked with api.recordSearch()
after search request is done:
search submit (type = serp
) - user submits search query in autocomplete component and is landed to SERP
faceting, paginating, sorting (type = serp
) or (type = category
) - user adjusts current search results by filtering (e.g. brand), selecting search page, sorting results
autocomplete input (type = autocomplete
) - user sees partial results while typing in search input
category merchandising results (type = category
) - user sees specific category results when category is selected (category merchandising must be implemented)
You don't need to execute api.recordSearch()
if you call api.search(query, { track: 'serp'|'autocomplete'|'category'})
function from JS API, becauseapi.search()
already calls api.recordSearch()
when track
option is provided.
Example:
Example:
Example:
Search queries are categorised into two groups: organic and non-organic searches.
In order to mark a search query as an organic search you need to call api.recordSearchSubmit(query: string)
. You should call it on search input submit only, before search request is sent.
Organic search - is a search query submitted through search input and which lead to SERP (search engine results page). Following faceting, paginating, sorting queries on organic query is also counted as organic.
Product clicks should be tracked in autocomplete component, SERP, category page with api.recordSearchClick()
by providing component (type), where click occurred, and clicked product data:
Example:
When tracking events, adherence to the following criteria is essential for capturing detailed and valid data:
query
parameter:
The query
string is an essential component for event tracking.
If present, include products.sort
to track sorting behavior.
If applicable, incorporate products.filter
.
searchResults
parameter:
products.hits
array containing objects with a productId
is mandatory.
products.total
number to identify if the search has results.
For accurate pagination tracking, products.from
and product.size
must be included.
For identifying if the request was autocorrected include products.fuzzy
.
For category requests, either products.categoryId
or products.categoryPath
is mandatory.
Bear in mind that search queries are split between organic and non-organic searches. To classify a search as organic, it is crucial to invoke api.recordSearchSubmit()
upon the search input submission, before the actual search request is dispatched. This step is pivotal in ensuring the seamless tracking of organic searches through to the SERP.
Tracking product clicks is fundamental for understanding user interaction. Use api.recordSearchClick()
to monitor this actions correctly, specifying the type
and relevant hit data.
Autocomplete is an element shown under search input used to display keywords and products for a partial query.
Check out .
To enable autocomplete, additional configuration should be passed to init
function.
In the example above, we supply autocomplete query parameters as an object. Additionally, the autocompleteQuery
parameter can also be supplied as a function. The function flavor can be used for building complex query parameters and provides access to other pre-defined configuration parameters. Section below shows an example of autocompleteQuery
supplied as a function which provides the product variation id by accessing the pre-defined variationId
method from the default configuration.
When the autocomplete component is injected, by default it will become the next sibling of the input field. It is possible to override that behaviour by specifying the dropdownCssSelector
value. If this selector is specified, the dropdown will be injected as the last child of the specified element.
It can also be set to be the first child of the element by using the object selector syntax.
Wrap each keywords and product to AutocompleteElement
element - it will allow clicking or selecting the element directly with keyboard.
To submit a search directly from the autocomplete, use the <button type="submit">
element. This will submit the search form.
History component renders user search history. It is displayed when user clicks on empty search box.
HistoryElement
renders clickable element that triggers search event with provided query.
Autocomplete automatically tracks to Google Analytics & Nosto Analytics when using <AutocompleteElement />
component.
Autocomplete provides keyword suggestions to assist users in completing their queries, supplemented by a selection of the most relevant products with the ability to see all products on the search results page.
Check out .
When integrating Autocomplete you have the option to directly access the API, or you can use our existing that provides most of the required functionality out of the box.
API can return highlights indicating which parts of a keyword match the search query. This HTML can be used to render and emphasize the matching sections during display.
API only returns redirect url, the actual browser redirect must be implemented by the merchant on keyword selection
Each autocomplete product click should be tracked as a search page virtual view to ensure that the Google Analytics search feature displays the correct conversion rate. For example, if you click any product when the typed query is phone
it should track a virtual page view with the URL /search?q=phone
(adjust the search path and query parameter to match your search page).
Since a product link click would redirect to a new page, to ensure that Google Analytics has time to send the tracking request, it's recommended to save the search query to local storage and track it on page load.
For a basic search, it’s enough to provide accountId
, query,
and select fields that should be returned. You can control which product attributes to select through products.hits
field. See .
For example, if you want to return only productId
and name
, the query would be:
Products offset parameter from
is used for pagination functionality.
The default count of documents returned per page is size = 5
, you can change it with products.size
, and offset of products is controlled with products.from
field:
By default results are sorted by products relevance score.
To change the sorting, use the sort parameter, where you would specify any indexed field which should be sorted by, and order: asc
for ascending and desc
for descending.
By default, you should always sort by relevance. Only if the user selects a different sort method, a sorting rule should be used.
Facets help the user to find products more easily. Faceted navigation is normally found in the sidebar of a website and contains filters only relevant to the current search query. Facets are configured in the Nosto dashboard.
One of the facet types is type = terms
. It returns list if common terms from found documents.
Assume that we have configured facets for customFields.brandname
and categories:
Stats facet returns minimum and maximum number field value from found documents. The most common usage is to render slider filter (e.g. price)/
Filtering by terms
facet, for example by Adidas, Converse brands:
When filtering by multiple same field items, filters will be joined with OR operator and different fields with AND.
If you wish to have more facets, you should configure it in the Nosto dashboard first.
Filtering by stats
field, for example by price:
You can sort using these arguments: lt
(less than), gt
(greater than), lte
(less than or equal to), gte
(greater than or equal to).
Redirects can be used to forward users to special pages depending on their search keywords. For example, users searching for shipping
could be forwarded to https://example.com/shipping.html.
For API integrations GraphQL can only return the target URL. The actual browser redirect must be implemented by the merchant.
For features like personalised results and user segments to function effectively, the search function needs access to the user's session information from the front-end.
Nosto Search engine is relevant out of the box and search API can be used without any initial setup. Nosto Dashboard can be used to further tune search engine configuration:
Not all of Nosto's functionality is available for pure GraphQL API integrations. The following features require :
Analytics
Segmentation
A/B testing
Debug toolbar
Both Search and Categories are built on the same technical foundation and use the same API and product data. For simplicity, we will just refer to Search API in the following documentation.
Use the to try out search queries and browse API reference.
It provides:
- you can see field types and inspect what fields are needed for a search request.
- you can see return field types with descriptions.
Send requests to the search engine and preview the response.
In the majority of cases, authentication is not a requirement for using search APIs. However in rare case may need to:
Access sensitive data- all sensitive data is restricted for public access (e.g. sorting by & returning sales).
Return all documents - public access require to specify search query, category ID or category path to avoid returning all documents.
Note: Keep your API key secret and do not expose it to the frontend!
Search use different API endpoint than other Nosto queries: https://search.nosto.com/v1/graphql
All requests require an account ID, which can be found in the top-right corner of the Admin dashboard, under the shop name.
Replace YOUR_ACCOUNT_ID
with your account id retrieved from the Nosto dashboard.
Replace YOUR_ACCOUNT_ID
with your account id retrieved from the Nosto dashboard.
Replace YOUR_ACCOUNT_ID
with your account id retrieved from the Nosto dashboard.
Replace YOUR_ACCOUNT_ID
with your account id retrieved from the Nosto dashboard.
Upon a successful request, the API will return a 200 status code response, which includes the search data:
API returns a list of errors with explanations. These errors should be logged internally and not displayed to the end user. Instead, display a general message, such as Search is unavailable at the moment, please try again
. This approach ensures that no sensitive information is leaked to the end user.
The API may return some errors even when data is returned. This means that some parts of the response may be missing, but you should still display the available data instead of showing an error to the user. These errors should be logged internally for future reference and troubleshooting.
For features like personalised results and user segments to function effectively, the search function needs access to the user's session information from the front-end.
To optimize search speed and reduce network load, select only the necessary data when performing a search query.
Variables should encompass all dynamic query data because it is the most efficient method to pass data, and data is automatically escaped to prevent injection attacks. Avoid generating dynamic queries, as they can lead to security issues if user input is not properly escaped.
Product fields that can be requested in the hits
object are documented . All indexed fields are accessible via the API.
Provide the API parameter to fetch all products associated with that category. This parameter is the same as the categories
product field.
Product fields that can be requested in the hits
object are documented . All indexed fields are accessible via the API.
In some rare cases or is not enough. In these cases can be used to build any query for category & landing pages.
To analyze user behavior you need to implement tracking. This can be achieved using our . You need to implement the following methods with type = category
:
to track category page visits
to track clicks on category results
For category pages in most cases the facets
parameter should be provided. Additionally (for Shopify) and should be also provided.
The results of this function should be passed to search query parameter. In case search is called from backend, it should pass this data to backend (e.g. using ).
On errors from api.search
calls the error object contains a status field that has the HTTP response status which can be used to determine the cause of the error in addition to the error message. The ranges of the status codes used for errors are 400-499 and 500-599. For details on these error codes, go to
The tracking metadata is primarily taken from the third parameter. The and objects must be provided in the api.recordSearch
call instead of partials.
Tip: In case of API integration, use this example GraphQL partial query to integrate with the API and retrieve the necessary response data for precise event tracking.
The full list of Configuration options is documented
Redirects are configured in the search dashboard and can be used to forward users to specific pages depending on what they type into the search field. For example, users searching for "shipping" could be directed to .
To analyze user behavior you need to implement tracking. This can be achieved using our . You need to implement the following methods with type = autocomplete
:
to track users typing in the search field and viewing suggestions
to track clicks on autocomplete suggestions
Additionally, see the .
See all .
To use facet for a specific field you need to first.
It's possible to get search session data using the :
The results of this function should be passed to search query parameter. In case search is called from backend, it should pass this data to backend (e.g. using ).
To analyze user behavior you need to implement tracking. This can be achieved using our . You need to implement the following methods with type = serp
:
to track search result interactions like filtering and pagination
to track result clicks
- manage which fields are used for search and their priorities,
- create facets (filtering options) for search results page,
Ranking and Personalization - manage how results are ranked,
Synonyms, Redirects, and other search features are also managed through Nosto Dashboard ().
with API_SEARCH
Role is available on dashboard settings page
When integrating Search you have the option to directly access the API, or you can use our existing that provides most of the required functionality out of the box.
JS API includes full-featured with tracking support.
It's possible to get search session data using the :
The results of this function should be passed to search query parameter. In case search is called from backend, it should pass this data to backend (e.g. using ).
It's also possible to save session data to on page load:
In the search application, you should use variables instead of hardcoded arguments to pass search data. This means that filters, sort, size, and 'from' options should be passed in the 'products' variable. For a full list of available options, please see the .
To analyze user behavior you need to implement tracking. This can be achieved using our . You need to implement the following methods:
to track search form submissions
maxWait
2000
Maximum execution time in MS
cacheRefreshInterval
60000
Maximum cache time
type
Search type: serp
, autocomplete
, category
request
result
options (optional)
Record search options. Currently is accepts:
isKeyword: boolean
- should be set when keyword in autocomplete is clicked (search is submitted via keyword)
type
Search type: serp
, autocomplete
, category
hit
Object containing productId
and url
, collected from clicked product
accountId
Nosto account ID
query
search query text
id
internal facet ID, used to select specific facets in query
field
facet field, should be used for filtering
type
facet type, in this case terms
name
user friendly facet name configured in the dashboard
data.value
original facet value, it should be displayed in the user interface
data.count
shows how many products will be returned if you select this facet, it should be displayed in the user interface
data.selected
indicates if there is an active filter on this value
name
user friendly facet name configured in the dashboard
terms
facet type, in this case stats
field
facet field, should be used for filtering
id
internal facet ID, used to select specific facets in query
min
minimum field value for documents that match provided query
max
maximum field value for documents that match provided query
Authorization
Bearer SEARCH_KEY
redirect
false
Automatically redirect if search returns a redirect
track
null
Track search query by provided type
You can install the Nosto Autocomplete
library via npm:
The Nosto Autocomplete library can be imported and used in various ways, depending on your preferred framework or template language. Some of the supported import methods include:
Base
import { autocomplete } from "@nosto/autocomplete"
Mustache
import { autocomplete, fromMustacheTemplate, defaultMustacheTemplate } from "@nosto/autocomplete/mustache"
Liquid
import { autocomplete, fromLiquidTemplate, defaultLiquidTemplate } from "@nosto/autocomplete/liquid"
Preact
import { autocomplete, Autocomplete } from "@nosto/autocomplete/preact"
React
import { autocomplete, Autocomplete } from "@nosto/autocomplete/react"
Choose the import method that aligns with your project's requirements and technology stack.
❗Do not combine multiple imports as it will fetch multiple bundles.❗
Nosto Autocomplete library is designed to simplify the implementation of Search Autocomplete functionality by providing: 🌟 Autocomplete products, keywords and history visualization. 🔄 Automatic bindings to Nosto Search API. 🧩 Autocomplete component state management. 📊 Nosto Analytics out of the box, Google Analytics support. 🏗️ Default Autocomplete components and templates. 🎮 Keyboard navigation.
When submitting Search results through Autocomplete, submit
callback is called on these events:
Enter
key press.
Submit button
click.
Keyword
click.
By default submit
checks if query/keyword length satisfies minQueryLength
, sends Search Submit event
to Nosto Analytics, and sends Search request to the Nosto Search API.
In the usual scenario, you want to render Search Results on submit, so you should override submit
function:
To disable submit
pass undefined
value.
\
Setting nostoAnalytics: true
will enable Nosto Analytics tracking. Tracking results can be seen in the Nosto Dashboard under Search & Categories -> Analytics page.
❗Note: you should additionally add click events on your search results page according to Nosto Tech Docs with type: serp || category
according to the results page type.❗
\
By default we send pageview
events to existing GA tag, found in shop site. To send pageview
events with correct search information, a minimal configuration is needed in googleAnalytics
property.
serpPath
- Search query url parameter name
queryParamName
- Search query url parameter name
enabled
- Enable Google Analytics
For example, if search results URL is https://examplenostoshop.com/search-results?query=shoes, then configuration should be:
To disable Google Analytics, set googleAnalytics: false
.
After installation, you can import and use the library in your JavaScript or TypeScript files. Library attaches to existing search input element. Once a search input is loaded, autocomplete
function can initialize event listeners for the Search Autocomplete.
❗autocomplete
should be called once.❗
inputSelector
Yes
N/A
Input element to attach the autocomplete to
dropdownSelector
Yes
N/A
Dropdown element to attach the autocomplete to (empty container's selector should be provided)
render
Yes
N/A
Function to render the dropdown
fetch
Yes
N/A
Function to fetch the search state
submit
No
Search API request
Function to submit the search
minQueryLength
No
2
Minimum length of the query before searching (applied on typing in autocomplete and used in default submit
implementation)
historyEnabled
No
true
Enables search history component
historySize
No
5
Max number of history items to show
nostoAnalytics
No
true
Enable Nosto Analytics
googleAnalytics
No
{ serpPath: "search", queryParamName: "query", enabled: true }
Google Analytics configuration. Set to false
to disable
hitDecorators
No
N/A
Decorate each search hit before rendering
Once the autocomplete component binds to input via inputSelector
and dropdownSelector
, it then renders autocomplete provided in a render
function. It is called on input focus and change events, and renders a dropdown element with the current search result state:
if input is empty and history entries exist, it renders dropdown with history list,
if input is not empty and it passes minQueryLength
rule, it render dropdown with keywords and products.
Render can be adjusted to the desired framework. Moreover, the library provides helpers for Mustache/Liquid template languages.
Examples
Suppose index.html
is
List of autocomplete
initialization examples:
Liquid
Example below uses fromLiquidTemplate
helper which renders string template. Library provides default autocomplete template via defaultLiquidTemplate
and default css for default template:
The template also can be loaded from a file. The library includes a default template, equivalent to string template in above example:
Mustache Mustache template is rendered similarly as Liquid template in the above example:
Or from a file:
React/Preact
One way to initialize autocomplete in a React app, is to call autocomplete
from the useEffect
on component mount, using default <Autocomplete />
component and styles:
The Preact solution does not differ from React a lot:
The library handles events through dataset
properties to avoid handling logic in a template. These data-*
attributes are used:
data-ns-hit
- this attribute should be used on clickable keyword
, product
, history
list elements. Stringified unmodified JSON object (product, keyword or history hit) from the search response should be provided as a value. You will need to escape it in Liquid and Mustache templates.
This attribute handles submit keyword/history as search, redirect to product, analytics (if enabled) request.
data-ns-remove-history
- should be used to delete history entries in the autocomplete.
To make an element delete a single history entry when clicked, add data-ns-remove-history={hit.item}
to an element.
To delete all history entries, add data-ns-remove-history="all"
to clear button.
Template examples: Mustache, Liquid, React/Preact
Mustache is based on logic-less templates which can be enhanced with helpers, e.g toJson
, imagePlaceholder
, showListPrice
in example template.
See library TypeDoc page to see more detailed documentation of the library.