@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/subscriptions/setup.js
CHANGED
|
@@ -1,17 +1,120 @@
|
|
|
1
|
-
import
|
|
1
|
+
import get from 'lodash/get';
|
|
2
|
+
import { logGroup, getWebStorageEntry, useBrowserConnector, errorManager, SOURCE_TRACKING, CODE_TRACKING, defaultClientInformation } from '@shopgate/pwa-core';
|
|
3
|
+
import { registerEvents } from '@shopgate/engage/core/commands';
|
|
4
|
+
import { appWillStart$ } from '@shopgate/engage/core/streams';
|
|
5
|
+
import { event } from '@shopgate/engage/core/classes';
|
|
6
|
+
import { TYPE_PHONE, OS_ALL, OS_ANDROID } from '@shopgate/pwa-common/constants/Device';
|
|
7
|
+
import appConfig, { shopNumber, componentsConfig } from '@shopgate/pwa-common/helpers/config';
|
|
8
|
+
import core from '@shopgate/tracking-core/core/Core';
|
|
9
|
+
import { COOKIE_CONSENT_UPDATED } from '@shopgate/tracking-core/helpers/events';
|
|
10
|
+
import { cookieConsentInitialized$, cookieConsentUpdated$ } from '@shopgate/engage/tracking/streams';
|
|
11
|
+
import UnifiedPlugin from '@shopgate/tracking-core/plugins/trackers/Unified';
|
|
12
|
+
import { track } from "../helpers/index";
|
|
13
|
+
|
|
14
|
+
/**
|
|
2
15
|
* Setup tracking subscriptions.
|
|
3
16
|
* @param {Function} subscribe The subscribe function.
|
|
4
|
-
*/
|
|
5
|
-
|
|
17
|
+
*/
|
|
18
|
+
export default function setup(subscribe) {
|
|
19
|
+
subscribe(appWillStart$, () => {
|
|
20
|
+
registerEvents(['nativeSgTrackingEventFired']);
|
|
21
|
+
|
|
22
|
+
// Route SgTracking events sent from the app to the tracking system
|
|
23
|
+
event.addCallback('nativeSgTrackingEventFired', ({
|
|
24
|
+
name,
|
|
25
|
+
params
|
|
26
|
+
}) => {
|
|
27
|
+
track(name, params);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/**
|
|
6
32
|
* Gets triggered when the app starts.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
33
|
+
*/
|
|
34
|
+
subscribe(cookieConsentInitialized$, async ({
|
|
35
|
+
getState,
|
|
36
|
+
action
|
|
37
|
+
}) => {
|
|
38
|
+
const {
|
|
39
|
+
statisticsCookiesAccepted,
|
|
40
|
+
comfortCookiesAccepted
|
|
41
|
+
} = action;
|
|
42
|
+
const clientInformationResponse = !useBrowserConnector() ? await getWebStorageEntry({
|
|
43
|
+
name: 'clientInformation'
|
|
44
|
+
}) : {
|
|
45
|
+
value: defaultClientInformation
|
|
46
|
+
};
|
|
47
|
+
const clientInformation = {
|
|
48
|
+
type: get(clientInformationResponse, 'value.device.type', TYPE_PHONE),
|
|
49
|
+
os: get(clientInformationResponse, 'value.device.os.platform', OS_ALL),
|
|
50
|
+
state: getState(),
|
|
51
|
+
services: get(clientInformationResponse, 'value.device.supportedAnalyticsServices', []),
|
|
52
|
+
libVersion: get(clientInformationResponse, 'value.libVersion'),
|
|
53
|
+
appVersion: get(clientInformationResponse, 'value.appVersion'),
|
|
54
|
+
cookieConsent: {
|
|
55
|
+
statisticsCookiesAccepted,
|
|
56
|
+
comfortCookiesAccepted
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// TODO: instantiate the UnifiedPlugin only if a native tracker is configured (FB, AppsFlyer)
|
|
61
|
+
// eslint-disable-next-line no-new
|
|
62
|
+
new UnifiedPlugin();
|
|
63
|
+
if (appConfig.tracking.hasWebTrackingEngage && statisticsCookiesAccepted) {
|
|
64
|
+
// eslint-disable-next-line global-require
|
|
65
|
+
const GaBase = require('@shopgate/tracking-core/plugins/trackers/GaBase').default;
|
|
66
|
+
GaBase.createUniversal({
|
|
67
|
+
shopNumber,
|
|
68
|
+
codebaseVersion: get(clientInformationResponse, 'value.codebaseVersion'),
|
|
69
|
+
config: {
|
|
70
|
+
merchant: [],
|
|
71
|
+
shopgate: {
|
|
72
|
+
id: clientInformation.os === OS_ANDROID ? appConfig.webTrackingEngage.android : appConfig.webTrackingEngage.ios,
|
|
73
|
+
useNetPrices: false
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
80
|
+
const extensionsIndex = require(`${process.env.THEME_PATH}/extensions/tracking`).default;
|
|
81
|
+
const trackingExtensions = componentsConfig.tracking || {};
|
|
82
|
+
Object.keys(trackingExtensions).forEach(key => {
|
|
83
|
+
const pluginInit = extensionsIndex[key];
|
|
84
|
+
if (pluginInit) {
|
|
85
|
+
/**
|
|
12
86
|
* Call the init function of the plugin.
|
|
13
87
|
* This init function will create the actual instances
|
|
14
|
-
*/
|
|
88
|
+
*/
|
|
89
|
+
pluginInit(clientInformation);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
} catch (error) {
|
|
93
|
+
logGroup('Tracking %c: Could not setup plugins', {
|
|
94
|
+
error
|
|
95
|
+
}, '#ED0422');
|
|
96
|
+
error.code = CODE_TRACKING;
|
|
97
|
+
error.source = SOURCE_TRACKING;
|
|
98
|
+
error.context = 'trackingPlugins';
|
|
99
|
+
errorManager.queue(error);
|
|
100
|
+
}
|
|
101
|
+
core.registerFinished();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
/**
|
|
15
105
|
* Gets triggered when the cookie consent selection changes. Registered trackers will be informed
|
|
16
106
|
* about the new decisions.
|
|
17
|
-
*/
|
|
107
|
+
*/
|
|
108
|
+
subscribe(cookieConsentUpdated$, ({
|
|
109
|
+
action
|
|
110
|
+
}) => {
|
|
111
|
+
const {
|
|
112
|
+
statisticsCookiesAccepted,
|
|
113
|
+
comfortCookiesAccepted
|
|
114
|
+
} = action;
|
|
115
|
+
track(COOKIE_CONSENT_UPDATED, {
|
|
116
|
+
statisticsCookiesAccepted,
|
|
117
|
+
comfortCookiesAccepted
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
package/subscriptions/user.js
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
|
-
import{loginDidFail$}from'@shopgate/engage/user';
|
|
1
|
+
import { loginDidFail$ } from '@shopgate/engage/user';
|
|
2
|
+
import { makeGetUser } from "../selectors/user";
|
|
3
|
+
import { loginSuccess$, registrationSuccess$ } from "../streams/user";
|
|
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 user(subscribe) {
|
|
11
|
+
subscribe(loginSuccess$, ({
|
|
12
|
+
getState
|
|
13
|
+
}) => {
|
|
14
|
+
const getUser = makeGetUser();
|
|
15
|
+
const state = getState();
|
|
16
|
+
track('loginSuccess', getUser(state), state);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
/**
|
|
5
20
|
* Gets triggered if login failed.
|
|
6
|
-
*/
|
|
21
|
+
*/
|
|
22
|
+
subscribe(loginDidFail$, ({
|
|
23
|
+
getState
|
|
24
|
+
}) => track('loginFailed', undefined, getState()));
|
|
25
|
+
subscribe(registrationSuccess$, ({
|
|
26
|
+
getState
|
|
27
|
+
}) => track('completedRegistration', {
|
|
28
|
+
registrationType: 'E-Mail'
|
|
29
|
+
}, getState()));
|
|
30
|
+
}
|