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
@@ -2,69 +2,69 @@ import {CookieStorage, CookieAndLocalStorage} from './storage';
2
2
  import {Cookie} from './cookieutils';
3
3
 
4
4
  describe('CookieStorage', () => {
5
- const key = 'wow';
6
- const someData = 'something';
5
+ const key = 'wow';
6
+ const someData = 'something';
7
7
 
8
- it('setItem writes data to a cookie', () => {
9
- const storage = new CookieStorage();
10
- storage.setItem(key, someData);
11
- expect(storage.getItem(key)).toBe(someData);
12
- });
8
+ it('setItem writes data to a cookie', () => {
9
+ const storage = new CookieStorage();
10
+ storage.setItem(key, someData);
11
+ expect(storage.getItem(key)).toBe(someData);
12
+ });
13
13
 
14
- it('removeItem removes the cookie', () => {
15
- const storage = new CookieStorage();
16
- storage.setItem(key, someData);
17
- storage.removeItem(key);
18
- expect(storage.getItem(key)).toBe(null);
19
- });
14
+ it('removeItem removes the cookie', () => {
15
+ const storage = new CookieStorage();
16
+ storage.setItem(key, someData);
17
+ storage.removeItem(key);
18
+ expect(storage.getItem(key)).toBe(null);
19
+ });
20
20
 
21
- it('honors expiration date', async () => {
22
- const storage = new CookieStorage();
23
- storage.setItem(key, someData, 1000);
24
- await new Promise((res) => setTimeout(res, 1000)); // wait for 1 sec
25
- expect(storage.getItem(key)).toBe(null);
26
- });
21
+ it('honors expiration date', async () => {
22
+ const storage = new CookieStorage();
23
+ storage.setItem(key, someData, 1000);
24
+ await new Promise((res) => setTimeout(res, 1000)); // wait for 1 sec
25
+ expect(storage.getItem(key)).toBe(null);
26
+ });
27
27
  });
28
28
 
29
29
  describe('CookieAndLocalStorage', () => {
30
- const key = 'hello';
31
- const someData = 'world';
32
- let storage: CookieAndLocalStorage;
33
- let cookie: CookieStorage;
30
+ const key = 'hello';
31
+ const someData = 'world';
32
+ let storage: CookieAndLocalStorage;
33
+ let cookie: CookieStorage;
34
34
 
35
- beforeEach(() => {
36
- storage = new CookieAndLocalStorage();
37
- cookie = new CookieStorage();
38
- });
35
+ beforeEach(() => {
36
+ storage = new CookieAndLocalStorage();
37
+ cookie = new CookieStorage();
38
+ });
39
39
 
40
- it('setItem writes data to a cookie and local storage', () => {
41
- storage.setItem(key, someData);
42
- expect(cookie.getItem(key)).toBe(someData);
43
- expect(localStorage.getItem(key)).toBe(someData);
44
- });
40
+ it('setItem writes data to a cookie and local storage', () => {
41
+ storage.setItem(key, someData);
42
+ expect(cookie.getItem(key)).toBe(someData);
43
+ expect(localStorage.getItem(key)).toBe(someData);
44
+ });
45
45
 
46
- it('removeItem removes the cookie and local storage', () => {
47
- storage.setItem(key, someData);
48
- storage.removeItem(key);
46
+ it('removeItem removes the cookie and local storage', () => {
47
+ storage.setItem(key, someData);
48
+ storage.removeItem(key);
49
49
 
50
- expect(storage.getItem(key)).toBe(null);
51
- expect(cookie.getItem(key)).toBe(null);
52
- expect(localStorage.getItem(key)).toBe(null);
53
- });
50
+ expect(storage.getItem(key)).toBe(null);
51
+ expect(cookie.getItem(key)).toBe(null);
52
+ expect(localStorage.getItem(key)).toBe(null);
53
+ });
54
54
 
55
- it('get item uses local storage first', () => {
56
- cookie.setItem(key, 'fail');
57
- localStorage.setItem(key, someData);
55
+ it('get item uses local storage first', () => {
56
+ cookie.setItem(key, 'fail');
57
+ localStorage.setItem(key, someData);
58
58
 
59
- storage.getItem(key);
60
- expect(storage.getItem(key)).toBe(someData);
61
- });
59
+ storage.getItem(key);
60
+ expect(storage.getItem(key)).toBe(someData);
61
+ });
62
62
 
63
- it('get item fallback on cookie storage if absent from local storage', () => {
64
- localStorage.setItem(key, '');
65
- cookie.setItem(key, someData);
63
+ it('get item fallback on cookie storage if absent from local storage', () => {
64
+ localStorage.setItem(key, '');
65
+ cookie.setItem(key, someData);
66
66
 
67
- storage.getItem(key);
68
- expect(storage.getItem(key)).toBe(someData);
69
- });
67
+ storage.getItem(key);
68
+ expect(storage.getItem(key)).toBe(someData);
69
+ });
70
70
  });
