coveo.analytics 2.30.56 → 2.32.0

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.
Files changed (84) hide show
  1. package/README.md +37 -43
  2. package/dist/browser.mjs +513 -357
  3. package/dist/coveoua.browser.js +1 -1
  4. package/dist/coveoua.browser.js.map +1 -1
  5. package/dist/coveoua.debug.js +542 -359
  6. package/dist/coveoua.debug.js.map +1 -1
  7. package/dist/coveoua.js +1 -1
  8. package/dist/coveoua.js.map +1 -1
  9. package/dist/definitions/client/analytics.d.ts +3 -2
  10. package/dist/definitions/client/runtimeEnvironment.d.ts +1 -1
  11. package/dist/definitions/donottrack.d.ts +1 -0
  12. package/dist/definitions/react-native/index.d.ts +1 -2
  13. package/dist/definitions/version.d.ts +1 -1
  14. package/dist/library.cjs +15350 -3699
  15. package/dist/library.es.js +513 -357
  16. package/dist/library.js +15350 -3699
  17. package/dist/library.mjs +15350 -3699
  18. package/dist/react-native.es.js +634 -460
  19. package/modules/package.json +9 -9
  20. package/package.json +60 -91
  21. package/react-native/package.json +7 -7
  22. package/src/caseAssist/caseAssistActions.ts +51 -50
  23. package/src/caseAssist/caseAssistClient.spec.ts +328 -297
  24. package/src/caseAssist/caseAssistClient.ts +201 -185
  25. package/src/client/analytics.spec.ts +724 -703
  26. package/src/client/analytics.ts +677 -602
  27. package/src/client/analyticsBeaconClient.spec.ts +195 -188
  28. package/src/client/analyticsBeaconClient.ts +99 -88
  29. package/src/client/analyticsFetchClient.ts +77 -61
  30. package/src/client/analyticsRequestClient.ts +17 -17
  31. package/src/client/location.ts +3 -3
  32. package/src/client/measurementProtocolMapper.ts +54 -45
  33. package/src/client/measurementProtocolMapping/baseMeasurementProtocolMapper.ts +48 -44
  34. package/src/client/measurementProtocolMapping/commerceMeasurementProtocolMapper.ts +133 -121
  35. package/src/client/measurementProtocolMapping/serviceMeasurementProtocolMapper.ts +17 -17
  36. package/src/client/noopAnalytics.ts +80 -68
  37. package/src/client/runtimeEnvironment.ts +50 -41
  38. package/src/client/utils.spec.ts +112 -97
  39. package/src/client/utils.ts +39 -39
  40. package/src/cookieutils.spec.ts +59 -0
  41. package/src/cookieutils.ts +40 -39
  42. package/src/coveoua/browser.ts +14 -12
  43. package/src/coveoua/library.ts +4 -4
  44. package/src/coveoua/plugins.ts +36 -34
  45. package/src/coveoua/simpleanalytics.spec.ts +467 -452
  46. package/src/coveoua/simpleanalytics.ts +146 -140
  47. package/src/detector.ts +17 -17
  48. package/src/donottrack.spec.ts +199 -121
  49. package/src/donottrack.ts +31 -8
  50. package/src/events.ts +86 -79
  51. package/src/formatting/format-array-for-coveo-custom-data.spec.ts +13 -12
  52. package/src/formatting/format-array-for-coveo-custom-data.ts +18 -18
  53. package/src/formatting/format-omnibox-metadata.ts +16 -12
  54. package/src/history.spec.ts +197 -195
  55. package/src/history.ts +143 -133
  56. package/src/hook/addDefaultValues.ts +13 -8
  57. package/src/hook/enhanceViewEvent.ts +17 -17
  58. package/src/insight/insightClient.spec.ts +1848 -1717
  59. package/src/insight/insightClient.ts +866 -761
  60. package/src/insight/insightEvents.ts +57 -56
  61. package/src/plugins/BasePlugin.ts +125 -121
  62. package/src/plugins/ec.spec.ts +457 -429
  63. package/src/plugins/ec.ts +202 -199
  64. package/src/plugins/link.spec.ts +183 -159
  65. package/src/plugins/link.ts +88 -85
  66. package/src/plugins/svc.spec.ts +161 -155
  67. package/src/plugins/svc.ts +93 -91
  68. package/src/react-native/index.ts +8 -1
  69. package/src/react-native/react-native-runtime.ts +33 -33
  70. package/src/react-native/react-native-utils.ts +1 -1
  71. package/src/react-native/react-native.spec.ts +31 -21
  72. package/src/searchPage/searchPageClient.spec.ts +1944 -1794
  73. package/src/searchPage/searchPageClient.ts +1261 -1040
  74. package/src/searchPage/searchPageEvents.ts +524 -511
  75. package/src/storage.spec.ts +51 -51
  76. package/src/storage.ts +47 -47
  77. package/dist/definitions/bundle/browser-fetch.d.ts +0 -1
  78. package/dist/definitions/src/coveoua/browser.d.ts +0 -6
  79. package/dist/definitions/src/coveoua/headless.d.ts +0 -6
  80. package/dist/definitions/src/coveoua/library.d.ts +0 -17
  81. package/dist/definitions/src/coveoua/plugins.d.ts +0 -10
  82. package/dist/definitions/src/coveoua/simpleanalytics.d.ts +0 -33
  83. package/dist/definitions/src/react-native/index.d.ts +0 -3
  84. package/dist/definitions/src/react-native/react-native-runtime.d.ts +0 -19
