@shopgate/pwa-tracking 6.22.0 → 6.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/pwa-tracking",
3
- "version": "6.22.0",
3
+ "version": "6.22.1",
4
4
  "description": "Tracking library for the Shopgate Connect PWA.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Shopgate <support@shopgate.com>",
@@ -15,10 +15,10 @@
15
15
  "connect"
16
16
  ],
17
17
  "devDependencies": {
18
- "@shopgate/pwa-common": "6.22.0",
19
- "@shopgate/pwa-common-commerce": "6.22.0",
20
- "@shopgate/pwa-core": "6.22.0",
21
- "@shopgate/tracking-core": "6.22.0",
18
+ "@shopgate/pwa-common": "6.22.1",
19
+ "@shopgate/pwa-common-commerce": "6.22.1",
20
+ "@shopgate/pwa-core": "6.22.1",
21
+ "@shopgate/tracking-core": "6.22.1",
22
22
  "reselect": "^3.0.1",
23
23
  "rxjs": "~5.5.12"
24
24
  }
@@ -0,0 +1,13 @@
1
+ import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import'rxjs/add/operator/switchMap';import'rxjs/add/observable/of';import'rxjs/add/observable/defer';import{Observable}from'rxjs/Observable';import{productsAdded$ as originalProductsAdded$}from'@shopgate/engage/cart';import{getProductById,fetchProductsById}from'@shopgate/engage/product';/**
2
+ * Emits when a product was added to the cart and product data is available
3
+ */export var productsAdded$=originalProductsAdded$.switchMap(function(input){var getState=input.getState,action=input.action,dispatch=input.dispatch;var _action$products=action.products,products=_action$products===void 0?[]:_action$products;// Collect product ids from the add-to-cart action
4
+ var productIds=products.map(function(_ref){var productId=_ref.productId;return productId;}).filter(Boolean);// Check if we have product data for all productIds
5
+ var productDataAvailable=productIds.every(function(productId){return getProductById(getState(),{productId:productId});});if(productDataAvailable){// All product data for the tracking event is available - handover action data to subscribers
6
+ return Observable.of(input);}/**
7
+ * Incomplete product data can be caused by an add-to-cart push message. In that case the
8
+ * product was never fetched before due to visiting PDP. So we need to fetch missing product
9
+ * data first.
10
+ * Subscribers will receive the original action when product data comes available.
11
+ */return Observable.defer(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var result;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:result={products:[]};_context.prev=1;_context.next=4;return dispatch(fetchProductsById(productIds));case 4:result=_context.sent;_context.next=9;break;case 7:_context.prev=7;_context.t0=_context["catch"](1);case 9:return _context.abrupt("return",result);case 10:case"end":return _context.stop();}}},_callee,null,[[1,7]]);}))).first()// do not proceed when request didn't return any products (no suitable tracking data)
12
+ .filter(function(data){return Array.isArray(data.products)&&data.products.length>0;})// handover original action to subscribers
13
+ .switchMap(function(){return Observable.of(input);});});
@@ -1,4 +1,4 @@
1
- import'rxjs/add/operator/switchMap';import'rxjs/add/observable/of';import{Observable}from'rxjs/Observable';import{hex2bin}from'@shopgate/pwa-common/helpers/data';import{routeDidEnter$}from'@shopgate/pwa-common/streams/router';import{pwaDidAppear$}from'@shopgate/pwa-common/streams/app';import{ROOT_CATEGORY_PATTERN,CATEGORY_PATTERN}from'@shopgate/pwa-common-commerce/category/constants';import{getProductsResult}from'@shopgate/pwa-common-commerce/product/selectors/product';import{receivedRootCategories$}from'@shopgate/pwa-common-commerce/category/streams';import{getRootCategories}from'@shopgate/pwa-common-commerce/category/selectors';import{productsReceived$}from"./product";/**
1
+ import'rxjs/add/operator/switchMap';import'rxjs/add/observable/of';import{Observable}from'rxjs/Observable';import{hex2bin}from'@shopgate/pwa-common/helpers/data';import{routeDidEnter$}from'@shopgate/pwa-common/streams/router';import{pwaDidAppear$}from'@shopgate/pwa-common/streams/app';import{ROOT_CATEGORY_PATTERN,CATEGORY_PATTERN}from'@shopgate/pwa-common-commerce/category/constants';import{getProductsResult}from'@shopgate/pwa-common-commerce/product/selectors/product';import{receivedRootCategories$}from'@shopgate/pwa-common-commerce/category/streams';import{getRootCategories}from'@shopgate/pwa-common-commerce/category/selectors';import{getIsAppWebViewVisible}from'@shopgate/engage/core';import{productsReceived$}from"./product";/**
2
2
  * Emits when the root category was entered.
3
3
  */var rootCategoryDidEnter$=routeDidEnter$.filter(function(_ref){var action=_ref.action;return action.route.pattern===ROOT_CATEGORY_PATTERN;});/**
4
4
  * Emits when a regular category was entered.
@@ -8,11 +8,12 @@ import'rxjs/add/operator/switchMap';import'rxjs/add/observable/of';import{Observ
8
8
  * Emits when a root category's data is already available.
9
9
  */var rootCategoryPreloaded$=rootCategoryDidEnter$.filter(function(_ref3){var getState=_ref3.getState;var rootCategories=getRootCategories(getState());return rootCategories?!!rootCategories.length:false;});/**
10
10
  * Emits when a category's data is available.
11
- */var categoryDataLoaded$=categoryDidEnter$.switchMap(function(data){var action=data.action,getState=data.getState;var categoryId=action.route.params.categoryId;// Check if products for the current route are already available within Redux.
11
+ */var categoryDataLoaded$=categoryDidEnter$// Do not track while PWA webview is in the background
12
+ .filter(function(_ref4){var getState=_ref4.getState;return getIsAppWebViewVisible(getState());}).switchMap(function(data){var action=data.action,getState=data.getState;var categoryId=action.route.params.categoryId;// Check if products for the current route are already available within Redux.
12
13
  var productsLoaded=getProductsResult(getState(),{categoryId:hex2bin(categoryId)}).totalProductCount!==null;if(!productsLoaded){// Wait for incoming products if they are not available yet.
13
14
  return productsReceived$.first();}return Observable.of(data);});/**
14
15
  * Emits when the category route comes active again after a legacy page was active.
15
- */var categoryRouteReappeared$=pwaDidAppear$.filter(function(_ref4){var action=_ref4.action;return[CATEGORY_PATTERN,ROOT_CATEGORY_PATTERN].includes(action.route.pattern);});/**
16
+ */var categoryRouteReappeared$=pwaDidAppear$.filter(function(_ref5){var action=_ref5.action;return[CATEGORY_PATTERN,ROOT_CATEGORY_PATTERN].includes(action.route.pattern);});/**
16
17
  * Emits when a category or root category is ready to be tracked,
17
18
  * considering loaded or preloaded data.
18
19
  */export var categoryIsReady$=categoryDataLoaded$.merge(rootCategoryLoaded$,rootCategoryPreloaded$,categoryRouteReappeared$);
package/streams/page.js CHANGED
@@ -1,9 +1,10 @@
1
- import'rxjs/add/operator/switchMap';import'rxjs/add/observable/of';import{Observable}from'rxjs/Observable';import{RECEIVE_PAGE_CONFIG}from'@shopgate/pwa-common/constants/ActionTypes';import{main$,routeDidEnter$,pwaDidAppear$}from'@shopgate/engage/core';import{PAGE_PATTERN,getPageConfigById}from'@shopgate/engage/page';/**
1
+ import'rxjs/add/operator/switchMap';import'rxjs/add/observable/of';import{Observable}from'rxjs/Observable';import{RECEIVE_PAGE_CONFIG}from'@shopgate/pwa-common/constants/ActionTypes';import{main$,routeDidEnter$,pwaDidAppear$,getIsAppWebViewVisible}from'@shopgate/engage/core';import{PAGE_PATTERN,getPageConfigById}from'@shopgate/engage/page';/**
2
2
  * Emits when a "page" was entered.
3
3
  */var pageDidEnter$=routeDidEnter$.filter(function(_ref){var action=_ref.action;return action.route.pattern===PAGE_PATTERN;});/**
4
4
  * Emits when the page route comes active again after a legacy page was active.
5
5
  */var pageRouteReappeared$=pwaDidAppear$.filter(function(_ref2){var action=_ref2.action;return action.route.pattern===PAGE_PATTERN;});var pageConfigReceived$=main$.filter(function(_ref3){var action=_ref3.action;return action.type===RECEIVE_PAGE_CONFIG;});/**
6
6
  * Emits when a "page" was opened, and its config is available.
7
- */export var pageIsReady$=pageDidEnter$.switchMap(function(data){var action=data.action,getState=data.getState;var pageId=action.route.params.pageId;// Check if the page config for the current route is already available within Redux.
7
+ */export var pageIsReady$=pageDidEnter$// Do not track while PWA webview is in the background
8
+ .filter(function(_ref4){var getState=_ref4.getState;return getIsAppWebViewVisible(getState());}).switchMap(function(data){var action=data.action,getState=data.getState;var pageId=action.route.params.pageId;// Check if the page config for the current route is already available within Redux.
8
9
  var pageConfig=getPageConfigById(getState(),{pageId:pageId});if(!pageConfig||pageConfig.isFetching){// Wait for incoming page data if it's not available yet.
9
10
  return pageConfigReceived$.first().switchMap(function(){return Observable.of(data);});}return Observable.of(data);}).merge(pageRouteReappeared$);
@@ -1,4 +1,4 @@
1
- import'rxjs/add/operator/switchMap';import{main$}from'@shopgate/pwa-common/streams/main';import{routeWillEnter$}from'@shopgate/pwa-common/streams/router';import{pwaDidAppear$}from'@shopgate/pwa-common/streams/app';import{receivedVisibleProduct$}from'@shopgate/pwa-common-commerce/product/streams';import{RECEIVE_PRODUCTS,ITEM_PATTERN}from'@shopgate/pwa-common-commerce/product/constants';/**
1
+ import'rxjs/add/operator/switchMap';import{main$}from'@shopgate/pwa-common/streams/main';import{routeWillEnter$}from'@shopgate/pwa-common/streams/router';import{pwaDidAppear$}from'@shopgate/pwa-common/streams/app';import{receivedVisibleProduct$}from'@shopgate/pwa-common-commerce/product/streams';import{RECEIVE_PRODUCTS,ITEM_PATTERN}from'@shopgate/pwa-common-commerce/product/constants';import{getIsAppWebViewVisible}from'@shopgate/engage/core';/**
2
2
  * Emits when product results has been received.
3
3
  */export var productsReceived$=main$.filter(function(_ref){var action=_ref.action;return action.type===RECEIVE_PRODUCTS;});/**
4
4
  * Emits when the category route comes active again after a legacy page was active.
@@ -6,5 +6,6 @@ import'rxjs/add/operator/switchMap';import{main$}from'@shopgate/pwa-common/strea
6
6
  * Emits when a product page was initially opened.
7
7
  */export var productWillEnter$=routeWillEnter$.filter(function(_ref3){var action=_ref3.action;return action.route.pattern===ITEM_PATTERN;});/**
8
8
  * Emits when a product page was initially opened and its data is present.
9
- */export var productIsReady$=productWillEnter$// Take care that the stream only emits when underlying streams emit within the correct order.
9
+ */export var productIsReady$=productWillEnter$// Do not track while PWA webview is in the background
10
+ .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.
10
11
  .switchMap(function(){return receivedVisibleProduct$.first();}).merge(productRouteReappeared$);
package/streams/search.js CHANGED
@@ -1,9 +1,10 @@
1
- import'rxjs/add/operator/switchMap';import'rxjs/add/observable/of';import{Observable}from'rxjs/Observable';import{SEARCH_PATTERN,RECEIVE_SEARCH_RESULTS}from'@shopgate/pwa-common-commerce/search/constants';import{getCurrentSearchQuery}from'@shopgate/pwa-common/selectors/router';import{searchDidEnter$}from'@shopgate/pwa-common-commerce/search/streams';import{getProductsResult}from'@shopgate/pwa-common-commerce/product/selectors/product';import{main$}from'@shopgate/pwa-common/streams/main';import{pwaDidAppear$}from'@shopgate/pwa-common/streams/app';/**
1
+ import'rxjs/add/operator/switchMap';import'rxjs/add/operator/filter';import'rxjs/add/observable/of';import{Observable}from'rxjs/Observable';import{SEARCH_PATTERN,RECEIVE_SEARCH_RESULTS}from'@shopgate/pwa-common-commerce/search/constants';import{getCurrentSearchQuery}from'@shopgate/pwa-common/selectors/router';import{searchDidEnter$}from'@shopgate/pwa-common-commerce/search/streams';import{getProductsResult}from'@shopgate/pwa-common-commerce/product/selectors/product';import{main$}from'@shopgate/pwa-common/streams/main';import{pwaDidAppear$}from'@shopgate/pwa-common/streams/app';import{getIsAppWebViewVisible}from'@shopgate/engage/core';/**
2
2
  * Emits when the search route comes active again after a legacy page was active.
3
3
  */var searchRouteReappeared$=pwaDidAppear$.filter(function(_ref){var action=_ref.action;return action.route.pattern===SEARCH_PATTERN;});/**
4
4
  * Emits when search results are received.
5
5
  */var resultsReceived$=main$.filter(function(_ref2){var action=_ref2.action;return action.type===RECEIVE_SEARCH_RESULTS;});/**
6
6
  * Emits when the search is ready to be tracked and all relevant data is available.
7
- */export var searchIsReady$=searchDidEnter$.switchMap(function(data){var getState=data.getState;var query=getCurrentSearchQuery(getState());// Check if products for the current route are already available within Redux.
7
+ */export var searchIsReady$=searchDidEnter$// Do not track while PWA webview is in the background
8
+ .filter(function(_ref3){var getState=_ref3.getState;return getIsAppWebViewVisible(getState());}).switchMap(function(data){var getState=data.getState;var query=getCurrentSearchQuery(getState());// Check if products for the current route are already available within Redux.
8
9
  var productsLoaded=getProductsResult(getState(),{searchPhrase:query}).totalProductCount!==null;if(!productsLoaded){// Wait for incoming products if they are not available yet.
9
10
  return resultsReceived$.first();}return Observable.of(data);}).merge(searchRouteReappeared$);
@@ -1,4 +1,4 @@
1
- import{productsAdded$}from'@shopgate/pwa-common-commerce/cart/streams';import{getAddToCartProducts}from"../selectors/cart";import getPage from"../selectors/page";import{track}from"../helpers/index";/**
1
+ import{productsAdded$}from"../streams/cart";import{getAddToCartProducts}from"../selectors/cart";import getPage from"../selectors/page";import{track}from"../helpers/index";/**
2
2
  * Pages tracking subscriptions.
3
3
  * @param {Function} subscribe The subscribe function.
4
4
  */export default function cart(subscribe){/**
@@ -1,16 +1,10 @@
1
- import{main$}from'@shopgate/pwa-common/streams/main';import{OPEN_DEEP_LINK,OPEN_PUSH_NOTIFICATION,OPEN_UNIVERSAL_LINK}from'@shopgate/pwa-common/constants/ActionTypes';import{track}from"../helpers/index";/**
2
- * Emits when a deeplink was opened.
3
- */var deeplinkOpened$=main$.filter(function(_ref){var action=_ref.action;return action.type===OPEN_DEEP_LINK;});/**
4
- * Emits when a push message was opened.
5
- */var pushOpened$=main$.filter(function(_ref2){var action=_ref2.action;return action.type===OPEN_PUSH_NOTIFICATION;});/**
6
- * Emits when a universal link was opened.
7
- */var universalLinkOpened$=main$.filter(function(_ref3){var action=_ref3.action;return action.type===OPEN_UNIVERSAL_LINK;});/**
1
+ import{pushNotificationOpened$,deeplinkOpened$,universalLinkOpened$}from'@shopgate/pwa-common/streams/app';import{track}from"../helpers/index";/**
8
2
  * Deeplink and push message tracking subscriptions.
9
3
  * @param {Function} subscribe The subscribe function.
10
4
  */export default function deeplinkPush(subscribe){/**
11
5
  * Gets triggered when a deeplink was opened.
12
- */subscribe(deeplinkOpened$,function(_ref4){var getState=_ref4.getState,action=_ref4.action;var state=getState();var _action$payload=action.payload,_action$payload$link=_action$payload.link,link=_action$payload$link===void 0?'':_action$payload$link,_action$payload$sourc=_action$payload.sourceApp,sourceApp=_action$payload$sourc===void 0?'':_action$payload$sourc,wasOpenedFromSearchIndex=_action$payload.wasOpenedFromSearchIndex;var eventLabel=wasOpenedFromSearchIndex?'os_search':sourceApp;track('openDeepLink',{eventAction:link,eventLabel:eventLabel},state);track('setCampaignWithUrl',{url:link,type:'deeplink'},state);});/**
6
+ */subscribe(deeplinkOpened$,function(_ref){var getState=_ref.getState,action=_ref.action;var state=getState();var _action$payload=action.payload,_action$payload$link=_action$payload.link,link=_action$payload$link===void 0?'':_action$payload$link,_action$payload$sourc=_action$payload.sourceApp,sourceApp=_action$payload$sourc===void 0?'':_action$payload$sourc,wasOpenedFromSearchIndex=_action$payload.wasOpenedFromSearchIndex;var eventLabel=wasOpenedFromSearchIndex?'os_search':sourceApp;track('openDeepLink',{eventAction:link,eventLabel:eventLabel},state);track('setCampaignWithUrl',{url:link,type:'deeplink'},state);});/**
13
7
  * Gets triggered when a push was opened.
14
- */subscribe(pushOpened$,function(_ref5){var getState=_ref5.getState,action=_ref5.action;var state=getState();var notificationId=action.notificationId?action.notificationId.toString():'n/a';track('openPushNotification',{eventAction:'opened',eventLabel:notificationId},state);track('setCampaignWithUrl',{url:action.link,notificationId:notificationId,type:'push_message'},state);});/**
8
+ */subscribe(pushNotificationOpened$,function(_ref2){var getState=_ref2.getState,action=_ref2.action;var state=getState();var notificationId=action.notificationId?action.notificationId.toString():'n/a';track('openPushNotification',{eventAction:'opened',eventLabel:notificationId},state);track('setCampaignWithUrl',{url:action.link,notificationId:notificationId,type:'push_message'},state);});/**
15
9
  * Gets triggered when a universal link was opened.
16
- */subscribe(universalLinkOpened$,function(_ref6){var getState=_ref6.getState,action=_ref6.action;var state=getState();var _action$payload2=action.payload,_action$payload2$link=_action$payload2.link,link=_action$payload2$link===void 0?'':_action$payload2$link,wasOpenedFromSearchIndex=_action$payload2.wasOpenedFromSearchIndex;var eventLabel=wasOpenedFromSearchIndex?'os_search':'n/a';track('openUniversalLink',{eventAction:link,eventLabel:eventLabel},state);track('setCampaignWithUrl',{url:link,type:'universal_link'},state);});}
10
+ */subscribe(universalLinkOpened$,function(_ref3){var getState=_ref3.getState,action=_ref3.action;var state=getState();var _action$payload2=action.payload,_action$payload2$link=_action$payload2.link,link=_action$payload2$link===void 0?'':_action$payload2$link,wasOpenedFromSearchIndex=_action$payload2.wasOpenedFromSearchIndex;var eventLabel=wasOpenedFromSearchIndex?'os_search':'n/a';track('openUniversalLink',{eventAction:link,eventLabel:eventLabel},state);track('setCampaignWithUrl',{url:link,type:'universal_link'},state);});}