Skip to main content
The Algolia PWA Kit demo shows how to add Autocomplete, InstantSearch, and Recommend to a Salesforce B2C Commerce PWA Kit storefront. Use the starter code to integrate these features into your own project.

View Algolia PWA Kit demo

Try the storefront demo with Autocomplete, InstantSearch, and Recommend.

Explore starter code

Browse the PWA Kit starter code and integration source on GitHub.

Integration with PWA Kit

The demo uses PWA Kit template extensibility with @salesforce/retail-react-app as its base template. It includes only files that differ from the base template. Copy the changes you need into your project or use the demo repository as starter code. For more information, see Template extensibility.

Before you begin

This guide requires:

Installation

This guide covers @salesforce/retail-react-app version 4.0.0. For other versions, check the PWA Kit release notes for configuration differences.

Run the Algolia demo application

  1. Set up API access to your Salesforce B2C Commerce instance.
  2. In Salesforce Business Manager, go to Merchant Tools > Algolia > Algolia. In Additional Product Attributes, enter color, size, colorVariations, masterID, lsImage, short_description, long_description, pricebooks, brand, name, and in_stock. These attributes determine which additional product fields the cartridge sends to Algolia. For more information, see Custom preferences. If you’re using other datasets or a custom indexing approach, adjust the attribute list for your implementation.
  3. Index your products and content from your Salesforce B2C Commerce instance into Algolia.
  4. Configure your indices in the Algolia dashboard:
  5. Import the following rule configuration using Enhanced > Rules > Import/Export.
    JSON
  6. Clone the Algolia PWA Kit demo repository from GitHub and go to the cloned repository:
    Command line
    Command line
  7. Install the dependencies:
    Command line
  8. Copy the example file to config/algolia-config.json. Update the Algolia credentials and index names.
  9. Copy the example file to config/commerce-api-config.json. Update the Salesforce B2C Commerce API credentials.
  10. Set the PWA_KIT_SLAS_CLIENT_SECRET in your environment variables. To learn more about creating Shopper Login and API Access Service (SLAS) credentials, see Build Your Site in the PWA Kit documentation.
  11. Start the development server:
    Command line
The demo runs at localhost:3000 using the credentials and index names in config/algolia-config.json.

Integrate Algolia into your existing PWA Kit project

  1. Index your products using the Algolia indexing jobs in Salesforce B2C Commerce.
  2. Create an algolia-config.json file in your root folder or use and rename the example file.
  3. Adjust your Commerce API and PWA Kit configuration as needed. For more information, see Configuration files.
  4. Install the necessary dependencies to use Algolia styles in your PWA application:
    Command line
    Copy the babel.config.js and postcss.config.js files from the demo repository to your project’s root directory.
  5. Copy the overrides/app/components/algolia directory from the demo repository to your project.
  6. Update your overrides/app/routes.jsx file to include the Algolia product list and detail pages:
    JavaScript
    If you don’t need recommendation widgets on product detail pages, omit the ProductDetail route override.

algolia-config.json file

The following JavaScript excerpt shows the Algolia configuration structure. For the complete JSON file, see algolia-config.example.json.
JavaScript
  • appId: your Algolia application ID, which you can find in the Algolia dashboard
  • apiKey: your Algolia API key, which you can find in the Algolia dashboard
  • indices.querySuggestions: the Query Suggestions index name
  • indices.primary.label: the label for the default sorting option
  • indices.primary.value: the primary product index name
  • indices.replicas: a sorting options array and their corresponding index names
  • indices.contents: the content index name
  • indices.faq: the index containing FAQ records. The demo uses the content index. To search a separate FAQ index, update this value.
  • indices.categories: the categories index name

InstantSearch implementation

The Algolia PWA Kit demo uses the algolia-product-list page for the /search and /category/:categoryId routes. It uses the following npm packages for building the InstantSearch experience: InstantSearch in the demo provides the following features:
  • Search results
  • Category listings
  • Filters for category, color, size, price, and brand
  • Pagination
  • Sorting by relevance or price
  • Content search in a separate tab
  • Color swatches on product listings