@@ -3,170 +3,182 @@ import {keysOf} from '../utils';
3
3
 
4
4
  // Based off: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#enhanced-ecomm
5
5
  const productKeysMapping: {[key in keyof Product]: string} = {
6
- id: 'id',
7
- name: 'nm',
8
- brand: 'br',
9
- category: 'ca',
10
- variant: 'va',
11
- price: 'pr',
12
- quantity: 'qt',
13
- coupon: 'cc',
14
- position: 'ps',
15
- // Below are keys that were extended for Coveo
16
- group: 'group',
6
+ id: 'id',
7
+ name: 'nm',
8
+ brand: 'br',
9
+ category: 'ca',
10
+ variant: 'va',
11
+ price: 'pr',
12
+ quantity: 'qt',
13
+ coupon: 'cc',
14
+ position: 'ps',
15
+ // Below are keys that were extended for Coveo
16
+ group: 'group',
17
17
  };
18
18
 
19
19
  const impressionKeysMapping: {[key in keyof BaseImpression]: string} = {
20
- id: 'id',
21
- name: 'nm',
22
- brand: 'br',
23
- category: 'ca',
24
- variant: 'va',
25
- position: 'ps',
26
- price: 'pr',
27
- // Below are keys that were extended for Coveo
28
- group: 'group',
20
+ id: 'id',
21
+ name: 'nm',
22
+ brand: 'br',
23
+ category: 'ca',
24
+ variant: 'va',
25
+ position: 'ps',
26
+ price: 'pr',
27
+ // Below are keys that were extended for Coveo
28
+ group: 'group',
29
29
  };
30
30
 
31
31
  const productActionsKeysMapping: {[name: string]: string} = {
32
- action: 'pa',
33
- list: 'pal',
34
- listSource: 'pls',
32
+ action: 'pa',
33
+ list: 'pal',
34
+ listSource: 'pls',
35
35
  };
36
36
 
37
37
  const transactionActionsKeysMapping: {[name: string]: string} = {
38
- id: 'ti',
39
- revenue: 'tr',
40
- tax: 'tt',
41
- shipping: 'ts',
42
- coupon: 'tcc',
43
- affiliation: 'ta',
44
- step: 'cos',
45
- option: 'col',
38
+ id: 'ti',
39
+ revenue: 'tr',
40
+ tax: 'tt',
41
+ shipping: 'ts',
42
+ coupon: 'tcc',
43
+ affiliation: 'ta',
44
+ step: 'cos',
45
+ option: 'col',
46
46
  };
47
47
 
48
48
  // These extension keys do not have direct mappings, we are sending them as-is, thus only requiring an array.
