@nosto/nosto-react

Nosto React

Nosto React is a React component library to make it even easier to implement Nosto.

The library provides you everything to get started with personalisation on your React site. It's dead simple, and beginner friendly.

You should be using Nosto React if you want to:

  • Design personalisation experiences with best practices
  • Customize your components at will and with ease
  • Follow React principles

Our React component library includes the following features:

  • Recommendations, including client-side rendering
  • Onsite content personalisation
  • Dynamic bundles
  • Debug toolbar* (excluding advanced use cases)
  • Pop-ups & personalised emails
  • A/B testing
  • Segmentation and Insights
  • Analytics
  • Search** (when implemented via our code editor)

*Note: Our React component library currently does not support advanced use cases of the debug toolbar, but we are constantly working to improve our library and provide you with the best possible integration options. We support most use-cases with page tagging and debug workflows.

**Note: The search feature is available when implemented via our code editor.

  • ✓ Lightweight. Almost zero bloat.
  • ✓ Full support for the Facebook Pixel and Google Analytics.
  • ✓ Full support for leveraging overlays.
  • ✓ Full support for the JS API.
  • ✓ Full support for placements.
  • npm: 9.8.1
  • node: v18.18.0
yarn add @nosto/nosto-react
npm install @nosto/nosto-react

There’s one very specific widget in Nosto React and it is the NostoProvider one.

This widget is what we call the Nosto root widget, which is responsible for adding the actual Nosto script and the JS API stub. This widget wraps all other React Nosto widgets. Here’s how:

import { NostoProvider } from "@nosto/nosto-react";

}
>
  
;

Note: the component also accepts a prop to configure the host host="connect.nosto.com". In advanced use-cases, the need to configure the host may surface.

In order to implement client-side rendering, the requires a designated component to render the recommendations provided by Nosto. This component should be capable of processing the JSON response received from our backend. Notice the recommendationComponent={<NostoSlot />} prop passed to <NostoProvider> above.

Learn more here and see a live example on our demo store.

Nosto React has a special component called NostoPlacement. The component is a simply a hidden <div> placeholder into which Nosto injects recommendations or personalises the content between the tags.

We recommend adding as many placements across your views as needed as these are hidden and only populated when a corresponding campaign (targeting that placement) is configured.

Nosto React requires that you pass it the details of current cart contents and the details of the currently logged-in customer, if any, on every route change. This makes it easier to add attribution.

The NostoSession component makes it very easy to keep the session up to date so long as the cart and the customer are provided.

The cart prop requires a value that adheres to the type Cart, while the customer prop requires a value that adheres to the type Customer.

import { NostoSession } from "@nosto/nosto-react";

<>
  
  
;

Nosto React ships with canned components for the different page types. Each component contains all lifecycle methods to dispatch the necessary events.

The NostoHome component must be used to personalise the home page. The component does not require any props.

By default, your account, when created, has four front-page placements named frontpage-nosto-1, frontpage-nosto-2, frontpage-nosto-3 and frontpage-nosto-4. You may omit these and use any identifier you need. The identifiers used here are simply provided to illustrate the example.

The <NostoHome \> component needs to be added after the placements. Content and recommendations will be rendered through this component.

import { NostoHome, NostoPlacement } from "@nosto/nosto-react";

... ... ...
;

The NostoProduct component must be used to personalise the product page. The component requires that you provide it the identifier of the current product being viewed.

By default, your account, when created, has three product-page placements named productpage-nosto-1, productpage-nosto-2 and productpage-nosto-3. You may omit these and use any identifier you need. The identifiers used here are simply provided to illustrate the example.

The <NostoProduct \> component needs to be added after the placements. Content and recommendations will be rendered through this component. Pass in the product ID via the product prop to pass this information back to Nosto.

import { NostoPlacement, NostoProduct } from "@nosto/nosto-react";

... ... ...
;

You can personalise your search pages by using the NostoSearch component. The component requires that you provide it the current search term.

By default, your account, when created, has two search-page placements named searchpage-nosto-1 and searchpage-nosto-2. You may omit these and use any identifier you need. The identifiers used here are simply provided to illustrate the example.

import { NostoPlacement, NostoSearch } from "@nosto/nosto-react";

... ... ...
;

Note: Do not encode the search term in any way. It should be provided an unencoded string. A query for "black shoes" must be provided as-is and not as "black+shoes". Doing so will lead to invalid results.

You can personalise your category and collection pages by using the NostoCategory component. The component requires that you provide it the the slash-delimited slug representation of the current category.

By default, your account, when created, has two category placements named categorypage-nosto-1 and categorypage-nosto-2. You may omit these and use any identifier you need. The identifiers used here are simply provided to illustrate the example.

import { NostoCategory, NostoPlacement } from "@nosto/nosto-react";

... ... ...
;

Note: Be sure to pass in the correct category representation. If the category being viewed is Mens >> Jackets, you must provide the name as /Mens/Jackets . You must ensure that the category path provided here matches that of the categories tagged in your products.

You can personalise your cart and checkout pages by using the NostoCheckout component. The component does not require any props.

By default, your account, when created, has two cart-page placements named categorypage-nosto-1 and categorypage-nosto-2. You may omit these and use any identifier you need. The identifiers used here are simply provided to illustrate the example.

import { NostoCheckout, NostoPlacement } from "@nosto/nosto-react";

... ... ...
;

You can personalise not found pages by using the Nosto404 component. The component does not require any props.

By default, your account, when created, has three 404-page placements named notfound-nosto-1, notfound-nosto-2 and notfound-nosto-2. You may omit these and use any identifier you need. The identifiers used here are simply provided to illustrate the example.

import { Nosto404, NostoPlacement } from "@nosto/nosto-react";

... ... ...
;

You can personalise your miscellaneous pages by using the NostoOther component. The component does not require any props.

By default, your account, when created, has two other-page placements named other-nosto-1 and other-nosto-2. You may omit these and use any identifier you need. The identifiers used here are simply provided to illustrate the example.

import { NostoOther, NostoPlacement } from "@nosto/nosto-react";

... ... ...
;

You can personalise your order-confirmation/thank-you page by using the NostoOrder component. The component requires that you provide it with the details of the order.

By default, your account, when created, has one other-page placement named thankyou-nosto-1. You may omit this and use any identifier you need. The identifier used here is simply provided to illustrate the example.

import {
  NostoOrder,
  NostoPlacement,
} from "@nosto/nosto-react";

... ... ...
;

For all the page type specific components hooks are also provided with the same props

  • useNosto404
  • useNostoOther
  • useNostoCheckout
  • useNostoProduct
  • useNostoCategory
  • useNostoSearch
  • useNostOrder
  • useNostoHome

Find our latest technical specs and documentation hosted here.

If you've found a feature missing or you would like to report an issue, simply open up an issue and let us know.

We're always collecting feedback and learning from your use-cases. If you find your self customising widgets and forking the repo to make patches - do drop a message. We'd love to know more and understand how we can make React Nosto an even slicker library for you.

Please take a moment to review the guidelines for contributing.

MIT