npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jetshop/flight-nosto

v2.0.0

Published

Nosto Integration for Flight

Downloads

9

Readme

flight-nosto

This package helps you to implement Nosto in your Flight shop. It handles tracking/tagging of different page types, attribution (meaning that Nosto will know if you have clicked on their recommendations) as well as product recommendations.

Before you set it up, make sure that you have access to the Nosto dashboard.

Getting Started with Nosto

In order to integrate your flight shop with nosto you must first install it:

yarn add @jetshop/flight-nosto

Adding the Nosto Provider and cart tagging

Now that Nosto has been added into the shop, you must wrap your shop in the FlightNostoProvider. We also need the cart to be tagged here.

import { FlightNostoProvider, FlightNostoCart } from '@jetshop/flight-nosto';
import cartQuery from '../path/to/your/cartQuery.gql';
import { useCart } from '@jetshop/core/components/Query/CartProvider';

function Shop() {
  const { cart } = useCart(cartQuery);
  return (
    <FlightNostoProvider>
      <FlightNostoCart cart={cart} />
      {/* The rest of your shop components */}
    </FlightNostoProvider>
  );
}

The FlightNostoProvider component adds the Nosto script to your site, and keeps track of all the other Nosto components on the page. FlightNostoCart is used to notify Nosto about products that are put in the cart.

Now that the FlightNostoProvider has been added we can now add tagging to your different pages.

Adding Tagging

Product page

Tagging the product page is important since Nosto uses this to populate their product data, and also because the attribution is done inside this component. Currently since the variation context is being deprecated we recommend passing the selectedVariation and product to the FlightNostoProduct component as props. This will be required in the future.

To ensure proper tagging on the product page please add the FlightNostoProduct component to your ProductPage:

import { FlightNostoProduct } from '@jetshop/flight-nosto';
import { useProductVariants } from '@jetshop/core/hooks/useProductVariants';

function ProductPage({ product }) {
  const { selectedVariant } = useProductVariants(product);
  return (
    <Fragment>
      <FlightNostoProduct
        selectedVariation={selectedVariation}
        brand={'Levis'}
        product={product}
      />
      {/* Rest of the product page */}
    </Fragment>
  );
}

The attribution uses the query string prop called nosto to understand which recommendation block the user has clicked to get here.

Category page

To ensure proper tagging on the category page, add the FlightNostoCategory component to your CategoryPage;

import { FlightNostoCategory } from '@jetshop/flight-nosto';

class Category extends Component {
  render() {
    const { category, result } = this.props;
    return (
      <Fragment>
        <FlightNostoCategory
          category={category}
          route={result.data && result.data.route}
        />
        {/* Rest of the category page */}
      </Fragment>
    );
  }
}

Search page

To ensure proper tagging on the search page please add the NostoSearch component to your SearchResults:

import { NostoSearch } from '@jetshop/flight-nosto';

const SearchResults = ({ loading, ...props }) => {
  const { term } = props;
  return (
    <Fragment>
      <NostoSearch searchTerm={term} />
      {/* Rest of the search page */}
    </Fragment>
  );
};

Other pages

The other types of pages you should add tagging to is front (start page) and notfound (404 page). To do this, use the NostoPage component and pass the page type:

import { NostoPage } from '@jetshop/flight-nosto';

const StartPage = () => {
  return (
    <Fragment>
      <NostoPage pageType="front" />
      {/* Rest of the start page */}
    </Fragment>
  );
};

Product recommendations

There's a few things you have to do to set up the Nosto recommendations.

Set up template in the Nosto dashboard

First, you need to update the template in the Nosto dashboard. flight-nosto expects a specific JSON structure, so update the template to look like this:

{
    "title" : "$!title",
    "productIds":[
        #foreach($product in $products)
            #if($foreach.count>1),#end
            "$!product.productId.escapeJsonString()"
        #end
    ]
}

Fetch the product data

The template above will only provide the title and productIds for the recommendation, so we need to fetch the full product data ourselves.

First, we create a query that takes ids and fetches the data we want:

#import "@jetshop/core/data/fragments/RouteCrumbFragment.gql"
#import "@jetshop/core/data/fragments/ProductPriceFragment.gql"
#import "@jetshop/core/data/fragments/BadgeFragment.gql"

query NostoProductRecosQuery(
  $ids: [Int] = null
  $articleNumbers: [String] = null
) {
  products(articleNumbers: $articleNumbers, ids: $ids) {
    id
    articleNumber
    name
    subName
    shortDescription
    description
    mainHeader
    primaryRoute {
      ...RouteCrumb
    }
    ...ProductPrice
    images {
      alt
      title
      url
    }
    badges {
      ...Badge
    }
  }
}

Then we pass this query into the FlightNostoRecos component. If you would like to use articleNumbers instead of ids for your products please set the boolean prop articleNumbers to true:

import React from 'react';
import { FlightNostoRecos } from '@jetshop/flight-nosto';
import GridProduct from '@jetshop/ui/ProductList/GridProduct';
import nostoRecosProductQuery from './NostoRecosProductQuery.gql';

const Product = ({ result: { data, loading }, product }) => {
  const nostoId = 'my-nosto-recommendation-id';
  return (
    <div>
      {/* ... Your Product page */}
      <FlightNostoRecos
        query={nostoRecosProductQuery}
        id={nostoId}
        articleNumbers={false}
      >
        {({ products }) => {
          return products.map(product => (
            <GridProduct
              key={product.id}
              product={product}
              search={`?nosto=${nostoId}`}
            />
          ));
        }}
      </FlightNostoRecos>
    </div>
  );
};

export default Product;

Also note that we pass a query string to the GridProduct component. This is used in the FlightNostoProduct component to do the correct attribution of the Nosto recommendation element - meaning that Nosto will know what product recommendation the user clicked to get to the product page.

That's it!