49
49
  const coveoCommerceExtensionKeys: string[] = [
50
- 'loyaltyCardId',
51
- 'loyaltyTier',
52
- 'thirdPartyPersona',
53
- 'companyName',
54
- 'favoriteStore',
55
- 'storeName',
56
- 'userIndustry',
57
- 'userRole',
58
- 'userDepartment',
59
- 'businessUnit',
50
+ 'loyaltyCardId',
51
+ 'loyaltyTier',
52
+ 'thirdPartyPersona',
53
+ 'companyName',
54
+ 'favoriteStore',
55
+ 'storeName',
56
+ 'userIndustry',
57
+ 'userRole',
58
+ 'userDepartment',
59
+ 'businessUnit',
60
60
  ];
61
61
 
62
62
  const quoteActionsKeysMapping: {[name: string]: string} = {
63
- id: 'quoteId',
64
- affiliation: 'quoteAffiliation',
63
+ id: 'quoteId',
64
+ affiliation: 'quoteAffiliation',
65
65
  };
66
66
 
67
67
  const reviewActionsKeysMapping: {[name: string]: string} = {
68
- id: 'reviewId',
69
- rating: 'reviewRating',
70
- comment: 'reviewComment',
68
+ id: 'reviewId',
69
+ rating: 'reviewRating',
70
+ comment: 'reviewComment',
71
71
  };
72
72
 
73
73
  export const commerceActionKeysMappingPerAction: Record<string, {[name: string]: string}> = {
74
- add: productActionsKeysMapping,
75
- bookmark_add: productActionsKeysMapping,
76
- bookmark_remove: productActionsKeysMapping,
77
- click: productActionsKeysMapping,
78
- checkout: productActionsKeysMapping,
79
- checkout_option: productActionsKeysMapping,
80
- detail: productActionsKeysMapping,
81
- impression: productActionsKeysMapping,
82
- remove: productActionsKeysMapping,
83
- refund: {
84
- ...productActionsKeysMapping,
85
- ...transactionActionsKeysMapping,
86
- },
87
- purchase: {
88
- ...productActionsKeysMapping,
89
- ...transactionActionsKeysMapping,
90
- },
91
- quickview: productActionsKeysMapping,
92
- quote: {
93
- ...productActionsKeysMapping,
94
- ...quoteActionsKeysMapping,
95
- },
96
- review: {
97
- ...productActionsKeysMapping,
98
- ...reviewActionsKeysMapping,
99
- },
74
+ add: productActionsKeysMapping,
75
+ bookmark_add: productActionsKeysMapping,
76
+ bookmark_remove: productActionsKeysMapping,
77
+ click: productActionsKeysMapping,
78
+ checkout: productActionsKeysMapping,
79
+ checkout_option: productActionsKeysMapping,
80
+ detail: productActionsKeysMapping,
81
+ impression: productActionsKeysMapping,
82
+ remove: productActionsKeysMapping,
83
+ refund: {
84
+ ...productActionsKeysMapping,
85
+ ...transactionActionsKeysMapping,
86
+ },
87
+ purchase: {
88
+ ...productActionsKeysMapping,
89
+ ...transactionActionsKeysMapping,
90
+ },
91
+ quickview: productActionsKeysMapping,
92
+ quote: {
93
+ ...productActionsKeysMapping,
94
+ ...quoteActionsKeysMapping,
95
+ },
96
+ review: {
97
+ ...productActionsKeysMapping,
98
+ ...reviewActionsKeysMapping,
99
+ },
100
100
  };
101
101
 
102
102
  export const convertProductToMeasurementProtocol = (product: Product, index: number) => {
103
- return keysOf(product).reduce((mappedProduct, key) => {
104
- const newKey = `pr${index + 1}${productKeysMapping[key] || key}`;
105
- return {
106
- ...mappedProduct,
107
- [newKey]: product[key],
108
- };
109
- }, {});
103
+ return keysOf(product).reduce((mappedProduct, key) => {
104
+ const newKey = `pr${index + 1}${productKeysMapping[key] || key}`;
105
+ return {
106
+ ...mappedProduct,
107
+ [newKey]: product[key],
108
+ };
109
+ }, {});
110
110
  };
111
111
 
