@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.
@@ -1,17 +1,120 @@
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 get from'lodash/get';import{logGroup,getWebStorageEntry,useBrowserConnector,errorManager,SOURCE_TRACKING,CODE_TRACKING,defaultClientInformation}from'@shopgate/pwa-core';import{registerEvents}from'@shopgate/engage/core/commands';import{appWillStart$}from'@shopgate/engage/core/streams';import{event}from'@shopgate/engage/core/classes';import{TYPE_PHONE,OS_ALL,OS_ANDROID}from'@shopgate/pwa-common/constants/Device';import appConfig,{shopNumber,componentsConfig}from'@shopgate/pwa-common/helpers/config';import core from'@shopgate/tracking-core/core/Core';import{COOKIE_CONSENT_UPDATED}from'@shopgate/tracking-core/helpers/events';import{cookieConsentInitialized$,cookieConsentUpdated$}from'@shopgate/engage/tracking/streams';import UnifiedPlugin from'@shopgate/tracking-core/plugins/trackers/Unified';import{track}from"../helpers/index";/**
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
- */export default function setup(subscribe){subscribe(appWillStart$,function(){registerEvents(['nativeSgTrackingEventFired']);// Route SgTracking events sent from the app to the tracking system
5
- event.addCallback('nativeSgTrackingEventFired',function(_ref){var name=_ref.name,params=_ref.params;track(name,params);});});/**
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
- */subscribe(cookieConsentInitialized$,/*#__PURE__*/function(){var _ref3=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2){var getState,action,statisticsCookiesAccepted,comfortCookiesAccepted,clientInformationResponse,clientInformation,GaBase,extensionsIndex,trackingExtensions;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:getState=_ref2.getState,action=_ref2.action;statisticsCookiesAccepted=action.statisticsCookiesAccepted,comfortCookiesAccepted=action.comfortCookiesAccepted;if(useBrowserConnector()){_context.next=8;break;}_context.next=5;return getWebStorageEntry({name:'clientInformation'});case 5:_context.t0=_context.sent;_context.next=9;break;case 8:_context.t0={value:defaultClientInformation};case 9:clientInformationResponse=_context.t0;clientInformation={type:get(clientInformationResponse,'value.device.type',TYPE_PHONE),os:get(clientInformationResponse,'value.device.os.platform',OS_ALL),state:getState(),services:get(clientInformationResponse,'value.device.supportedAnalyticsServices',[]),libVersion:get(clientInformationResponse,'value.libVersion'),appVersion:get(clientInformationResponse,'value.appVersion'),cookieConsent:{statisticsCookiesAccepted:statisticsCookiesAccepted,comfortCookiesAccepted:comfortCookiesAccepted}};// TODO: instantiate the UnifiedPlugin only if a native tracker is configured (FB, AppsFlyer)
8
- // eslint-disable-next-line no-new
9
- new UnifiedPlugin();if(appConfig.tracking.hasWebTrackingEngage&&statisticsCookiesAccepted){// eslint-disable-next-line global-require
10
- GaBase=require('@shopgate/tracking-core/plugins/trackers/GaBase')["default"];GaBase.createUniversal({shopNumber:shopNumber,codebaseVersion:get(clientInformationResponse,'value.codebaseVersion'),config:{merchant:[],shopgate:{id:clientInformation.os===OS_ANDROID?appConfig.webTrackingEngage.android:appConfig.webTrackingEngage.ios,useNetPrices:false}}});}try{// eslint-disable-next-line global-require, import/no-dynamic-require
11
- extensionsIndex=require("".concat(process.env.THEME_PATH,"/extensions/tracking"))["default"];trackingExtensions=componentsConfig.tracking||{};Object.keys(trackingExtensions).forEach(function(key){var pluginInit=extensionsIndex[key];if(pluginInit){/**
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
- */pluginInit(clientInformation);}});}catch(error){logGroup('Tracking %c: Could not setup plugins',{error:error},'#ED0422');error.code=CODE_TRACKING;error.source=SOURCE_TRACKING;error.context='trackingPlugins';errorManager.queue(error);}core.registerFinished();case 15:case"end":return _context.stop();}},_callee);}));return function(_x){return _ref3.apply(this,arguments);};}());/**
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
- */subscribe(cookieConsentUpdated$,function(_ref4){var action=_ref4.action;var statisticsCookiesAccepted=action.statisticsCookiesAccepted,comfortCookiesAccepted=action.comfortCookiesAccepted;track(COOKIE_CONSENT_UPDATED,{statisticsCookiesAccepted:statisticsCookiesAccepted,comfortCookiesAccepted:comfortCookiesAccepted});});}
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
+ }
@@ -1,6 +1,30 @@
1
- import{loginDidFail$}from'@shopgate/engage/user';import{makeGetUser}from"../selectors/user";import{loginSuccess$,registrationSuccess$}from"../streams/user";import{track}from"../helpers/index";/**
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
- */export default function user(subscribe){subscribe(loginSuccess$,function(_ref){var getState=_ref.getState;var getUser=makeGetUser();var state=getState();track('loginSuccess',getUser(state),state);});/**
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
- */subscribe(loginDidFail$,function(_ref2){var getState=_ref2.getState;return track('loginFailed',undefined,getState());});subscribe(registrationSuccess$,function(_ref3){var getState=_ref3.getState;return track('completedRegistration',{registrationType:'E-Mail'},getState());});}
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
+ }