@shopgate/pwa-tracking 7.30.0-alpha.7 → 7.30.0-alpha.8
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/helpers/index.js +412 -15
- package/package.json +5 -5
- package/selectors/cart.js +30 -5
- package/selectors/category.js +25 -2
- package/selectors/favorites.js +7 -2
- package/selectors/index.js +29 -3
- package/selectors/page.js +46 -8
- package/selectors/product.js +30 -4
- package/selectors/search.js +34 -4
- package/selectors/user.js +31 -2
- package/spec.js +6 -1
- package/streams/app.js +9 -3
- package/streams/cart.js +55 -12
- package/streams/category.js +72 -11
- package/streams/checkout.js +26 -5
- package/streams/page.js +49 -7
- package/streams/pages.js +33 -6
- package/streams/product.js +33 -7
- package/streams/scanner.js +43 -2
- package/streams/search.js +44 -7
- package/streams/user.js +13 -4
- package/subscriptions/cart.js +23 -3
- package/subscriptions/checkout.js +71 -3
- package/subscriptions/deeplinkPush.js +70 -5
- package/subscriptions/favorites.js +39 -6
- package/subscriptions/pages.js +28 -3
- package/subscriptions/product.js +40 -4
- package/subscriptions/scanner.js +94 -3
- package/subscriptions/search.js +17 -2
- package/subscriptions/setup.js +113 -10
- package/subscriptions/user.js +27 -3
package/streams/search.js
CHANGED
|
@@ -1,10 +1,47 @@
|
|
|
1
|
-
import'rxjs/add/operator/switchMap';
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
*/
|
|
4
|
-
|
|
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
|
-
*/
|
|
14
|
+
*/
|
|
15
|
+
export const registrationSuccess$ = registrationSuccessCore$.switchMap(() => userDataReceived$.first());
|
package/subscriptions/cart.js
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
|
-
import{productsAdded$}from"../streams/cart";
|
|
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
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
export default function cart(subscribe) {
|
|
11
|
+
/**
|
|
5
12
|
* Gets triggered on product variant change/selection
|
|
6
|
-
*/
|
|
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
|
-
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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';
|
|
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
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
export default function deeplinkPush(subscribe) {
|
|
9
|
+
/**
|
|
5
10
|
* Gets triggered when a deeplink was opened.
|
|
6
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
|
|
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
|
-
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
}
|
package/subscriptions/pages.js
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
|
-
import{getCurrentRoute}from'@shopgate/engage/core/selectors';
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
+
}
|
package/subscriptions/product.js
CHANGED
|
@@ -1,8 +1,44 @@
|
|
|
1
|
-
import{getCurrentRoute}from'@shopgate/engage/core/selectors';
|
|
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
|
-
*/
|
|
11
|
+
*/
|
|
12
|
+
export default function product(subscribe) {
|
|
13
|
+
/**
|
|
5
14
|
* Gets triggered on product variant change/selection.
|
|
6
|
-
*/
|
|
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
|
-
*/
|
|
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
|
+
}
|
package/subscriptions/scanner.js
CHANGED
|
@@ -1,5 +1,96 @@
|
|
|
1
|
-
|
|
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
|
-
*/
|
|
5
|
-
|
|
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
|
+
}
|
package/subscriptions/search.js
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
import{getCurrentRoute}from'@shopgate/engage/core/selectors';
|
|
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
|
-
*/
|
|
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
|
+
}
|