112
112
  export const convertImpressionListToMeasurementProtocol = (
113
- impressionList: ImpressionList,
114
- listIndex: number,
115
- prefix: string,
113
+ impressionList: ImpressionList,
114
+ listIndex: number,
115
+ prefix: string
116
116
  ) => {
117
- const payload: {[name: string]: any} = impressionList.impressions.reduce(
118
- (mappedImpressions, impression, productIndex) => {
119
- return {
120
- ...mappedImpressions,
121
- ...convertImpressionToMeasurementProtocol(impression, listIndex, productIndex, prefix),
122
- };
123
- },
124
- {},
125
- );
126
-
127
- if (impressionList.listName) {
128
- const listNameKey = `il${listIndex + 1}nm`;
129
- payload[listNameKey] = impressionList.listName;
130
- }
131
- return payload;
117
+ const payload: {[name: string]: any} = impressionList.impressions.reduce(
118
+ (mappedImpressions, impression, productIndex) => {
119
+ return {
120
+ ...mappedImpressions,
121
+ ...convertImpressionToMeasurementProtocol(impression, listIndex, productIndex, prefix),
122
+ };
123
+ },
124
+ {}
125
+ );
126
+
127
+ if (impressionList.listName) {
128
+ const listNameKey = `il${listIndex + 1}nm`;
129
+ payload[listNameKey] = impressionList.listName;
130
+ }
131
+ return payload;
132
132
  };
133
133
 
134
134
  const convertImpressionToMeasurementProtocol = (
135
- impression: BaseImpression,
136
- listIndex: number,
137
- productIndex: number,
138
- prefix: string,
135
+ impression: BaseImpression,
136
+ listIndex: number,
137
+ productIndex: number,
138
+ prefix: string
139
139
  ) => {
140
- return keysOf(impression).reduce((mappedImpression, key) => {
141
- const newKey = `il${listIndex + 1}${prefix}${productIndex + 1}${impressionKeysMapping[key] || key}`;
142
- return {
143
- ...mappedImpression,
144
- [newKey]: impression[key],
145
- };
146
- }, {});
140
+ return keysOf(impression).reduce((mappedImpression, key) => {
141
+ const newKey = `il${listIndex + 1}${prefix}${productIndex + 1}${impressionKeysMapping[key] || key}`;
142
+ return {
143
+ ...mappedImpression,
144
+ [newKey]: impression[key],
145
+ };
146
+ }, {});
147
147
  };
148
148
 
149
149
  const productKeysMappingValues = keysOf(productKeysMapping).map((key) => productKeysMapping[key]);
150
- const impressionKeysMappingValues = keysOf(impressionKeysMapping).map((key) => impressionKeysMapping[key]);
151
- const productActionsKeysMappingValues = keysOf(productActionsKeysMapping).map((key) => productActionsKeysMapping[key]);
150
+ const impressionKeysMappingValues = keysOf(impressionKeysMapping).map(
151
+ (key) => impressionKeysMapping[key]
152
+ );
153
+ const productActionsKeysMappingValues = keysOf(productActionsKeysMapping).map(
154
+ (key) => productActionsKeysMapping[key]
155
+ );
152
156
  const transactionActionsKeysMappingValues = keysOf(transactionActionsKeysMapping).map(
153
- (key) => transactionActionsKeysMapping[key],
157
+ (key) => transactionActionsKeysMapping[key]
158
+ );
159
+ const reviewKeysMappingValues = keysOf(reviewActionsKeysMapping).map(
160
+ (key) => reviewActionsKeysMapping[key]
161
+ );
162
+ const quoteKeysMappingValues = keysOf(quoteActionsKeysMapping).map(
163
+ (key) => quoteActionsKeysMapping[key]
154
164
  );
155
- const reviewKeysMappingValues = keysOf(reviewActionsKeysMapping).map((key) => reviewActionsKeysMapping[key]);
156
- const quoteKeysMappingValues = keysOf(quoteActionsKeysMapping).map((key) => quoteActionsKeysMapping[key]);
157
165
 
158
166
  const productSubKeysMatchGroup = [...productKeysMappingValues, 'custom'].join('|');
159
167
  const impressionSubKeysMatchGroup = [...impressionKeysMappingValues, 'custom'].join('|');
160
168
  const productPrefixMatchGroup = '(pr[0-9]+)';
161
169
  const impressionPrefixMatchGroup = '(il[0-9]+pi[0-9]+)';
