@shopgate/pwa-tracking
Version:
Tracking library for the Shopgate Connect PWA.
33 lines (31 loc) • 1.11 kB
JavaScript
import { createSelector } from 'reselect';
import { createPageviewData } from "../helpers";
import getPage, { makeGetRoutePageConfig } from "./page";
import getCart from "./cart";
import getSearch from "./search";
import getFavorites from "./favorites";
import { makeGetRouteCategory } from "./category";
import { makeGetRouteProduct } from "./product";
/**
* Creates a selector that retrieves tracking data for the current route.
* @returns {Function}
*/
export const makeGetTrackingData = () => {
const getRouteCategory = makeGetRouteCategory();
const getRouteProduct = makeGetRouteProduct();
const getRoutePageConfig = makeGetRoutePageConfig();
/**
* Selects the combined tracking information.
* @param {Object} state The current state.
* @returns {Object} The tracking data.
*/
return createSelector(getPage, getCart, getFavorites, getSearch, getRouteCategory, getRouteProduct, getRoutePageConfig, (page, cart, favorites, search, category, product, pageConfig) => createPageviewData({
page,
cart,
favorites,
search,
category,
product,
pageConfig
}));
};