Skip to main content

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 a Promise to delay InstantSearch until your work completes.

Examples

Return a Promise to pause InstantSearch while you run async work.
JavaScript

beforeInstantSearchConfigurationOptions

Changes InstantSearch options.

Parameters

object
InstantSearch configuration options.

Returns

object
Modified configuration options.

Examples

Update InstantSearch options before it initializes.
JavaScript

beforeInstantSearchOptions

Changes the following parameters:

Parameters

object
InstantSearch options with the following properties:
  • colors
  • distinct
  • facets
  • hitsPerPage
  • selector
  • sortOrders

Returns

object
Modified InstantSearch options.

beforeInstantSearchAllowParamsArray

Preserves URL parameters when navigating through the search results.

Parameters

string[]
URL parameter names to preserve.

Returns

string[]
Modified parameter names.

Examples

Add ref to the allowlist so InstantSearch preserves it in the URL.
JavaScript

beforeInstantSearchFiltersString

Changes the filter parameter of the search results page.

Parameters

string
Default (may be empty).

Returns

string
Filters to apply.

Examples

Append a price filter to the existing filter string, if present.
JavaScript

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

string[]
Default rule contexts. On collection pages, this includes the collection handle and shopify_default_collection. On other pages, this is an empty array.

Returns

string[]
Modified rule contexts. Duplicates are removed and the list is limited to 10 items.

Examples

This example adds a rule context based on the utm_source URL parameter.
JavaScript

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

Default template.
object
Contains facets and configuration.
Tagged template function for rendering HTML.

Returns

Template to render.

Examples

Return a custom page layout that includes facet, stats, and results containers.
JavaScript

beforeInstantSearchProductTemplate

Template for product hits in the search results. When using this template, also call trackSearchAttribution(hit) to properly handle events.

Parameters

Default template.
object
Product hit.
Tagged template function for rendering HTML.
object
InstantSearch components (like Highlight).
Function to track search attribution. Equivalent to algoliaShopify.helpers.handleItemClick.

Returns

Template to render.

Examples

Return a custom product-hit template and call trackSearchAttribution(hit) to track events.
JavaScript

beforeInstantSearchNoResultTemplate

Template for when there are no results.

Parameters

Default template.
Tagged template function for rendering HTML.

Returns

Template to render.

Examples

Replace the default empty state with a custom template.
JavaScript

beforeInstantSearchStatsTemplate

Template for search stats
If the active sort order uses a virtual replica, the response includes 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

Default template.
object
Contains search statistics, for example nbHits, nbSortedHits, page, and hitsPerPage.
Tagged template function for rendering HTML.

Returns

Template to render.

Examples

Customize the stats template for one or many results.
JavaScript

beforeInstantSearchTransformItems

Change items before they’re rendered.

Parameters

array
Search result items.
array
Original items.

Returns

array
Modified items.

Examples

Set can_order to false for items with inventory_quantity equal to 0.
JavaScript

beforeInstantSearchStartAddWidgets

Add InstantSearch widgets to the search results page. You can add the following widgets:

Returns

array
InstantSearch widgets.

Examples

Add a searchBox widget before InstantSearch adds default widgets.
JavaScript

afterInstantSearchStartRemoveDefaultWidgets

Remove default widgets from the search results page. You can remove these widgets (widget.$$widgetType):
  • ais.sortBy
  • ais.searchBox
  • ais.stats
  • ais.hits
  • ais.pagination

Parameters

array
Default InstantSearch widgets.

Returns

array
Widgets to remove.

Examples

Remove the default pagination widget.
JavaScript

beforeInstantSearchFacetSearchablePlaceholder

Changes the searchablePlaceholder for facet search.

Parameters

string
Default placeholder text.

Returns

string
Modified placeholder text.

Examples

Override the facet search placeholder text.
JavaScript

beforeInstantSearchFacetParamsOptions

Update widget parameters before they’re rendered.

Parameters

object
Widget parameters. Parameters depend on the widget type. Use facet.type to determine the widget.
object
Facet metadata (read-only):

Returns

object
Modified widget parameters.

Examples

Adjust facet widget parameters based on facet.title or facet.type.
JavaScript

beforeInstantSearchFacetPanelOptions

Update the panel parameters before they’re rendered.

Parameters

object
Panel parameters. For more information, see panel.
object
Facet metadata (read-only):
  • title
  • name

Returns

object
Modified panel parameters.

Examples

Customize panel templates like header, footer, and searchableNoResults.
JavaScript

beforeInstantSearchInitSearchSortOrders

Transform sort order before they’re rendered.

Parameters

object[]
Sort orders, spread as individual arguments. The last argument is reserved for internal use: use rest syntax and slice(0, -1) to collect the sort order objects. Each has:
  • label (string): display name for the sort order
  • value (string): name for the sort order