162
170
  const productKeyRegex = new RegExp(`^${productPrefixMatchGroup}(${productSubKeysMatchGroup})$`);
163
- const impressionKeyRegex = new RegExp(`^(${impressionPrefixMatchGroup}(${impressionSubKeysMatchGroup}))|(il[0-9]+nm)$`);
171
+ const impressionKeyRegex = new RegExp(
172
+ `^(${impressionPrefixMatchGroup}(${impressionSubKeysMatchGroup}))|(il[0-9]+nm)$`
173
+ );
164
174
  const productActionsKeyRegex = new RegExp(`^(${productActionsKeysMappingValues.join('|')})$`);
165
- const transactionActionsKeyRegex = new RegExp(`^(${transactionActionsKeysMappingValues.join('|')})$`);
175
+ const transactionActionsKeyRegex = new RegExp(
176
+ `^(${transactionActionsKeysMappingValues.join('|')})$`
177
+ );
166
178
  const customProductKeyRegex = new RegExp(`^${productPrefixMatchGroup}custom$`);
167
179
  const customImpressionKeyRegex = new RegExp(`^${impressionPrefixMatchGroup}custom$`);
168
180
  const coveoCommerceExtensionKeysRegex = new RegExp(
169
- `^(${[...coveoCommerceExtensionKeys, ...reviewKeysMappingValues, ...quoteKeysMappingValues].join('|')})$`,
181
+ `^(${[...coveoCommerceExtensionKeys, ...reviewKeysMappingValues, ...quoteKeysMappingValues].join('|')})$`
170
182
  );
171
183
 
172
184
  const isProductKey = (key: string) => productKeyRegex.test(key);
@@ -176,10 +188,10 @@ const isTransactionActionsKeyRegex = (key: string) => transactionActionsKeyRegex
176
188
  const isCoveoCommerceExtensionKey = (key: string) => coveoCommerceExtensionKeysRegex.test(key);
177
189
 
178
190
  export const isCommerceKey = [
179
- isImpressionKey,
180
- isProductKey,
181
- isProductActionsKey,
182
- isTransactionActionsKeyRegex,
183
- isCoveoCommerceExtensionKey,
191
+ isImpressionKey,
192
+ isProductKey,
193
+ isProductActionsKey,
194
+ isTransactionActionsKeyRegex,
195
+ isCoveoCommerceExtensionKey,
184
196
  ];
185
197
  export const isCustomCommerceKey = [customProductKeyRegex, customImpressionKeyRegex];
@@ -2,32 +2,32 @@ import {Ticket} from '../../plugins/svc';
2
2
  import {keysOf} from '../utils';
3
3
 
4
4
  const ticketKeysMapping: {[key in keyof Ticket]: string} = {
5
- id: 'svc_ticket_id',
6
- subject: 'svc_ticket_subject',
7
- description: 'svc_ticket_description',
8
- category: 'svc_ticket_category',
9
- productId: 'svc_ticket_product_id',
10
- custom: 'svc_ticket_custom',
5
+ id: 'svc_ticket_id',
6
+ subject: 'svc_ticket_subject',
7
+ description: 'svc_ticket_description',
8
+ category: 'svc_ticket_category',
9
+ productId: 'svc_ticket_product_id',
10
+ custom: 'svc_ticket_custom',
11
11
  };
12
12
  const ticketKeysMappingValues = keysOf(ticketKeysMapping).map((key) => ticketKeysMapping[key]);
13
13
  const ticketSubKeysMatchGroup = [...ticketKeysMappingValues].join('|');
14
14
  const ticketKeyRegex = new RegExp(`^(${ticketSubKeysMatchGroup}$)`);
15
15
 
16
16
  export const serviceActionsKeysMapping: {[name: string]: string} = {
17
- svcAction: 'svc_action',
18
- svcActionData: 'svc_action_data',
17
+ svcAction: 'svc_action',
18
+ svcActionData: 'svc_action_data',
19
19
  };
20
20
 
