UNPKG

@shopgate/pwa-tracking

Version:

Tracking library for the Shopgate Connect PWA.

8 lines 1.14 kB
import{getCurrentRoute}from'@shopgate/engage/core/selectors';import{variantDidChange$}from'@shopgate/pwa-common-commerce/product/streams';import{productIsReady$}from"../streams/product";import{getBaseProductFormatted,getProductFormatted}from"../selectors/product";import{makeGetTrackingData}from"../selectors";import{track}from"../helpers";/** * Product tracking subscriptions. * @param {Function} subscribe The subscribe function. */export default function product(subscribe){/** * Gets triggered on product variant change/selection. */subscribe(variantDidChange$,function(_ref){var getState=_ref.getState,action=_ref.action;var state=getState();var productId=action.productData.id;var props={productId:productId};var trackingData={variant:getProductFormatted(state,props),baseProduct:getBaseProductFormatted(state,props)};track('variantSelected',trackingData,state);});/** * Gets triggered on product pageview. */subscribe(productIsReady$,function(_ref2){var getState=_ref2.getState;var state=getState();var getTrackingData=makeGetTrackingData();track('viewContent',getTrackingData(state,getCurrentRoute(state)),state);});}