coveo.analytics 2.30.55 → 2.31.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 (86) hide show
  1. package/README.md +37 -43
  2. package/dist/browser.mjs +525 -357
  3. package/dist/coveoua.browser.js +1 -1
  4. package/dist/coveoua.browser.js.map +1 -1
  5. package/dist/coveoua.debug.js +559 -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 -1
  13. package/dist/definitions/searchPage/searchPageClient.d.ts +3 -1
  14. package/dist/definitions/searchPage/searchPageEvents.d.ts +6 -0
  15. package/dist/definitions/version.d.ts +1 -1
  16. package/dist/library.cjs +15367 -3699
  17. package/dist/library.es.js +525 -357
  18. package/dist/library.js +15367 -3699
  19. package/dist/library.mjs +15367 -3699
  20. package/dist/react-native.es.js +646 -460
  21. package/modules/package.json +9 -9
  22. package/package.json +60 -91
  23. package/react-native/package.json +7 -7
  24. package/src/caseAssist/caseAssistActions.ts +51 -50
  25. package/src/caseAssist/caseAssistClient.spec.ts +328 -297
  26. package/src/caseAssist/caseAssistClient.ts +201 -185
  27. package/src/client/analytics.spec.ts +724 -703
  28. package/src/client/analytics.ts +677 -602
  29. package/src/client/analyticsBeaconClient.spec.ts +195 -188
  30. package/src/client/analyticsBeaconClient.ts +99 -88
  31. package/src/client/analyticsFetchClient.ts +77 -61
  32. package/src/client/analyticsRequestClient.ts +17 -17
  33. package/src/client/location.ts +3 -3
  34. package/src/client/measurementProtocolMapper.ts +54 -45
  35. package/src/client/measurementProtocolMapping/baseMeasurementProtocolMapper.ts +48 -44
  36. package/src/client/measurementProtocolMapping/commerceMeasurementProtocolMapper.ts +133 -121
  37. package/src/client/measurementProtocolMapping/serviceMeasurementProtocolMapper.ts +17 -17
  38. package/src/client/noopAnalytics.ts +80 -68
  39. package/src/client/runtimeEnvironment.ts +50 -41
  40. package/src/client/utils.spec.ts +112 -97
  41. package/src/client/utils.ts +39 -39
  42. package/src/cookieutils.spec.ts +59 -0
  43. package/src/cookieutils.ts +40 -39
  44. package/src/coveoua/browser.ts +14 -12
  45. package/src/coveoua/library.ts +4 -4
  46. package/src/coveoua/plugins.ts +36 -34
  47. package/src/coveoua/simpleanalytics.spec.ts +467 -452
  48. package/src/coveoua/simpleanalytics.ts +146 -140
  49. package/src/detector.ts +17 -17
  50. package/src/donottrack.spec.ts +199 -121
  51. package/src/donottrack.ts +31 -8
  52. package/src/events.ts +86 -79
  53. package/src/formatting/format-array-for-coveo-custom-data.spec.ts +13 -12
  54. package/src/formatting/format-array-for-coveo-custom-data.ts +18 -18
  55. package/src/formatting/format-omnibox-metadata.ts +16 -12
  56. package/src/history.spec.ts +197 -195
  57. package/src/history.ts +143 -133
  58. package/src/hook/addDefaultValues.ts +13 -8
  59. package/src/hook/enhanceViewEvent.ts +17 -17
  60. package/src/insight/insightClient.spec.ts +1848 -1717
  61. package/src/insight/insightClient.ts +866 -761
  62. package/src/insight/insightEvents.ts +57 -56
  63. package/src/plugins/BasePlugin.ts +125 -121
  64. package/src/plugins/ec.spec.ts +457 -429
  65. package/src/plugins/ec.ts +202 -199
  66. package/src/plugins/link.spec.ts +183 -159
  67. package/src/plugins/link.ts +88 -85
  68. package/src/plugins/svc.spec.ts +161 -155
  69. package/src/plugins/svc.ts +93 -91
  70. package/src/react-native/index.ts +5 -1
  71. package/src/react-native/react-native-runtime.ts +33 -33
  72. package/src/react-native/react-native-utils.ts +1 -1
  73. package/src/react-native/react-native.spec.ts +22 -21
  74. package/src/searchPage/searchPageClient.spec.ts +1944 -1766
  75. package/src/searchPage/searchPageClient.ts +1261 -1029
  76. package/src/searchPage/searchPageEvents.ts +529 -500
  77. package/src/storage.spec.ts +51 -51
  78. package/src/storage.ts +47 -47
  79. package/dist/definitions/bundle/browser-fetch.d.ts +0 -1
  80. package/dist/definitions/src/coveoua/browser.d.ts +0 -6
  81. package/dist/definitions/src/coveoua/headless.d.ts +0 -6
  82. package/dist/definitions/src/coveoua/library.d.ts +0 -17
  83. package/dist/definitions/src/coveoua/plugins.d.ts +0 -10
  84. package/dist/definitions/src/coveoua/simpleanalytics.d.ts +0 -33
  85. package/dist/definitions/src/react-native/index.d.ts +0 -3
  86. package/dist/definitions/src/react-native/react-native-runtime.d.ts +0 -19