21
21
  export const convertTicketToMeasurementProtocol = (ticket: Ticket) => {
22
- return keysOf(ticket)
23
- .filter((key) => ticket[key] !== undefined)
24
- .reduce((mappedTicket, key) => {
25
- const newKey = ticketKeysMapping[key] || key;
26
- return {
27
- ...mappedTicket,
28
- [newKey]: ticket[key],
29
- };
30
- }, {});
22
+ return keysOf(ticket)
23
+ .filter((key) => ticket[key] !== undefined)
24
+ .reduce((mappedTicket, key) => {
25
+ const newKey = ticketKeysMapping[key] || key;
26
+ return {
27
+ ...mappedTicket,
28
+ [newKey]: ticket[key],
29
+ };
30
+ }, {});
31
31
  };
32
32
 
33
33
  const isTicketKey = (key: string) => ticketKeyRegex.test(key);
@@ -1,76 +1,88 @@
1
1
  import {AnalyticsClient, PreparedEvent} from './analytics';
2
2
  import {
3
- AnyEventResponse,
4
- SearchEventResponse,
5
- ClickEventResponse,
6
- CustomEventResponse,
7
- VisitResponse,
8
- HealthResponse,
9
- ViewEventResponse,
10
- EventType,
11
- PreparedSearchEventRequest,
12
- SearchEventRequest,
13
- ClickEventRequest,
14
- CustomEventRequest,
15
- PreparedClickEventRequest,
16
- PreparedCustomEventRequest,
17
- PreparedViewEventRequest,
18
- ViewEventRequest,
3
+ AnyEventResponse,
4
+ SearchEventResponse,
5
+ ClickEventResponse,
6
+ CustomEventResponse,
7
+ VisitResponse,
8
+ HealthResponse,
9
+ ViewEventResponse,
10
+ EventType,
11
+ PreparedSearchEventRequest,
12
+ SearchEventRequest,
13
+ ClickEventRequest,
14
+ CustomEventRequest,
15
+ PreparedClickEventRequest,
16
+ PreparedCustomEventRequest,
17
+ PreparedViewEventRequest,
18
+ ViewEventRequest,
19
19
  } from '../events';
20
20
  import {libVersion} from '../version';
21
21
  import {NoopRuntime} from './runtimeEnvironment';
22
22
 
