beforeInstantSearchAsyncFunction
Use this hook to run asynchronous work (for example, an external API request) before InstantSearch sets any parameters.
Add several await statements to run tasks in sequence.
Parameters
This hook doesn’t accept parameters.Returns
This hook doesn’t return a value. Return aPromise to delay InstantSearch until your work completes.
Examples
Delay InstantSearch until an async task completes
Delay InstantSearch until an async task completes
Promise to pause InstantSearch while you run async work.beforeInstantSearchConfigurationOptions
Changes InstantSearch options.
Parameters
Returns
Examples
Customize InstantSearch configuration options
Customize InstantSearch configuration options
beforeInstantSearchOptions
Changes the following parameters:
Parameters
colorsdistinctfacetshitsPerPageselectorsortOrdersswatchRowLimit
Returns
Examples
Show fewer swatch chips in the row
Show fewer swatch chips in the row
swatchRowLimit sets how many swatch chips a product-level card shows in its row.
The rest go behind the +N button that opens the overflow panel.
Set it to 0 to remove the cap, so the row holds every option and no panel renders.Every option stays on the card either way.
To remove options altogether, use
beforeInstantSearchSwatchOptionResolver.beforeInstantSearchAllowParamsArray
Preserves URL parameters when navigating through the search results.
Parameters
Returns
Examples
Preserve a custom URL parameter
Preserve a custom URL parameter
ref to the allowlist so InstantSearch preserves it in the URL.beforeInstantSearchFiltersString
Changes the filter parameter of the search results page.
Parameters
Returns
Examples
Add a filter condition
Add a filter condition
beforeInstantSearchRuleContexts
Modifies the ruleContexts sent with InstantSearch queries.
Use this hook to trigger Rules based on page context, such as UTM parameters, customer segments, or custom page metadata.
On collection pages, the default contexts include the collection handle and shopify_default_collection.
Parameters
shopify_default_collection. On other pages, this is an empty array.Returns
Examples
Add rule contexts based on UTM parameters
Add rule contexts based on UTM parameters
utm_source URL parameter.beforeInstantSearchMainTemplate
Template for the main template container.
If you’re using the facet display feature,
include a div with class="ais-facets-container" to display the facets.
Parameters
Returns
Examples
Customize the main template
Customize the main template
beforeInstantSearchProductTemplate
Template for product hits in the search results.
When using this template,
also call trackSearchAttribution(hit) to properly handle events.
Parameters
hit._productLevel is true and the variants are nested under
hit.variants.
The chips to render are on hit._swatchOptions, each one shaped like the options
the swatch resolver returns, with _matched on the chip
the app preselected.
See Product cards.Highlight).algoliaShopify.helpers.handleItemClick.Returns
Examples
Customize product hits
Customize product hits
trackSearchAttribution(hit) to track events.Customize product-level hits
Customize product-level hits
variants[], so the card shows a swatch row and a price range instead of a
single variant’s price and an add-to-cart button.
Check hit._productLevel and keep your variant-level template for the other branch.Keep the class names and data- attributes from this example.
The app delegates chip clicks from the results container and reads them to retarget the card image,
the title link, and the overflow panel.beforeInstantSearchNoResultTemplate
Template for when there are no results.
Parameters
Returns
Examples
Customize the no results template
Customize the no results template
beforeInstantSearchStatsTemplate
Template for search stats
nbSortedHits:
the number of results Algolia considered were relevant enough to sort.
Use nbSortedHits to show a message such as “42 relevant results sorted out of 1,247”
instead of only the total hit count.Parameters
nbHits, nbSortedHits, page, and hitsPerPage.Returns
Examples
Customize the stats template
Customize the stats template
beforeInstantSearchTransformItems
Change items before they’re rendered.
Parameters
Returns
Examples
Mark out-of-stock items
Mark out-of-stock items
can_order to false for items with inventory_quantity equal to 0.beforeInstantSearchSwatchOptionResolver
Reorder or filter the swatch chips on a product-level card before the template renders them.
Only fires for product-level hits whose records carry swatch data.
swatchRowLimit with
beforeInstantSearchOptions instead.beforeInstantSearchTransformItems and edit _matched on
hit._swatchOptions.
Parameters
name, color, swatchImage, productImage, variantID, and available.Returns
Examples
Show the first five in-stock swatches
Show the first five in-stock swatches
afterInstantSearchSwatchClick
Runs after a shopper clicks a swatch chip.
The app has already marked the chip, swapped the card image, and re-pointed the card at the
selected variant before this hook runs.
This hook doesn’t use a return value.
The app doesn’t fire this hook for a chip it preselected on first render.
Parameters
swatchButton: element of the chip the shopper clicked.hitEl: card element that holds the chip.optionValue: name of the clicked option value.
Examples
Track swatch clicks
Track swatch clicks
beforeInstantSearchStartAddWidgets
Add InstantSearch widgets to the search results page.
You can add the following widgets:
clearRefinementsconfiguredynamicWidgetshierarchicalMenuhitsmenupaginationpanelrangeSliderrefinementListsearchBoxsortBystats
Returns
Examples
Add a custom widget
Add a custom widget
searchBox widget before InstantSearch adds default widgets.afterInstantSearchStartRemoveDefaultWidgets
Remove default widgets from the search results page.
You can remove these widgets (widget.$$widgetType):
ais.sortByais.searchBoxais.statsais.hitsais.pagination
Parameters
Returns
Examples
Remove a default widget
Remove a default widget
beforeInstantSearchFacetSearchablePlaceholder
Changes the searchablePlaceholder for facet search.
beforeInstantSearchFacetParamsOptions instead.Parameters
Returns
Examples
Change the facet search placeholder
Change the facet search placeholder
beforeInstantSearchFacetParamsOptions
Update widget parameters before they’re rendered.
Parameters
facet.type to determine the widget.titlenametype(refinement parameters)slider:rangeSlidermenu:menuconjunctive:refinementListdisjunctive:refinementList
Returns
Examples
Customize facet widget parameters
Customize facet widget parameters
facet.title or facet.type.beforeInstantSearchFacetPanelOptions
Update the panel parameters before they’re rendered.
Parameters
titlename
Returns
Examples
Customize panel parameters
Customize panel parameters
header, footer, and searchableNoResults.beforeInstantSearchInitSearchSortOrders
Transform sort order before they’re rendered.
Parameters
slice(0, -1) to collect the sort order objects. Each has:label(string): display name for the sort ordervalue(string): name for the sort order
Returns
Examples
Add a custom sort order
Add a custom sort order
beforeInstantSearchInitCollectionSortOrders
Transform the sort order for collections.
Parameters
slice(0, -1) to collect the sort order objects. Each has:label(string): display name for the sort ordervalue(string): name for the sort order
Returns
Examples
Add a custom collection sort order
Add a custom collection sort order
afterInstantSearchHitClickAction (deprecated)
beforeInstantSearchProductTemplate instead.Parameters
Returns
beforeInstantSearchFacetItemTemplate (deprecated)
beforeInstantSearchFacetParamsOptions instead.
The refinementList widget can be added as a parameter in the template object.Parameters
beforeInstantSearchShowMoreTemplate (deprecated)
beforeInstantSearchFacetParamsOptions instead.
The refinementList widget can be added as a parameter within the template object.showMoreText button.
Parameters
isShowingMore property.beforeInstantSearchFacetLimitNumber (deprecated)
beforeInstantSearchFacetParamsOptions instead.
The refinementList widget can be added as a parameter.limit (default: 10).
Parameters
Returns
beforeISFacetSearchablePlaceholderString (deprecated)
beforeInstantSearchFacetSearchablePlaceholder or
beforeInstantSearchFacetParamsOptions instead.
The searchablePlaceholder option can be added as a parameter in the template object.searchablePlaceholder.
Parameters
Returns
beforeISFacetSearchableNoResultsString (deprecated)
beforeInstantSearchFacetParamsOptions instead.
The searchableNoResults option can be added as a parameter in the template object.searchableNoResults.
Parameters
Returns
beforeInstantSearchFacetHeaderString (deprecated)
beforeInstantSearchFacetPanelOptions instead.
The header parameter can be added as a parameter in the template object.
To avoid duplicate headers, use the beforeInstantSearchMainTemplate hook and remove the ais-facet-dropdown-wrapper container.Parameters
Returns
beforeInstantSearchFacetTransformItemsOptions (deprecated)
beforeInstantSearchFacetParamsOptions instead.
Use transformItems as a parameter to transform the data.items before they’re rendered.
Parameters
Returns
beforeISTransformItems (deprecated)
beforeInstantSearchTransformItems instead.Parameters
Returns
afterISStartRemoveDefaultWidget (deprecated)
afterInstantSearchStartRemoveDefaultWidgets instead.widget.widgetType):
ais.sortByais.searchBoxais.statsais.hitsais.pagination
Parameters
Returns
beforeISearchInitSortOrdersArray (deprecated)
beforeInstantSearchInitSearchSortOrders instead.sort order before they’re rendered.
Parameters
Returns
beforeISStartAddWidgetArray (deprecated)
beforeInstantSearchStartAddWidgets instead.rangeSlidermenurefinementListsearchBoxstatssortByclearRefinementspanelhitspaginationconfigure
Returns
beforeISInitCollectionSortOrdersArray (deprecated)
beforeInstantSearchInitCollectionSortOrders instead.