@shopgate/pwa-tracking 7.30.0-alpha.7 → 7.30.0-alpha.9

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/streams/search.js CHANGED
@@ -1,10 +1,47 @@
1
- import'rxjs/add/operator/switchMap';import'rxjs/add/operator/filter';import'rxjs/add/observable/of';import{Observable}from'rxjs/Observable';import{getProductsResult}from'@shopgate/pwa-common-commerce/product/selectors/product';import{main$,pwaDidAppear$}from'@shopgate/engage/core/streams';import{getIsAppWebViewVisible,getCurrentSearchQuery}from'@shopgate/engage/core/selectors';import{SEARCH_PATTERN,RECEIVE_SEARCH_RESULTS}from'@shopgate/engage/search/constants';import{searchDidEnter$}from'@shopgate/engage/search/streams';/**
1
+ import 'rxjs/add/operator/switchMap';
2
+ import 'rxjs/add/operator/filter';
3
+ import 'rxjs/add/observable/of';
4
+ import { Observable } from 'rxjs/Observable';
5
+ import { getProductsResult } from '@shopgate/pwa-common-commerce/product/selectors/product';
6
+ import { main$, pwaDidAppear$ } from '@shopgate/engage/core/streams';
7
+ import { getIsAppWebViewVisible, getCurrentSearchQuery } from '@shopgate/engage/core/selectors';
8
+ import { SEARCH_PATTERN, RECEIVE_SEARCH_RESULTS } from '@shopgate/engage/search/constants';
9
+ import { searchDidEnter$ } from '@shopgate/engage/search/streams';
10
+
11
+ /**
2
12
  * Emits when the search route comes active again after a legacy page was active.
3
- */var searchRouteReappeared$=pwaDidAppear$.filter(function(_ref){var action=_ref.action;return action.route.pattern===SEARCH_PATTERN;});/**
13
+ */
14
+ const searchRouteReappeared$ = pwaDidAppear$.filter(({
15
+ action
16
+ }) => action.route.pattern === SEARCH_PATTERN);
17
+
18
+ /**
4
19
  * Emits when search results are received.
5
- */var resultsReceived$=main$.filter(function(_ref2){var action=_ref2.action;return action.type===RECEIVE_SEARCH_RESULTS;});/**
20
+ */
21
+ const resultsReceived$ = main$.filter(({
22
+ action
23
+ }) => action.type === RECEIVE_SEARCH_RESULTS);
24
+
25
+ /**
6
26
  * Emits when the search is ready to be tracked and all relevant data is available.
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.
9
- var productsLoaded=getProductsResult(getState(),{searchPhrase:query}).totalProductCount!==null;if(!productsLoaded){// Wait for incoming products if they are not available yet.
10
- return resultsReceived$.first();}return Observable.of(data);}).merge(searchRouteReappeared$);
27
+ */
28
+ export const searchIsReady$ = searchDidEnter$
29
+ // Do not track while PWA webview is in the background
30
+ .filter(({
31
+ getState
32
+ }) => getIsAppWebViewVisible(getState())).switchMap(data => {
33
+ const {
34
+ getState
35
+ } = data;
36
+ const query = getCurrentSearchQuery(getState());
37
+
38
+ // Check if products for the current route are already available within Redux.
39
+ const productsLoaded = getProductsResult(getState(), {
40
+ searchPhrase: query
41
+ }).totalProductCount !== null;
42
+ if (!productsLoaded) {
43
+ // Wait for incoming products if they are not available yet.
44
+ return resultsReceived$.first();
45
+ }
46
+ return Observable.of(data);
47
+ }).merge(searchRouteReappeared$);
package/streams/user.js CHANGED
@@ -1,6 +1,15 @@
1
- import{userDidLogin$,userDataReceived$,registrationSuccess$ as registrationSuccessCore$,REGISTRATION_FORM_LOGIN_STRATEGY}from'@shopgate/engage/user';/**
1
+ import { userDidLogin$, userDataReceived$, registrationSuccess$ as registrationSuccessCore$, REGISTRATION_FORM_LOGIN_STRATEGY } from '@shopgate/engage/user';
2
+
3
+ /**
2
4
  * Gets triggered if login was successful and we received the user data.
3
- */export var loginSuccess$=userDidLogin$// Do not track a login when user was automatically logged in after registration
4
- .filter(function(_ref){var action=_ref.action;return(action===null||action===void 0?void 0:action.strategy)!==REGISTRATION_FORM_LOGIN_STRATEGY;}).switchMap(function(){return userDataReceived$.first();});/**
5
+ */
6
+ export const loginSuccess$ = userDidLogin$
7
+ // Do not track a login when user was automatically logged in after registration
8
+ .filter(({
9
+ action
10
+ }) => action?.strategy !== REGISTRATION_FORM_LOGIN_STRATEGY).switchMap(() => userDataReceived$.first());
11
+
12
+ /**
5
13
  * Gets triggered if registration was successful and we received the user data.
6
- */export var registrationSuccess$=registrationSuccessCore$.switchMap(function(){return userDataReceived$.first();});
14
+ */
15
+ export const registrationSuccess$ = registrationSuccessCore$.switchMap(() => userDataReceived$.first());
@@ -1,6 +1,26 @@
1
- import{productsAdded$}from"../streams/cart";import{getAddToCartProducts}from"../selectors/cart";import getPage from"../selectors/page";import{track}from"../helpers/index";/**
1
+ import { productsAdded$ } from "../streams/cart";
2
+ import { getAddToCartProducts } from "../selectors/cart";
3
+ import getPage from "../selectors/page";
4
+ import { track } from "../helpers/index";
5
+
6
+ /**
2
7
  * Pages tracking subscriptions.
3
8
  * @param {Function} subscribe The subscribe function.
4
- */export default function cart(subscribe){/**
9
+ */
10
+ export default function cart(subscribe) {
11
+ /**
5
12
  * Gets triggered on product variant change/selection
6
- */subscribe(productsAdded$,function(_ref){var getState=_ref.getState,action=_ref.action;var state=getState();var products=getAddToCartProducts(state,action.products);var page=getPage(state);track('addToCart',{products:products,page:page},state);});}
13
+ */
14
+ subscribe(productsAdded$, ({
15
+ getState,
16
+ action
17
+ }) => {
18
+ const state = getState();
19
+ const products = getAddToCartProducts(state, action.products);
20
+ const page = getPage(state);
21
+ track('addToCart', {
22
+ products,
23
+ page
24
+ }, state);
25
+ });
26
+ }
@@ -1,6 +1,74 @@
1
- function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{event}from'@shopgate/engage/core/classes';import{appDidStart$}from'@shopgate/engage/core/streams';import{analyticsSetCustomValues}from'@shopgate/engage/core/commands';import{checkoutSuccess$}from'@shopgate/engage/checkout/streams';import getCart from"../selectors/cart";import{track,formatPurchaseData,formatNativeCheckoutPurchaseData}from"../helpers";import{checkoutDidEnter$}from"../streams/checkout";/**
1
+ import { event } from '@shopgate/engage/core/classes';
2
+ import { appDidStart$ } from '@shopgate/engage/core/streams';
3
+ import { analyticsSetCustomValues } from '@shopgate/engage/core/commands';
4
+ import { checkoutSuccess$ } from '@shopgate/engage/checkout/streams';
5
+ import getCart from "../selectors/cart";
6
+ import { track, formatPurchaseData, formatNativeCheckoutPurchaseData } from "../helpers";
7
+ import { checkoutDidEnter$ } from "../streams/checkout";
8
+
9
+ /**
2
10
  * Checkout tracking subscriptions.
3
11
  * @param {Function} subscribe The subscribe function.
4
- */export default function checkout(subscribe){subscribe(checkoutDidEnter$,function(_ref){var getState=_ref.getState;var state=getState();track('initiatedCheckout',{cart:getCart(state)},state);});/**
12
+ */
13
+ export default function checkout(subscribe) {
14
+ subscribe(checkoutDidEnter$, ({
15
+ getState
16
+ }) => {
17
+ const state = getState();
18
+ track('initiatedCheckout', {
19
+ cart: getCart(state)
20
+ }, state);
21
+ });
22
+
23
+ /**
5
24
  * Gets triggered when the app starts.
6
- */subscribe(appDidStart$,function(_ref2){var getState=_ref2.getState;event.addCallback('checkoutSuccess',function(){var data=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};if(typeof data.order==='undefined'){return;}var source=data.type!=='legacy'?'web_PWA':'app_PWA';analyticsSetCustomValues({customDimensions:[{index:4,value:source}]});var formattedData=_extends({},formatPurchaseData(data.order),{meta:{source:source}});track('purchase',formattedData,getState());});});subscribe(checkoutSuccess$,function(_ref3){var getState=_ref3.getState,action=_ref3.action;var order=action.order;if(typeof order==='undefined'){return;}var source=(order===null||order===void 0?void 0:order.platform)==='desktop'?'web_PWA':'app_PWA';analyticsSetCustomValues({customDimensions:[{index:4,value:source}]});var formattedData=_extends({},formatNativeCheckoutPurchaseData(order),{meta:{source:source}});track('purchase',formattedData,getState());});}
25
+ */
26
+ subscribe(appDidStart$, ({
27
+ getState
28
+ }) => {
29
+ event.addCallback('checkoutSuccess', (data = {}) => {
30
+ if (typeof data.order === 'undefined') {
31
+ return;
32
+ }
33
+ const source = data.type !== 'legacy' ? 'web_PWA' : 'app_PWA';
34
+ analyticsSetCustomValues({
35
+ customDimensions: [{
36
+ index: 4,
37
+ value: source
38
+ }]
39
+ });
40
+ const formattedData = {
41
+ ...formatPurchaseData(data.order),
42
+ meta: {
43
+ source
44
+ }
45
+ };
46
+ track('purchase', formattedData, getState());
47
+ });
48
+ });
49
+ subscribe(checkoutSuccess$, ({
50
+ getState,
51
+ action
52
+ }) => {
53
+ const {
54
+ order
55
+ } = action;
56
+ if (typeof order === 'undefined') {
57
+ return;
58
+ }
59
+ const source = order?.platform === 'desktop' ? 'web_PWA' : 'app_PWA';
60
+ analyticsSetCustomValues({
61
+ customDimensions: [{
62
+ index: 4,
63
+ value: source
64
+ }]
65
+ });
66
+ const formattedData = {
67
+ ...formatNativeCheckoutPurchaseData(order),
68
+ meta: {
69
+ source
70
+ }
71
+ };
72
+ track('purchase', formattedData, getState());
73
+ });
74
+ }
@@ -1,10 +1,75 @@
1
- import{pushNotificationOpened$,deeplinkOpened$,universalLinkOpened$}from'@shopgate/engage/core/streams';import{track}from"../helpers/index";/**
1
+ import { pushNotificationOpened$, deeplinkOpened$, universalLinkOpened$ } from '@shopgate/engage/core/streams';
2
+ import { track } from "../helpers/index";
3
+
4
+ /**
2
5
  * Deeplink and push message tracking subscriptions.
3
6
  * @param {Function} subscribe The subscribe function.
4
- */export default function deeplinkPush(subscribe){/**
7
+ */
8
+ export default function deeplinkPush(subscribe) {
9
+ /**
5
10
  * Gets triggered when a deeplink was opened.
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);});/**
11
+ */
12
+ subscribe(deeplinkOpened$, ({
13
+ getState,
14
+ action
15
+ }) => {
16
+ const state = getState();
17
+ const {
18
+ link = '',
19
+ sourceApp = '',
20
+ wasOpenedFromSearchIndex
21
+ } = action.payload;
22
+ const eventLabel = wasOpenedFromSearchIndex ? 'os_search' : sourceApp;
23
+ track('openDeepLink', {
24
+ eventAction: link,
25
+ eventLabel
26
+ }, state);
27
+ track('setCampaignWithUrl', {
28
+ url: link,
29
+ type: 'deeplink'
30
+ }, state);
31
+ });
32
+
33
+ /**
7
34
  * Gets triggered when a push was opened.
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);});/**
35
+ */
36
+ subscribe(pushNotificationOpened$, ({
37
+ getState,
38
+ action
39
+ }) => {
40
+ const state = getState();
41
+ const notificationId = action.notificationId ? action.notificationId.toString() : 'n/a';
42
+ track('openPushNotification', {
43
+ eventAction: 'opened',
44
+ eventLabel: notificationId
45
+ }, state);
46
+ track('setCampaignWithUrl', {
47
+ url: action.link,
48
+ notificationId,
49
+ type: 'push_message'
50
+ }, state);
51
+ });
52
+
53
+ /**
9
54
  * Gets triggered when a universal link was opened.
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);});}
55
+ */
56
+ subscribe(universalLinkOpened$, ({
57
+ getState,
58
+ action
59
+ }) => {
60
+ const state = getState();
61
+ const {
62
+ link = '',
63
+ wasOpenedFromSearchIndex
64
+ } = action.payload;
65
+ const eventLabel = wasOpenedFromSearchIndex ? 'os_search' : 'n/a';
66
+ track('openUniversalLink', {
67
+ eventAction: link,
68
+ eventLabel
69
+ }, state);
70
+ track('setCampaignWithUrl', {
71
+ url: link,
72
+ type: 'universal_link'
73
+ }, state);
74
+ });
75
+ }
@@ -1,8 +1,41 @@
1
- function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{favoritesDidAddItem$}from'@shopgate/pwa-common-commerce/favorites/streams';import getPage from"../selectors/page";import{track}from"../helpers/index";import{getProductFormatted}from"../selectors/product";/**
1
+ import { favoritesDidAddItem$ } from '@shopgate/pwa-common-commerce/favorites/streams';
2
+ import getPage from "../selectors/page";
3
+ import { track } from "../helpers/index";
4
+ import { getProductFormatted } from "../selectors/product";
5
+
6
+ /**
2
7
  * Favorites tracking subscriptions.
3
8
  * @param {Function} subscribe The subscribe function.
4
- */export default function favorites(subscribe){subscribe(favoritesDidAddItem$,function(_ref){var getState=_ref.getState,action=_ref.action;var state=getState();var page=getPage(state);var productId=action.productId;productId=[].concat(productId);// cast to array
5
- var favouriteListProducts=productId.map(function(id){var product=getProductFormatted(state,{productId:id});return _extends({},product,{// eslint-disable-next-line camelcase
6
- unit_amount_net:product.amount.net*100,// eslint-disable-next-line camelcase
7
- unit_amount_with_tax:product.amount.gross*100,// eslint-disable-next-line camelcase
8
- currency_id:product.amount.currency});});track('addToWishlist',{page:page,favouriteListProducts:favouriteListProducts},state);});}
9
+ */
10
+ export default function favorites(subscribe) {
11
+ subscribe(favoritesDidAddItem$, ({
12
+ getState,
13
+ action
14
+ }) => {
15
+ const state = getState();
16
+ const page = getPage(state);
17
+ let {
18
+ productId
19
+ } = action;
20
+ productId = [].concat(productId); // cast to array
21
+
22
+ const favouriteListProducts = productId.map(id => {
23
+ const product = getProductFormatted(state, {
24
+ productId: id
25
+ });
26
+ return {
27
+ ...product,
28
+ // eslint-disable-next-line camelcase
29
+ unit_amount_net: product.amount.net * 100,
30
+ // eslint-disable-next-line camelcase
31
+ unit_amount_with_tax: product.amount.gross * 100,
32
+ // eslint-disable-next-line camelcase
33
+ currency_id: product.amount.currency
34
+ };
35
+ });
36
+ track('addToWishlist', {
37
+ page,
38
+ favouriteListProducts
39
+ }, state);
40
+ });
41
+ }
@@ -1,7 +1,32 @@
1
- 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";/**
1
+ import { getCurrentRoute } from '@shopgate/engage/core/selectors';
2
+ import { categoryIsReady$ } from "../streams/category";
3
+ import { searchIsReady$ } from "../streams/search";
4
+ import { productIsReady$ } from "../streams/product";
5
+ import { pagesAreReady$ } from "../streams/pages";
6
+ import { pageIsReady$ } from "../streams/page";
7
+ import { makeGetTrackingData } from "../selectors";
8
+ import { track } from "../helpers";
9
+
10
+ /**
2
11
  * Calls the pageview core tracking function.
3
12
  * @param {Object} input The input of the tracked stream.
4
- */var callPageViewTracker=function callPageViewTracker(_ref){var getState=_ref.getState;var state=getState();var getTrackingData=makeGetTrackingData();track('pageview',getTrackingData(state,getCurrentRoute(state)),state);};/**
13
+ */
14
+ const callPageViewTracker = ({
15
+ getState
16
+ }) => {
17
+ const state = getState();
18
+ const getTrackingData = makeGetTrackingData();
19
+ track('pageview', getTrackingData(state, getCurrentRoute(state)), state);
20
+ };
21
+
22
+ /**
5
23
  * Pages tracking subscriptions.
6
24
  * @param {Function} subscribe The subscribe function.
7
- */export default function pages(subscribe){subscribe(categoryIsReady$,callPageViewTracker);subscribe(searchIsReady$,callPageViewTracker);subscribe(productIsReady$,callPageViewTracker);subscribe(pagesAreReady$,callPageViewTracker);subscribe(pageIsReady$,callPageViewTracker);}
25
+ */
26
+ export default function pages(subscribe) {
27
+ subscribe(categoryIsReady$, callPageViewTracker);
28
+ subscribe(searchIsReady$, callPageViewTracker);
29
+ subscribe(productIsReady$, callPageViewTracker);
30
+ subscribe(pagesAreReady$, callPageViewTracker);
31
+ subscribe(pageIsReady$, callPageViewTracker);
32
+ }
@@ -1,8 +1,44 @@
1
- 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";/**
1
+ import { getCurrentRoute } from '@shopgate/engage/core/selectors';
2
+ import { variantDidChange$ } from '@shopgate/pwa-common-commerce/product/streams';
3
+ import { productIsReady$ } from "../streams/product";
4
+ import { getBaseProductFormatted, getProductFormatted } from "../selectors/product";
5
+ import { makeGetTrackingData } from "../selectors";
6
+ import { track } from "../helpers";
7
+
8
+ /**
2
9
  * Product tracking subscriptions.
3
10
  * @param {Function} subscribe The subscribe function.
4
- */export default function product(subscribe){/**
11
+ */
12
+ export default function product(subscribe) {
13
+ /**
5
14
  * Gets triggered on product variant change/selection.
6
- */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);});/**
15
+ */
16
+ subscribe(variantDidChange$, ({
17
+ getState,
18
+ action
19
+ }) => {
20
+ const state = getState();
21
+ const {
22
+ id: productId
23
+ } = action.productData;
24
+ const props = {
25
+ productId
26
+ };
27
+ const trackingData = {
28
+ variant: getProductFormatted(state, props),
29
+ baseProduct: getBaseProductFormatted(state, props)
30
+ };
31
+ track('variantSelected', trackingData, state);
32
+ });
33
+
34
+ /**
7
35
  * Gets triggered on product pageview.
8
- */subscribe(productIsReady$,function(_ref2){var getState=_ref2.getState;var state=getState();var getTrackingData=makeGetTrackingData();track('viewContent',getTrackingData(state,getCurrentRoute(state)),state);});}
36
+ */
37
+ subscribe(productIsReady$, ({
38
+ getState
39
+ }) => {
40
+ const state = getState();
41
+ const getTrackingData = makeGetTrackingData();
42
+ track('viewContent', getTrackingData(state, getCurrentRoute(state)), state);
43
+ });
44
+ }
@@ -1,5 +1,96 @@
1
- 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 core from'@shopgate/tracking-core/core/Core';import{routeDidLeave$}from'@shopgate/engage/core/streams';import{scanActivated$,scanFail$,scanSuccess$}from"../streams/scanner";import{buildScannerUtmUrl,createScannerEventData,track}from"../helpers";/**
1
+ import core from '@shopgate/tracking-core/core/Core';
2
+ import { routeDidLeave$ } from '@shopgate/engage/core/streams';
3
+ import { scanActivated$, scanFail$, scanSuccess$ } from "../streams/scanner";
4
+ import { buildScannerUtmUrl, createScannerEventData, track } from "../helpers";
5
+
6
+ /**
2
7
  * Scanner tracking subscriptions.
3
8
  * @param {Function} subscribe The subscribe function.
4
- */export default function scanner(subscribe){var events=core.getScannerEvents();subscribe(scanActivated$,function(_ref){var action=_ref.action,getState=_ref.getState;var format=action.format;track('qrScanner',createScannerEventData({event:events.SCAN_ACTIVATED,userInteraction:false,format:format}),getState());});subscribe(scanSuccess$,function(_ref2){var action=_ref2.action,getState=_ref2.getState;var format=action.format,payload=action.payload;track('qrScanner',createScannerEventData({event:events.SCAN_SUCCESS,format:format,payload:payload}),getState());});subscribe(scanFail$,function(_ref3){var action=_ref3.action,getState=_ref3.getState;var format=action.format,payload=action.payload;track('qrScanner',createScannerEventData({event:events.SCAN_FAIL,format:format,payload:payload}),getState());});var afterScan$=scanActivated$.withLatestFrom(routeDidLeave$).switchMap(function(){return scanSuccess$.first();},function(_ref4,successAction){var _ref5=_slicedToArray(_ref4,2),activatedAction=_ref5[0],refererAction=_ref5[1];return{activatedAction:activatedAction,refererAction:refererAction,successAction:successAction,getState:activatedAction.getState};});subscribe(afterScan$,function(_ref6){var activatedAction=_ref6.activatedAction,refererAction=_ref6.refererAction,successAction=_ref6.successAction,getState=_ref6.getState;var _activatedAction$acti=activatedAction.action,_activatedAction$acti2=_activatedAction$acti===void 0?{}:_activatedAction$acti,scannerRoute=_activatedAction$acti2.route;var _refererAction$action=refererAction.action.route,_refererAction$action2=_refererAction$action===void 0?{}:_refererAction$action,referer=_refererAction$action2.location;var _successAction$action=successAction.action,format=_successAction$action.format,payload=_successAction$action.payload;// eslint-disable-next-line extra-rules/no-single-line-objects
5
- var urlWithUtm=buildScannerUtmUrl({scannerRoute:scannerRoute,format:format,payload:payload,referer:referer});track('setCampaignWithUrl',{url:urlWithUtm,type:'scanner'},getState());});}
9
+ */
10
+ export default function scanner(subscribe) {
11
+ const events = core.getScannerEvents();
12
+ subscribe(scanActivated$, ({
13
+ action,
14
+ getState
15
+ }) => {
16
+ const {
17
+ format
18
+ } = action;
19
+ track('qrScanner', createScannerEventData({
20
+ event: events.SCAN_ACTIVATED,
21
+ userInteraction: false,
22
+ format
23
+ }), getState());
24
+ });
25
+ subscribe(scanSuccess$, ({
26
+ action,
27
+ getState
28
+ }) => {
29
+ const {
30
+ format,
31
+ payload
32
+ } = action;
33
+ track('qrScanner', createScannerEventData({
34
+ event: events.SCAN_SUCCESS,
35
+ format,
36
+ payload
37
+ }), getState());
38
+ });
39
+ subscribe(scanFail$, ({
40
+ action,
41
+ getState
42
+ }) => {
43
+ const {
44
+ format,
45
+ payload
46
+ } = action;
47
+ track('qrScanner', createScannerEventData({
48
+ event: events.SCAN_FAIL,
49
+ format,
50
+ payload
51
+ }), getState());
52
+ });
53
+ const afterScan$ = scanActivated$.withLatestFrom(routeDidLeave$).switchMap(() => scanSuccess$.first(), ([activatedAction, refererAction], successAction) => ({
54
+ activatedAction,
55
+ refererAction,
56
+ successAction,
57
+ getState: activatedAction.getState
58
+ }));
59
+ subscribe(afterScan$, ({
60
+ activatedAction,
61
+ refererAction,
62
+ successAction,
63
+ getState
64
+ }) => {
65
+ const {
66
+ action: {
67
+ route: scannerRoute
68
+ } = {}
69
+ } = activatedAction;
70
+ const {
71
+ action: {
72
+ route: {
73
+ location: referer
74
+ } = {}
75
+ }
76
+ } = refererAction;
77
+ const {
78
+ action: {
79
+ format,
80
+ payload
81
+ }
82
+ } = successAction;
83
+
84
+ // eslint-disable-next-line extra-rules/no-single-line-objects
85
+ const urlWithUtm = buildScannerUtmUrl({
86
+ scannerRoute,
87
+ format,
88
+ payload,
89
+ referer
90
+ });
91
+ track('setCampaignWithUrl', {
92
+ url: urlWithUtm,
93
+ type: 'scanner'
94
+ }, getState());
95
+ });
96
+ }
@@ -1,4 +1,19 @@
1
- import{getCurrentRoute}from'@shopgate/engage/core/selectors';import{searchIsReady$}from"../streams/search";import getTrackingData from"../selectors/search";import{track}from"../helpers/index";/**
1
+ import { getCurrentRoute } from '@shopgate/engage/core/selectors';
2
+ import { searchIsReady$ } from "../streams/search";
3
+ import getTrackingData from "../selectors/search";
4
+ import { track } from "../helpers/index";
5
+
6
+ /**
2
7
  * Search tracking subscriptions.
3
8
  * @param {Function} subscribe The subscribe function.
4
- */export default function search(subscribe){subscribe(searchIsReady$,function(_ref){var getState=_ref.getState;var state=getState();track('search',{search:getTrackingData(state,getCurrentRoute(state))},state);});}
9
+ */
10
+ export default function search(subscribe) {
11
+ subscribe(searchIsReady$, ({
12
+ getState
13
+ }) => {
14
+ const state = getState();
15
+ track('search', {
16
+ search: getTrackingData(state, getCurrentRoute(state))
17
+ }, state);
18
+ });
19
+ }