23
23
  export class NoopAnalytics implements AnalyticsClient {
24
- getPayload(): Promise<any> {
25
- return Promise.resolve();
26
- }
27
- getParameters(): Promise<any> {
28
- return Promise.resolve();
29
- }
30
- makeEvent<TPreparedRequest, TCompleteRequest, TResponse extends AnyEventResponse>(
31
- eventType: EventType | string,
32
- ): Promise<PreparedEvent<TPreparedRequest, TCompleteRequest, TResponse>> {
33
- return Promise.resolve({eventType: eventType as EventType, payload: null, log: () => Promise.resolve()});
34
- }
35
- sendEvent(): Promise<AnyEventResponse | void> {
36
- return Promise.resolve();
37
- }
38
- makeSearchEvent() {
39
- return this.makeEvent<PreparedSearchEventRequest, SearchEventRequest, SearchEventResponse>(EventType.search);
40
- }
41
- sendSearchEvent(): Promise<SearchEventResponse | void> {
42
- return Promise.resolve();
43
- }
44
- makeClickEvent() {
45
- return this.makeEvent<PreparedClickEventRequest, ClickEventRequest, ClickEventResponse>(EventType.click);
46
- }
47
- sendClickEvent(): Promise<ClickEventResponse | void> {
48
- return Promise.resolve();
49
- }
50
- makeCustomEvent() {
51
- return this.makeEvent<PreparedCustomEventRequest, CustomEventRequest, CustomEventResponse>(EventType.custom);
52
- }
53
- sendCustomEvent(): Promise<CustomEventResponse | void> {
54
- return Promise.resolve();
55
- }
56
- makeViewEvent() {
57
- return this.makeEvent<PreparedViewEventRequest, ViewEventRequest, ViewEventResponse>(EventType.view);
58
- }
59
- sendViewEvent(): Promise<ViewEventResponse | void> {
60
- return Promise.resolve();
61
- }
62
- getVisit(): Promise<VisitResponse> {
63
- return Promise.resolve({id: '', visitorId: ''});
64
- }
65
- getHealth(): Promise<HealthResponse> {
66
- return Promise.resolve({status: ''});
67
- }
68
- registerBeforeSendEventHook(): void {}
69
- registerAfterSendEventHook(): void {}
70
- addEventTypeMapping(): void {}
71
- runtime = new NoopRuntime();
72
- public get version(): string {
73
- return libVersion;
74
- }
75
- currentVisitorId = '';
24
+ getPayload(): Promise<any> {
25
+ return Promise.resolve();
26
+ }
27
+ getParameters(): Promise<any> {
28
+ return Promise.resolve();
29
+ }
30
+ makeEvent<TPreparedRequest, TCompleteRequest, TResponse extends AnyEventResponse>(
31
+ eventType: EventType | string
32
+ ): Promise<PreparedEvent<TPreparedRequest, TCompleteRequest, TResponse>> {
33
+ return Promise.resolve({
34
+ eventType: eventType as EventType,
35
+ payload: null,
36
+ log: () => Promise.resolve(),
37
+ });
38
+ }
39
+ sendEvent(): Promise<AnyEventResponse | void> {
40
+ return Promise.resolve();
41
+ }
42
+ makeSearchEvent() {
43
+ return this.makeEvent<PreparedSearchEventRequest, SearchEventRequest, SearchEventResponse>(
44
+ EventType.search
45
+ );
46
+ }
47
+ sendSearchEvent(): Promise<SearchEventResponse | void> {
48
+ return Promise.resolve();
49
+ }
50
+ makeClickEvent() {
51
+ return this.makeEvent<PreparedClickEventRequest, ClickEventRequest, ClickEventResponse>(
52
+ EventType.click
53
+ );
54
+ }
55
+ sendClickEvent(): Promise<ClickEventResponse | void> {
56
+ return Promise.resolve();
57
+ }
58
+ makeCustomEvent() {
59
+ return this.makeEvent<PreparedCustomEventRequest, CustomEventRequest, CustomEventResponse>(
60
+ EventType.custom
61
+ );
62
+ }
63
+ sendCustomEvent(): Promise<CustomEventResponse | void> {
64
+ return Promise.resolve();
65
+ }
66
+ makeViewEvent() {
67
+ return this.makeEvent<PreparedViewEventRequest, ViewEventRequest, ViewEventResponse>(
68
+ EventType.view
69
+ );
70
+ }
71
+ sendViewEvent(): Promise<ViewEventResponse | void> {
72
+ return Promise.resolve();
73
+ }
74
+ getVisit(): Promise<VisitResponse> {
75
+ return Promise.resolve({id: '', visitorId: ''});
76
+ }
77
+ getHealth(): Promise<HealthResponse> {
78
+ return Promise.resolve({status: ''});
79
+ }
80
+ registerBeforeSendEventHook(): void {}
81
+ registerAfterSendEventHook(): void {}
82
+ addEventTypeMapping(): void {}
83
+ runtime = new NoopRuntime();
84
+ public get version(): string {
85
+ return libVersion;
86
+ }
87
+ currentVisitorId = '';
76
88
  }
@@ -1,65 +1,74 @@
1
1
  import {WebStorage, NullStorage, CookieAndLocalStorage} from '../storage';
2
2
  import {AnalyticsBeaconClient} from './analyticsBeaconClient';
3
3
  import {hasLocalStorage, hasCookieStorage} from '../detector';
4
- import {AnalyticsRequestClient, IAnalyticsClientOptions, NoopAnalyticsClient} from './analyticsRequestClient';
4
+ import {
5
+ AnalyticsRequestClient,
6
+ IAnalyticsClientOptions,
7
+ NoopAnalyticsClient,
8
+ } from './analyticsRequestClient';
5
9
  import {AnalyticsFetchClient} from './analyticsFetchClient';
6
10
  import {BufferedRequest} from './analytics';
7
11
  import {EventType} from '../events';
8
12
 
9
13
  export interface IRuntimeEnvironment {
10
- storage: WebStorage;
11
- client: AnalyticsRequestClient;
12
- getClientDependingOnEventType(eventType: EventType): AnalyticsRequestClient;
14
+ storage: WebStorage;
15
+ client: AnalyticsRequestClient;
16
+ getClientDependingOnEventType(eventType: EventType): AnalyticsRequestClient;
13
17
  }
14
18
 
