Track Page Views

  • For best analytics, this hook requires the following data to be passed in. This should be determined in whatever way necessary for your store:

    • Cart or Checkout Token

    • Country

    • Currency

  • This hook runs client-side with an internal useEffect().

import React from "react";

import {
  IntelligemsGatsbyProvider,
  useIgTrack,
} from "@intelligems/headless/gatsby";

const IntelligemsTracker = ({ children }) => {
  const { checkout } = React.useContext(StoreContext);

  useIgTrack({
    cartOrCheckoutToken: checkout?.id,
    currency: checkout?.totalTaxV2?.currencyCode,
    country: "US",
  });

  return children;
};

export const wrapRootElement = ({ element }) => (
  <IntelligemsGatsbyProvider
    organizationId={process.env.GATSBY_INTELLIGEMS_ORG_ID}
    storefrontApiToken={process.env.GATSBY_STOREFRONT_ACCESS_TOKEN}
    antiFlicker={true}
  >
    <StoreProvider>
      <IntelligemsTracker>{element}</IntelligemsTracker>
    </StoreProvider>
  </IntelligemsGatsbyProvider>
);

Last updated