To customize filtering, change the hardcoded hierarchicalCategoryAttributes and filterEls variables in the index.jsx file. For example, to filter by collection instead of brand, set the AlgoliaCheckboxRefinements component’s attribute prop to "collection":
JavaScript
To add a filter for material, add an AlgoliaCheckboxRefinements component to filterEls with attribute="material":
JavaScript

Autocomplete implementation

The demo replaces the default search box with the Autocomplete widget. The Autocomplete component is in the overrides/app/components/algolia/autocomplete directory. The implementation in index.jsx and uses the following plugins.

recentSearchesPlugin

Displays users’ recent searches with the createLocalStorageRecentSearchesPlugin. The plugin stores recent searches in the browser’s local storage under the pwa-recent-searches key.

querySuggestionsPlugin

Provides Query Suggestions based on the user’s input. It uses the createQuerySuggestionsPlugin and fetches suggestions from the indices.querySuggestions index in the configuration.

categoriesPlugin

Fetches and displays category suggestions. It uses the getAlgoliaResults function to retrieve category results from the indices.categories index in the configuration.

brandsPlugin

Displays popular brands based on Algolia’s Trending Facets feature. It uses the getAlgoliaFacets function to fetch trending brands from the indices.primary.value index in the configuration.

faqPlugin

Provides FAQ suggestions based on the user’s input. It fetches results from the index specified by indices.faq using the getAlgoliaResults function.

popularPlugin

Displays popular searches based on Algolia’s Query Suggestions feature. It uses the createQuerySuggestionsPlugin to retrieve popular searches from the indices.querySuggestions index in the configuration.

popularCategoriesPlugin

Fetches and displays popular categories based on Algolia’s facet values. It uses the getAlgoliaFacets function to retrieve popular categories from the indices.primary.value index in the configuration.

productPlugin

Fetches and displays product suggestions based on the user’s input. It uses the getAlgoliaResults function to retrieve product results from the indices.primary.value index in the configuration.

Customization and extensibility

The popularCategoriesPlugin helps display popular product categories based on search results. Replace the hardcoded category images in popularCategoriesPlugin.tsx. The quickAccessPlugin displays content configured through Algolia Rules. Customize the configuration in quickAccessPlugin.tsx. For demonstration purposes, the index.jsx file includes sample data. Customize the Algolia component styles in style.css.

Recommend implementation

The demo includes Algolia Recommend components for product recommendations. These components are in overrides/app/components/algolia/recommend. The available Recommend components are:
  • Frequently bought together: displays products frequently bought with the current product
  • Looking similar: shows products that look like the current product
  • Related products: displays products with similar attributes as the current product
  • Trending items: displays trending items, based on a specific facet name and facet values
  • Trending facets: shows trending facet values for a facet name
Each Recommend component uses the @algolia/recommend-react package to retrieve recommendations from Algolia. The following are examples of the Recommend components. Import them from the overrides/app/components/algolia/recommend directory for use anywhere in your project.
  • Frequently bought together:
    JavaScript
  • Looking similar:
    JavaScript
  • RelatedProducts:
    JavaScript
  • TrendingItems:
    JavaScript
  • TrendingFacets:
    JavaScript
For examples of how to use these components, see the index.jsx file. In the preceding examples:
  • product represents the current product object for displaying recommendations. It matches the context-object in Einstein Recommendation isslots.
  • facetName and facetValue specify the facet name and value for fetching trending items.
The Recommend components also include extra props for customization, such as:
  • recommendClient to specify the Algolia Recommend client
  • indexName to specify the index to fetch recommendations from
  • headerComponent and itemComponent for rendering custom headers and items.
To use the Recommend components in your PWA Kit project:
  1. Import the desired Recommend component from the overrides/app/components/algolia/recommend directory.
  2. Configure the necessary props, such as the current product, click event handlers, and any extra customization options.
  3. Place the Recommend component in the appropriate location within your product detail page or any other relevant page.

Next steps

Customize the starter code for your storefront:

Common issues

Last modified on October 12, 2026