@shopgate/pwa-tracking
Version:
Tracking library for the Shopgate Connect PWA.
11 lines • 1.43 kB
JavaScript
import'rxjs/add/operator/switchMap';import{main$,routeWillEnter$,pwaDidAppear$}from'@shopgate/engage/core/streams';import{getIsAppWebViewVisible}from'@shopgate/engage/core/selectors';import{receivedVisibleProduct$}from'@shopgate/pwa-common-commerce/product/streams';import{RECEIVE_PRODUCTS,ITEM_PATTERN}from'@shopgate/pwa-common-commerce/product/constants';/**
* Emits when product results has been received.
*/export var productsReceived$=main$.filter(function(_ref){var action=_ref.action;return action.type===RECEIVE_PRODUCTS;});/**
* Emits when the category route comes active again after a legacy page was active.
*/export var productRouteReappeared$=pwaDidAppear$.filter(function(_ref2){var action=_ref2.action;return action.route.pattern===ITEM_PATTERN;});/**
* Emits when a product page was initially opened.
*/export var productWillEnter$=routeWillEnter$.filter(function(_ref3){var action=_ref3.action;return action.route.pattern===ITEM_PATTERN;});/**
* Emits when a product page was initially opened and its data is present.
*/export var productIsReady$=productWillEnter$// Do not track while PWA webview is in the background
.filter(function(_ref4){var getState=_ref4.getState;return getIsAppWebViewVisible(getState());})// Take care that the stream only emits when underlying streams emit within the correct order.
.switchMap(function(){return receivedVisibleProduct$.first();}).merge(productRouteReappeared$);