15
19
  export class BrowserRuntime implements IRuntimeEnvironment {
16
- public storage: WebStorage;
17
- public client: AnalyticsFetchClient;
18
- private beaconClient: AnalyticsBeaconClient;
20
+ public storage: WebStorage;
21
+ public client: AnalyticsFetchClient;
22
+ private beaconClient: AnalyticsBeaconClient;
19
23
 
20
- constructor(clientOptions: IAnalyticsClientOptions, getUnprocessedRequests: () => Array<BufferedRequest>) {
21
- if (hasLocalStorage() && hasCookieStorage()) {
22
- this.storage = new CookieAndLocalStorage();
23
- } else if (hasLocalStorage()) {
24
- this.storage = localStorage;
25
- } else {
26
- console.warn('BrowserRuntime detected no valid storage available.', this);
27
- this.storage = new NullStorage();
28
- }
29
- this.client = new AnalyticsFetchClient(clientOptions);
30
- this.beaconClient = new AnalyticsBeaconClient(clientOptions);
31
- window.addEventListener('beforeunload', () => {
32
- const requests = getUnprocessedRequests();
33
- for (let {eventType, payload} of requests) {
34
- this.beaconClient.sendEvent(eventType, payload);
35
- }
36
- });
24
+ constructor(
25
+ clientOptions: IAnalyticsClientOptions,
26
+ getUnprocessedRequests: () => Array<BufferedRequest>
27
+ ) {
28
+ if (hasLocalStorage() && hasCookieStorage()) {
29
+ this.storage = new CookieAndLocalStorage();
30
+ } else if (hasLocalStorage()) {
31
+ this.storage = localStorage;
32
+ } else {
33
+ console.warn('BrowserRuntime detected no valid storage available.', this);
34
+ this.storage = new NullStorage();
37
35
  }
36
+ this.client = new AnalyticsFetchClient(clientOptions);
37
+ this.beaconClient = new AnalyticsBeaconClient(clientOptions);
38
+ window.addEventListener('beforeunload', () => {
39
+ const requests = getUnprocessedRequests();
40
+ for (let {eventType, payload} of requests) {
41
+ this.beaconClient.sendEvent(eventType, payload);
42
+ }
43
+ });
44
+ }
38
45
 
39
- public getClientDependingOnEventType(eventType: EventType) {
40
- return eventType === 'click' && this.beaconClient.isAvailable() ? this.beaconClient : this.client;
41
- }
46
+ public getClientDependingOnEventType(eventType: EventType) {
47
+ return eventType === 'click' && this.beaconClient.isAvailable()
48
+ ? this.beaconClient
49
+ : this.client;
50
+ }
42
51
  }
43
52
 
44
53
  export class NodeJSRuntime implements IRuntimeEnvironment {
45
- public storage: WebStorage;
46
- public client: AnalyticsFetchClient;
54
+ public storage: WebStorage;
55
+ public client: AnalyticsFetchClient;
47
56
 
48
- constructor(clientOptions: IAnalyticsClientOptions, storage?: WebStorage) {
49
- this.storage = storage || new NullStorage();
50
- this.client = new AnalyticsFetchClient(clientOptions);
51
- }
57
+ constructor(clientOptions: IAnalyticsClientOptions, storage?: WebStorage) {
58
+ this.storage = storage || new NullStorage();
59
+ this.client = new AnalyticsFetchClient(clientOptions);
60
+ }
52
61
 
53
- getClientDependingOnEventType(eventType: EventType): AnalyticsRequestClient {
54
- return this.client;
55
- }
62
+ getClientDependingOnEventType(eventType: EventType): AnalyticsRequestClient {
63
+ return this.client;
64
+ }
56
65
  }
57
66
 
58
67
  export class NoopRuntime implements IRuntimeEnvironment {
59
- public storage = new NullStorage();
60
- public client = new NoopAnalyticsClient();
68
+ public storage = new NullStorage();
69
+ public client = new NoopAnalyticsClient();
61
70
 
62
- getClientDependingOnEventType(eventType: EventType): AnalyticsRequestClient {
63
- return this.client;
64
- }
71
+ getClientDependingOnEventType(eventType: EventType): AnalyticsRequestClient {
72
+ return this.client;
73
+ }
65
74
  }