UNPKG

@shopgate/pwa-tracking

Version:

Tracking library for the Shopgate Connect PWA.

32 lines (30 loc) 1.13 kB
import { getCurrentRoute } from '@shopgate/engage/core/selectors'; import { categoryIsReady$ } from "../streams/category"; import { searchIsReady$ } from "../streams/search"; import { productIsReady$ } from "../streams/product"; import { pagesAreReady$ } from "../streams/pages"; import { pageIsReady$ } from "../streams/page"; import { makeGetTrackingData } from "../selectors"; import { track } from "../helpers"; /** * Calls the pageview core tracking function. * @param {Object} input The input of the tracked stream. */ const callPageViewTracker = ({ getState }) => { const state = getState(); const getTrackingData = makeGetTrackingData(); track('pageview', getTrackingData(state, getCurrentRoute(state)), state); }; /** * Pages tracking subscriptions. * @param {Function} subscribe The subscribe function. */ export default function pages(subscribe) { subscribe(categoryIsReady$, callPageViewTracker); subscribe(searchIsReady$, callPageViewTracker); subscribe(productIsReady$, callPageViewTracker); subscribe(pagesAreReady$, callPageViewTracker); subscribe(pageIsReady$, callPageViewTracker); }