Returns

array
Modified sort orders.

Examples

Add a custom sort option to the sort-by widget.
JavaScript

beforeInstantSearchInitCollectionSortOrders

Transform the sort order for collections.

Parameters

object[]
Sort orders, spread as individual arguments. The last argument is reserved for internal use: use rest syntax and slice(0, -1) to collect the sort order objects. Each has:
  • label (string): display name for the sort order
  • value (string): name for the sort order

Returns

array
Modified sort orders.

Examples

Add a custom sort option for collections.
JavaScript

afterInstantSearchHitClickAction (deprecated)

This hook is deprecated. Use beforeInstantSearchProductTemplate instead.
Runs after a user clicks a search result. Return a function to override the default click behavior.

Parameters

any
First parameter (unused).
object
Product search result (hit) that was clicked.

Returns

Function to run on click.

beforeInstantSearchFacetItemTemplate (deprecated)

This hook is deprecated. Use beforeInstantSearchFacetParamsOptions instead. The refinementList widget can be added as a parameter in the template object.
Template for rendering facet items.

Parameters

Default template.
object
Facet.
Tagged template function for rendering HTML.

beforeInstantSearchShowMoreTemplate (deprecated)

This hook is deprecated. Use beforeInstantSearchFacetParamsOptions instead. The refinementList widget can be added as a parameter within the template object.
Template for the showMoreText button.

Parameters

Default template.
object
Contains the isShowingMore property.
Tagged template function for rendering HTML.

beforeInstantSearchFacetLimitNumber (deprecated)

This hook is deprecated. Use beforeInstantSearchFacetParamsOptions instead. The refinementList widget can be added as a parameter.
Changes the limit (default: 10).

Parameters

number
default:"10"
Default limit.

Returns

number
New limit.

beforeISFacetSearchablePlaceholderString (deprecated)

This hook is deprecated. Use beforeInstantSearchFacetSearchablePlaceholder or beforeInstantSearchFacetParamsOptions instead. The searchablePlaceholder option can be added as a parameter in the template object.
Changes the searchablePlaceholder.

Parameters

string
Default placeholder text.

Returns

string
Modified placeholder text.

beforeISFacetSearchableNoResultsString (deprecated)

This hook is deprecated. Use beforeInstantSearchFacetParamsOptions instead. The searchableNoResults option can be added as a parameter in the template object.
Changes the searchableNoResults.

Parameters

string
Default “no results” text.

Returns

string
Modified “no results” text (string or template literal).

beforeInstantSearchFacetHeaderString (deprecated)

This hook is deprecated. Use 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.
Changes the facet header string.

Parameters

string
Default facet header.

Returns

string
Modified facet header.

beforeInstantSearchFacetTransformItemsOptions (deprecated)

This hook is deprecated. Use beforeInstantSearchFacetParamsOptions instead. Use transformItems as a parameter to transform the data.
Transforms items before they’re rendered.

Parameters

object
Transform items options.

Returns

object
Modified options.

beforeISTransformItems (deprecated)

This hook is deprecated. Use beforeInstantSearchTransformItems instead.
Change items before they’re rendered.

Parameters

array
Transformed items.
array
Original items.

Returns

array
Modified items.

afterISStartRemoveDefaultWidget (deprecated)

This hook is deprecated. Use afterInstantSearchStartRemoveDefaultWidgets instead.
Remove default widgets from the search results page. You can remove these widgets (widget.widgetType):
  • ais.sortBy
  • ais.searchBox
  • ais.stats
  • ais.hits
  • ais.pagination

Parameters

array
Default InstantSearch widgets.

Returns

array
Widgets to remove.

beforeISearchInitSortOrdersArray (deprecated)

This hook is deprecated. Use beforeInstantSearchInitSearchSortOrders instead.
Transform sort order before they’re rendered.

Parameters

array
Sort orders.

Returns

array
Modified sort orders.

beforeISStartAddWidgetArray (deprecated)

This hook is deprecated. Use beforeInstantSearchStartAddWidgets instead.
Add InstantSearch widgets to the search results page. You can add the following widgets:
  • rangeSlider
  • menu
  • refinementList
  • searchBox
  • stats
  • sortBy
  • clearRefinements
  • panel
  • hits
  • pagination
  • configure

Returns

array
InstantSearch widgets.

beforeISInitCollectionSortOrdersArray (deprecated)

This hook is deprecated. Use beforeInstantSearchInitCollectionSortOrders instead.
Transform the sort order for collections.

Parameters

array
Sort orders.

Returns

array
Modified sort orders.

See also

Last modified on June 19, 2026