@shopgate/pwa-tracking
Version:
Tracking library for the Shopgate Connect PWA.
13 lines • 2.63 kB
JavaScript
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import{appWillStart$,pwaDidAppear$,pwaDidDisappear$,routeDidEnter$}from'@shopgate/engage/core/streams';import{APP_WILL_START,PWA_DID_APPEAR}from'@shopgate/engage/core/constants';import{SEARCH_PATH,SEARCH_FILTER_PATTERN}from'@shopgate/engage/search/constants';import{ROOT_CATEGORY_PATTERN,CATEGORY_PATTERN,CATEGORY_FILTER_PATTERN}from'@shopgate/engage/category/constants';import{ITEM_PATTERN,ITEM_GALLERY_PATTERN,ITEM_REVIEWS_PATTERN,ITEM_WRITE_REVIEW_PATTERN}from'@shopgate/engage/product/constants';import{PAGE_PATTERN}from'@shopgate/engage/page/constants';import{pwaVisibility$}from"./app";import{checkoutDidEnter$}from"./checkout";/**
* A blacklist of paths that should be tracked within their individual subscriptions.
* @type {Array}
*/export var blacklistedPatterns=[ROOT_CATEGORY_PATTERN,CATEGORY_PATTERN,ITEM_PATTERN,SEARCH_PATH,// Patterns for routes which are not supported for tracking at the moment.
CATEGORY_FILTER_PATTERN,SEARCH_FILTER_PATTERN,ITEM_GALLERY_PATTERN,ITEM_REVIEWS_PATTERN,ITEM_WRITE_REVIEW_PATTERN,PAGE_PATTERN];var latestAppActions$=appWillStart$.merge(pwaVisibility$,checkoutDidEnter$);/**
* Route did enter and PWA is visible and route is not blacklisted
* @type {Rx.Observable<*[]>}
*/var routeDidEnterForVisiblePwa$=routeDidEnter$.withLatestFrom(latestAppActions$).filter(function(_ref){var _ref2=_slicedToArray(_ref,2),type=_ref2[1].action.type;return type===APP_WILL_START||type===PWA_DID_APPEAR;}).map(function(_ref3){var _ref4=_slicedToArray(_ref3,1),routeDidEnter=_ref4[0];return routeDidEnter;});/**
* PWA reappear after disappear
* @type {Rx.Observable<any>}
*/var pwaDidAppearAfterDisappear=pwaDidDisappear$.switchMap(function(){return pwaDidAppear$.first();});/**
* Emits when one of the tracked paths is entered or pwa reappear
*/export var pagesAreReady$=routeDidEnterForVisiblePwa$.merge(pwaDidAppearAfterDisappear).filter(function(_ref5){var action=_ref5.action;return!blacklistedPatterns.find(function(pattern){return action.route.pattern===pattern;});});