@@ -8,181 +8,187 @@ import {libVersion} from '../version';
8
8
  export type AvailableActions = keyof CoveoUA;
9
9
 
10
10
  export interface CoveoUAOptions {
11
- endpoint?: string;
12
- isCustomEndpoint?: boolean;
13
- plugins?: string[];
11
+ endpoint?: string;
12
+ isCustomEndpoint?: boolean;
13
+ plugins?: string[];
14
14
  }
15
15
 
16
16
  // CoveoUA mimics the GoogleAnalytics API.
17
17
  export class CoveoUA {
18
- public client?: AnalyticsClient;
19
- private plugins: Plugins = new Plugins();
20
- private params: {[name: string]: string} = {};
21
-
22
- // init initializes a new SimpleAPI client.
23
- // @param token is your coveo access_token / api_key / ...
24
- // @param endpoint is the endpoint you want to target defaults to the
25
- // usage analytics production endpoint
26
- init(token: string | AnalyticsClient, optionsOrEndpoint: string | CoveoUAOptions): void {
27
- if (!token) {
28
- throw new Error(`You must pass your token when you call 'init'`);
29
- }
30
-
31
- if (typeof token === 'string') {
32
- this.client = new CoveoAnalyticsClient({
33
- token: token,
34
- endpoint: this.getEndpoint(optionsOrEndpoint),
35
- isCustomEndpoint: this.getIsCustomEndpoint(optionsOrEndpoint),
36
- });
37
- } else if (this.isAnalyticsClient(token)) {
38
- this.client = token;
39
- }
40
-
41
- if (this.client) {
42
- const pluginOptions: PluginOptions = {client: this.client};
43
- this.plugins.clearRequired();
44
- this.getPluginKeys(optionsOrEndpoint).forEach((pluginKey) =>
45
- this.plugins.require(pluginKey, pluginOptions),
46
- );
47
- this.client.registerBeforeSendEventHook((eventType, payload) => ({
48
- ...payload,
49
- ...this.params,
50
- }));
51
- } else {
52
- throw new Error(`You must pass either your token or a valid object when you call 'init'`);
53
- }
18
+ public client?: AnalyticsClient;
19
+ private plugins: Plugins = new Plugins();
20
+ private params: {[name: string]: string} = {};
21
+
22
+ // init initializes a new SimpleAPI client.
23
+ // @param token is your coveo access_token / api_key / ...
24
+ // @param endpoint is the endpoint you want to target defaults to the
25
+ // usage analytics production endpoint
26
+ init(token: string | AnalyticsClient, optionsOrEndpoint: string | CoveoUAOptions): void {
27
+ if (!token) {
28
+ throw new Error(`You must pass your token when you call 'init'`);
54
29
  }
55
30
 
56
- private isAnalyticsClient(token: AnalyticsClient): token is AnalyticsClient {
57
- return typeof token === 'object' && typeof token.sendEvent !== 'undefined';
31
+ if (typeof token === 'string') {
32
+ this.client = new CoveoAnalyticsClient({
33
+ token: token,
34
+ endpoint: this.getEndpoint(optionsOrEndpoint),
35
+ isCustomEndpoint: this.getIsCustomEndpoint(optionsOrEndpoint),
36
+ });
37
+ } else if (this.isAnalyticsClient(token)) {
38
+ this.client = token;
58
39
  }
59
40
 
60
- private getPluginKeys(optionsOrEndpoint: string | CoveoUAOptions): string[] {
61
- if (typeof optionsOrEndpoint === 'string') {
62
- return Plugins.DefaultPlugins;
63
- }
64
- return Array.isArray(optionsOrEndpoint?.plugins) ? optionsOrEndpoint.plugins : Plugins.DefaultPlugins;
41
+ if (this.client) {
42
+ const pluginOptions: PluginOptions = {client: this.client};
43
+ this.plugins.clearRequired();
44
+ this.getPluginKeys(optionsOrEndpoint).forEach((pluginKey) =>
45
+ this.plugins.require(pluginKey, pluginOptions)
46
+ );
47
+ this.client.registerBeforeSendEventHook((eventType, payload) => ({
48
+ ...payload,
49
+ ...this.params,
50
+ }));
51
+ } else {
52
+ throw new Error(`You must pass either your token or a valid object when you call 'init'`);
65
53
  }
54
+ }
66
55
 
67
- private getEndpoint(optionsOrEndpoint: string | CoveoUAOptions) {
68
- if (typeof optionsOrEndpoint === 'string') {
69
- return optionsOrEndpoint || Endpoints.default;
70
- } else if (optionsOrEndpoint?.endpoint) {
71
- return optionsOrEndpoint.endpoint;
72
- }
73
- return Endpoints.default;
74
- }
56
+ private isAnalyticsClient(token: AnalyticsClient): token is AnalyticsClient {
57
+ return typeof token === 'object' && typeof token.sendEvent !== 'undefined';
58
+ }
75
59
 
76
- private getIsCustomEndpoint(optionsOrEndpoint: string | CoveoUAOptions) {
77
- if (typeof optionsOrEndpoint === 'string') {
78
- return false;
79
- } else if (optionsOrEndpoint?.isCustomEndpoint) {
80
- return optionsOrEndpoint.isCustomEndpoint;
81
- }
82
- return false;
60
+ private getPluginKeys(optionsOrEndpoint: string | CoveoUAOptions): string[] {
61
+ if (typeof optionsOrEndpoint === 'string') {
62
+ return Plugins.DefaultPlugins;
83
63
  }
84
-
85
- // init initializes a new client intended to be used with a proxy that injects the access token.
86
- // @param endpoint is the endpoint of your proxy.
87
- initForProxy(endpoint: string, isCustomEndpoint = false): void {
88
- if (!endpoint) {
89
- throw new Error(`You must pass your endpoint when you call 'initForProxy'`);
90
- }
91
-
92
- if (typeof endpoint !== 'string') {
93
- throw new Error(`You must pass a string as the endpoint parameter when you call 'initForProxy'`);
94
- }
95
-
96
- this.client = new CoveoAnalyticsClient({
97
- endpoint: endpoint,
98
- isCustomEndpoint: isCustomEndpoint,
99
- });
64
+ return Array.isArray(optionsOrEndpoint?.plugins)
65
+ ? optionsOrEndpoint.plugins
66
+ : Plugins.DefaultPlugins;
67
+ }
68
+
69
+ private getEndpoint(optionsOrEndpoint: string | CoveoUAOptions) {
70
+ if (typeof optionsOrEndpoint === 'string') {
71
+ return optionsOrEndpoint || Endpoints.default;
72
+ } else if (optionsOrEndpoint?.endpoint) {
73
+ return optionsOrEndpoint.endpoint;
100
74
  }
101
-
102
- set(keyOrObject: string | any, value: string): void {
103
- if (typeof keyOrObject === 'string') {
104
- this.params[keyOrObject] = value;
105
- } else {
106
- Object.keys(keyOrObject).map((key) => {
107
- this.params[key] = keyOrObject[key];
108
- });
109
- }
75
+ return Endpoints.default;
76
+ }
77
+
78
+ private getIsCustomEndpoint(optionsOrEndpoint: string | CoveoUAOptions) {
79
+ if (typeof optionsOrEndpoint === 'string') {
80
+ return false;
81
+ } else if (optionsOrEndpoint?.isCustomEndpoint) {
82
+ return optionsOrEndpoint.isCustomEndpoint;
83
+ }
84
+ return false;
85
+ }
86
+
87
+ // init initializes a new client intended to be used with a proxy that injects the access token.
88
+ // @param endpoint is the endpoint of your proxy.
89
+ initForProxy(endpoint: string, isCustomEndpoint = false): void {
90
+ if (!endpoint) {
91
+ throw new Error(`You must pass your endpoint when you call 'initForProxy'`);
110
92
  }
111
93
 
112
- send(...[event, ...payload]: SendEventArguments): Promise<AnyEventResponse | void> {
113
- if (typeof this.client == 'undefined') {
114
- throw new Error(`You must call init before sending an event`);
115
- }
116
-
117
- if (!event) {
118
- throw new Error(`You must provide an event type when calling "send".`);
119
- }
120
-
121
- return this.client.sendEvent(event.toLowerCase(), ...(payload as VariableArgumentsPayload));
94
+ if (typeof endpoint !== 'string') {
95
+ throw new Error(
96
+ `You must pass a string as the endpoint parameter when you call 'initForProxy'`
97
+ );
122
98
  }
123
99
 
124
- onLoad(callback: Function) {
125
- if (typeof callback == 'undefined') {
126
- throw new Error(`You must pass a function when you call 'onLoad'`);
127
- }
100
+ this.client = new CoveoAnalyticsClient({
101
+ endpoint: endpoint,
102
+ isCustomEndpoint: isCustomEndpoint,
103
+ });
104
+ }
128
105
 
129
- callback();
106
+ set(keyOrObject: string | any, value: string): void {
107
+ if (typeof keyOrObject === 'string') {
108
+ this.params[keyOrObject] = value;
109
+ } else {
110
+ Object.keys(keyOrObject).map((key) => {
111
+ this.params[key] = keyOrObject[key];
112
+ });
130
113
  }
114
+ }
131
115
 
132
- provide(name: string, plugin: PluginClass) {
133
- this.plugins.provide(name, plugin);
116
+ send(...[event, ...payload]: SendEventArguments): Promise<AnyEventResponse | void> {
117
+ if (typeof this.client == 'undefined') {
118
+ throw new Error(`You must call init before sending an event`);
134
119
  }
135
120
 
136
- require(name: string, options: Omit<PluginOptions, 'client'>) {
137
- if (!this.client) {
138
- throw new Error(`You must call init before requiring a plugin`);
139
- }
140
- this.plugins.require(name, {...options, client: this.client});
121
+ if (!event) {
122
+ throw new Error(`You must provide an event type when calling "send".`);
141
123
  }
142
124
 
143
- callPlugin(pluginName: string, fn: string, ...args: any): any {
144
- if (!this.client) {
145
- throw new Error(`You must call init before calling a plugin function`);
146
- }
147
- return this.plugins.execute(pluginName, fn, ...args);
125
+ return this.client.sendEvent(event.toLowerCase(), ...(payload as VariableArgumentsPayload));
126
+ }
127
+
128
+ onLoad(callback: Function) {
129
+ if (typeof callback == 'undefined') {
130
+ throw new Error(`You must pass a function when you call 'onLoad'`);
148
131
  }
149
132
 
150
- reset() {
151
- this.client = undefined;
152
- this.plugins = new Plugins();
153
- this.params = {};
133
+ callback();
134
+ }
135
+
136
+ provide(name: string, plugin: PluginClass) {
137
+ this.plugins.provide(name, plugin);
138
+ }
139
+
140
+ require(name: string, options: Omit<PluginOptions, 'client'>) {
141
+ if (!this.client) {
142
+ throw new Error(`You must call init before requiring a plugin`);
154
143
  }
144
+ this.plugins.require(name, {...options, client: this.client});
145
+ }
155
146
 
156
- version(): string {
157
- return libVersion;
147
+ callPlugin(pluginName: string, fn: string, ...args: any): any {
148
+ if (!this.client) {
149
+ throw new Error(`You must call init before calling a plugin function`);
158
150
  }
151
+ return this.plugins.execute(pluginName, fn, ...args);
152
+ }
153
+
154
+ reset() {
155
+ this.client = undefined;
156
+ this.plugins = new Plugins();
157
+ this.params = {};
158
+ }
159
+
160
+ version(): string {
161
+ return libVersion;
162
+ }
159
163
  }
160
164
 
161
165
  export const coveoua = new CoveoUA();
162
166
  export const getCurrentClient = () => coveoua.client;
163
167
 
164
168
  export const handleOneAnalyticsEvent = (command: string, ...params: any[]) => {
165
- const [, trackerName, pluginName, fn] = /^(?:(\w+)\.)?(?:(\w+):)?(\w+)$/.exec(command)!;
166
-
167
- const actionFunction = (<any>coveoua)[fn];
168
- if (pluginName && fn) {
169
- return coveoua.callPlugin(pluginName as string, fn, ...params);
170
- } else if (actionFunction) {
171
- return actionFunction.apply(coveoua, params);
172
- } else {
173
- const actions: AvailableActions[] = [
174
- 'init',
175
- 'set',
176
- 'send',
177
- 'onLoad',
178
- 'callPlugin',
179
- 'reset',
180
- 'require',
181
- 'provide',
182
- 'version',
183
- ];
184
- throw new Error(`The action "${command}" does not exist. Available actions: ${actions.join(', ')}.`);
185
- }
169
+ const [, trackerName, pluginName, fn] = /^(?:(\w+)\.)?(?:(\w+):)?(\w+)$/.exec(command)!;
170
+
171
+ const actionFunction = (<any>coveoua)[fn];
172
+ if (pluginName && fn) {
173
+ return coveoua.callPlugin(pluginName as string, fn, ...params);
174
+ } else if (actionFunction) {
175
+ return actionFunction.apply(coveoua, params);
176
+ } else {
177
+ const actions: AvailableActions[] = [
178
+ 'init',
179
+ 'set',
180
+ 'send',
181
+ 'onLoad',
182
+ 'callPlugin',
183
+ 'reset',
184
+ 'require',
185
+ 'provide',
186
+ 'version',
187
+ ];
188
+ throw new Error(
189
+ `The action "${command}" does not exist. Available actions: ${actions.join(', ')}.`
190
+ );
191
+ }
186
192
  };
187
193
 
188
194
  export default handleOneAnalyticsEvent;
package/src/detector.ts CHANGED
@@ -1,43 +1,43 @@
1
1
  export function hasWindow(): boolean {
2
- return typeof window !== 'undefined';
2
+ return typeof window !== 'undefined';
3
3
  }
4
4
 
5
5
  export function hasNavigator(): boolean {
6
- return typeof navigator !== 'undefined';
6
+ return typeof navigator !== 'undefined';
7
7
  }
8
8
 
9
9
  export function hasDocument(): boolean {
10
- return typeof document !== 'undefined';
10
+ return typeof document !== 'undefined';
11
11
  }
12
12
 
13
13
  export function hasLocalStorage(): boolean {
14
- try {
15
- return typeof localStorage !== 'undefined';
16
- } catch (error) {
17
- return false;
18
- }
14
+ try {
15
+ return typeof localStorage !== 'undefined';
16
+ } catch (error) {
17
+ return false;
18
+ }
19
19
  }
20
20
 
21
21
  export function hasSessionStorage(): boolean {
22
- try {
23
- return typeof sessionStorage !== 'undefined';
24
- } catch (error) {
25
- return false;
26
- }
22
+ try {
23
+ return typeof sessionStorage !== 'undefined';
24
+ } catch (error) {
25
+ return false;
26
+ }
27
27
  }
28
28
 
29
29
  export function hasCookieStorage(): boolean {
30
- return hasNavigator() && navigator.cookieEnabled;
30
+ return hasNavigator() && navigator.cookieEnabled;
31
31
  }
32
32
 
33
33
  export function hasCrypto(): boolean {
34
- return typeof crypto !== 'undefined';
34
+ return typeof crypto !== 'undefined';
35
35
  }
36
36
 
37
37
  export function hasCryptoRandomValues(): boolean {
38
- return hasCrypto() && typeof crypto.getRandomValues !== 'undefined';
38
+ return hasCrypto() && typeof crypto.getRandomValues !== 'undefined';
39
39
  }
40
40
 
41
41
  export function hasLocation(): boolean {
42
- return typeof location !== 'undefined';
42
+ return typeof location !== 'undefined';
43
43
  }