package/src/storage.ts CHANGED
@@ -4,66 +4,66 @@ import {Cookie} from './cookieutils';
4
4
  export let preferredStorage: WebStorage | null = null;
5
5
 
6
6
  export interface WebStorage {
7
- getItem(key: string): string | null | Promise<string | null>;
8
- removeItem(key: string): void;
9
- setItem(key: string, data: string): void | Promise<void>;
7
+ getItem(key: string): string | null | Promise<string | null>;
8
+ removeItem(key: string): void;
9
+ setItem(key: string, data: string): void | Promise<void>;
10
10
  }
11
11
 
12
12
  export function getAvailableStorage(): WebStorage {
13
- if (preferredStorage) {
14
- return preferredStorage;
15
- }
16
- if (detector.hasLocalStorage()) {
17
- return localStorage;
18
- }
19
- if (detector.hasCookieStorage()) {
20
- return new CookieStorage();
21
- }
22
- if (detector.hasSessionStorage()) {
23
- return sessionStorage;
24
- }
25
- return new NullStorage();
13
+ if (preferredStorage) {
14
+ return preferredStorage;
15
+ }
16
+ if (detector.hasLocalStorage()) {
17
+ return localStorage;
18
+ }
19
+ if (detector.hasCookieStorage()) {
20
+ return new CookieStorage();
21
+ }
22
+ if (detector.hasSessionStorage()) {
23
+ return sessionStorage;
24
+ }
25
+ return new NullStorage();
26
26
  }
27
27
 
28
28
  export class CookieStorage implements WebStorage {
29
- static prefix = 'coveo_';
30
- getItem(key: string): string | null {
31
- return Cookie.get(`${CookieStorage.prefix}${key}`);
32
- }
33
- removeItem(key: string) {
34
- Cookie.erase(`${CookieStorage.prefix}${key}`);
35
- }
36
- setItem(key: string, data: string, expire?: number): void {
37
- Cookie.set(`${CookieStorage.prefix}${key}`, data, expire);
38
- }
29
+ static prefix = 'coveo_';
30
+ getItem(key: string): string | null {
31
+ return Cookie.get(`${CookieStorage.prefix}${key}`);
32
+ }
33
+ removeItem(key: string) {
34
+ Cookie.erase(`${CookieStorage.prefix}${key}`);
35
+ }
36
+ setItem(key: string, data: string, expire?: number): void {
37
+ Cookie.set(`${CookieStorage.prefix}${key}`, data, expire);
38
+ }
39
39
  }
40
40
 
41
41
  export class CookieAndLocalStorage implements WebStorage {
42
- private cookieStorage = new CookieStorage();
42
+ private cookieStorage = new CookieStorage();
43
43
 
44
- getItem(key: string): string | null {
45
- return localStorage.getItem(key) || this.cookieStorage.getItem(key);
46
- }
44
+ getItem(key: string): string | null {
45
+ return localStorage.getItem(key) || this.cookieStorage.getItem(key);
46
+ }
47
47
 
48
- removeItem(key: string): void {
49
- this.cookieStorage.removeItem(key);
50
- localStorage.removeItem(key);
51
- }
48
+ removeItem(key: string): void {
49
+ this.cookieStorage.removeItem(key);
50
+ localStorage.removeItem(key);
51
+ }
52
52
 
53
- setItem(key: string, data: string): void {
54
- localStorage.setItem(key, data);
55
- this.cookieStorage.setItem(key, data, 31556926000); // 1 year first party cookie
56
- }
53
+ setItem(key: string, data: string): void {
54
+ localStorage.setItem(key, data);
55
+ this.cookieStorage.setItem(key, data, 31556926000); // 1 year first party cookie
56
+ }
57
57
  }
58
58
 
59
59
  export class NullStorage implements WebStorage {
60
- getItem(key: string): string | null {
61
- return null;
62
- }
63
- removeItem(key: string) {
64
- /**/
65
- }
66
- setItem(key: string, data: string): void {
67
- /**/
68
- }
60
+ getItem(key: string): string | null {
61
+ return null;
62
+ }
63
+ removeItem(key: string) {
64
+ /**/
65
+ }
66
+ setItem(key: string, data: string): void {
67
+ /**/
68
+ }
69
69
  }
@@ -1 +0,0 @@
1
- export declare const fetch: typeof globalThis.fetch;
@@ -1,6 +0,0 @@
1
- export interface CoveoUAGlobal {
2
- (action: string, ...params: any[]): void;
3
- q?: [string, any[]][];
4
- }
5
- declare const _default: any;
6
- export default _default;
@@ -1,6 +0,0 @@
1
- export { CoveoSearchPageClient, SearchPageClientProvider } from '../searchPage/searchPageClient';
2
- export { CaseAssistClient, CaseAssistClientProvider } from '../caseAssist/caseAssistClient';
3
- export { CoveoInsightClient, InsightClientProvider } from '../insight/insightClient';
4
- export { CoveoAnalyticsClient, AnalyticsClientSendEventHook } from '../client/analytics';
5
- export { PreprocessAnalyticsRequest } from '../client/analyticsRequestClient';
6
- export * as history from '../history';
@@ -1,17 +0,0 @@
1
- import * as analytics from '../client/analytics';
2
- import * as donottrack from '../donottrack';
3
- import * as history from '../history';
4
- import * as SimpleAnalytics from './simpleanalytics';
5
- import * as storage from '../storage';
6
- export { CoveoAnalyticsClient, AnalyticsClientSendEventHook } from '../client/analytics';
7
- export { PreprocessAnalyticsRequest } from '../client/analyticsRequestClient';
8
- export { IRuntimeEnvironment } from '../client/runtimeEnvironment';
9
- export { CoveoUA, getCurrentClient, handleOneAnalyticsEvent } from './simpleanalytics';
10
- export { CoveoSearchPageClient, SearchPageClientProvider, EventDescription, EventBuilder, } from '../searchPage/searchPageClient';
11
- export { CaseAssistClient, CaseAssistClientProvider } from '../caseAssist/caseAssistClient';
12
- export { CoveoInsightClient, InsightClientProvider } from '../insight/insightClient';
13
- export * from '../searchPage/searchPageEvents';
14
- export * from '../caseAssist/caseAssistActions';
15
- export * from '../insight/insightEvents';
16
- export * from '../events';
17
- export { analytics, donottrack, history, SimpleAnalytics, storage };
@@ -1,10 +0,0 @@
1
- import { PluginClass, PluginOptions } from '../plugins/BasePlugin';
2
- export declare class Plugins {
3
- static readonly DefaultPlugins: string[];
4
- private registeredPluginsMap;
5
- private requiredPlugins;
6
- require(name: string, options: PluginOptions): void;
7
- provide(name: string, plugin: PluginClass): void;
8
- clearRequired(): void;
9
- execute(name: string, fn: string, ...args: any[]): any;
10
- }
@@ -1,33 +0,0 @@
1
- import { AnyEventResponse, SendEventArguments } from '../events';
2
- import { AnalyticsClient } from '../client/analytics';
3
- import { PluginOptions } from '../plugins/BasePlugin';
4
- import { PluginClass } from '../plugins/BasePlugin';
5
- export type AvailableActions = keyof CoveoUA;
6
- export interface CoveoUAOptions {
7
- endpoint?: string;
8
- isCustomEndpoint?: boolean;
9
- plugins?: string[];
10
- }
11
- export declare class CoveoUA {
12
- client?: AnalyticsClient;
13
- private plugins;
14
- private params;
15
- init(token: string | AnalyticsClient, optionsOrEndpoint: string | CoveoUAOptions): void;
16
- private isAnalyticsClient;
17
- private getPluginKeys;
18
- private getEndpoint;
19
- private getIsCustomEndpoint;
20
- initForProxy(endpoint: string, isCustomEndpoint?: boolean): void;
21
- set(keyOrObject: string | any, value: string): void;
22
- send(...[event, ...payload]: SendEventArguments): Promise<AnyEventResponse | void>;
23
- onLoad(callback: Function): void;
24
- provide(name: string, plugin: PluginClass): void;
25
- require(name: string, options: Omit<PluginOptions, 'client'>): void;
26
- callPlugin(pluginName: string, fn: string, ...args: any): any;
27
- reset(): void;
28
- version(): string;
29
- }
30
- export declare const coveoua: CoveoUA;
31
- export declare const getCurrentClient: () => AnalyticsClient | undefined;
32
- export declare const handleOneAnalyticsEvent: (command: string, ...params: any[]) => any;
33
- export default handleOneAnalyticsEvent;
@@ -1,3 +0,0 @@
1
- export { ReactNativeRuntime, ReactNativeRuntimeOptions, ReactNativeStorage } from './react-native-runtime';
2
- export * from '../coveoua/headless';
3
- import 'react-native-get-random-values';
@@ -1,19 +0,0 @@
1
- import { WebStorage } from '../storage';
2
- import { AnalyticsFetchClient } from '../client/analyticsFetchClient';
3
- import { IRuntimeEnvironment } from '../client/runtimeEnvironment';
4
- import { PreprocessAnalyticsRequest } from '../client/analyticsRequestClient';
5
- export type ReactNativeStorage = WebStorage;
6
- export interface ReactNativeRuntimeOptions {
7
- storage: ReactNativeStorage;
8
- visitorIdKey?: string;
9
- token?: string;
10
- version?: string;
11
- endpoint?: string;
12
- preprocessRequest?: PreprocessAnalyticsRequest;
13
- }
14
- export declare class ReactNativeRuntime implements IRuntimeEnvironment {
15
- client: AnalyticsFetchClient;
16
- storage: ReactNativeStorage;
17
- constructor(options: ReactNativeRuntimeOptions);
18
- getClientDependingOnEventType(): AnalyticsFetchClient;
19
- }