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
@@ -1,84 +1,85 @@
1
1
  import {
2
- CategoryFacetMetadata,
3
- FacetBaseMeta,
4
- FacetMetadata,
5
- FacetRangeMetadata,
6
- FacetSortMeta,
7
- InterfaceChangeMetadata,
8
- PagerMetadata,
9
- QueryErrorMeta,
10
- ResultsSortMetadata,
11
- StaticFilterToggleValueMetadata,
2
+ CategoryFacetMetadata,
3
+ FacetBaseMeta,
4
+ FacetMetadata,
5
+ FacetRangeMetadata,
6
+ FacetSortMeta,
7
+ InterfaceChangeMetadata,
8
+ PagerMetadata,
9
+ QueryErrorMeta,
10
+ ResultsSortMetadata,
11
+ StaticFilterToggleValueMetadata,
12
12
  } from '../searchPage/searchPageEvents';
13
13
 
14
14
  export enum InsightEvents {
15
- /**
16
- * Identifies the search event that gets logged when the query context is updated as a result of updating one of the case context fields.
17
- */
18
- contextChanged = 'contextChanged',
19
- /**
20
- * Identifies the event that gets logged when the user opens the full search page from the insight panel.
21
- */
22
- expandToFullUI = 'expandToFullUI',
23
- /**
24
- * Identifies the event that gets logged when the user opens the user actions section.
25
- */
26
- openUserActions = 'openUserActions',
27
- /**
28
- * Identifies the event that gets logged when the user clicks to view user action sessions preceding the ticket creation.
29
- */
30
- showPrecedingSessions = 'showPrecedingSessions',
31
- /**
32
- * Identifies the event that gets logged when the user clicks to view user action sessions following the ticket creation.
33
- */
34
- showFollowingSessions = 'showFollowingSessions',
35
- /**
36
- * Identifies the event that gets logged when the user clicks a viewed document link on the user actions timeline.
37
- */
38
- clickViewedDocument = 'clickViewedDocument',
39
- /**
40
- * Identifies the event that gets logged when the user clicks a viewed page link on the user actions timeline.
41
- */
42
- clickPageView = 'clickPageView',
43
- /**
44
- * Identifies the event that gets logged when the user clicks the create article button.
45
- */
46
- createArticle = 'createArticle',
15
+ /**
16
+ * Identifies the search event that gets logged when the query context is updated as a result of updating one of the case context fields.
17
+ */
18
+ contextChanged = 'contextChanged',
19
+ /**
20
+ * Identifies the event that gets logged when the user opens the full search page from the insight panel.
21
+ */
22
+ expandToFullUI = 'expandToFullUI',
23
+ /**
24
+ * Identifies the event that gets logged when the user opens the user actions section.
25
+ */
26
+ openUserActions = 'openUserActions',
27
+ /**
28
+ * Identifies the event that gets logged when the user clicks to view user action sessions preceding the ticket creation.
29
+ */
30
+ showPrecedingSessions = 'showPrecedingSessions',
31
+ /**
32
+ * Identifies the event that gets logged when the user clicks to view user action sessions following the ticket creation.
33
+ */
34
+ showFollowingSessions = 'showFollowingSessions',
35
+ /**
36
+ * Identifies the event that gets logged when the user clicks a viewed document link on the user actions timeline.
37
+ */
38
+ clickViewedDocument = 'clickViewedDocument',
39
+ /**
40
+ * Identifies the event that gets logged when the user clicks a viewed page link on the user actions timeline.
41
+ */
42
+ clickPageView = 'clickPageView',
43
+ /**
44
+ * Identifies the event that gets logged when the user clicks the create article button.
45
+ */
46
+ createArticle = 'createArticle',
47
47
  }
48
48
 
49
49
  export interface CaseMetadata {
50
- caseId?: string;
51
- caseNumber?: string;
52
- caseContext?: Record<string, string>;
50
+ caseId?: string;
51
+ caseNumber?: string;
52
+ caseContext?: Record<string, string>;
53
53
  }
54
54
 
55
55
  export interface ExpandToFullUIMetadata extends CaseMetadata {
56
- fullSearchComponentName: string;
57
- triggeredBy: string;
56
+ fullSearchComponentName: string;
57
+ triggeredBy: string;
58
58
  }
59
59
 
60
60
  export interface UserActionsDocumentMetadata {
61
- title: string;
62
- uri: string;
63
- uriHash?: string;
64
- permanentId?: string;
61
+ title: string;
62
+ uri: string;
63
+ uriHash?: string;
64
+ permanentId?: string;
65
65
  }
66
66
 
67
67
  export interface UserActionsPageViewMetadata {
68
- title: string;
69
- contentIdKey: string;
70
- contentIdValue: string;
68
+ title: string;
69
+ contentIdKey: string;
70
+ contentIdValue: string;
71
71
  }
72
72
 
73
73
  export interface CreateArticleMetadata {
74
- articleType: string;
74
+ articleType: string;
75
75
  }
76
76
 
77
77
  export interface InsightInterfaceChangeMetadata extends InterfaceChangeMetadata, CaseMetadata {}
78
78
 
79
79
  export interface InsightFacetMetadata extends FacetMetadata, CaseMetadata {}
80
80
 
81
- export interface InsightStaticFilterToggleValueMetadata extends StaticFilterToggleValueMetadata, CaseMetadata {}
81
+ export interface InsightStaticFilterToggleValueMetadata
82
+ extends StaticFilterToggleValueMetadata, CaseMetadata {}
82
83
 
83
84
  export interface InsightFacetRangeMetadata extends FacetRangeMetadata, CaseMetadata {}
84
85
 
@@ -4,148 +4,152 @@ import {getFormattedLocation} from '../client/location';
4
4
  import {hasDocument} from '../detector';
5
5
 
6
6
  type PluginWithId = {
7
- readonly Id: string;
7
+ readonly Id: string;
8
8
  };
9
9
 
10
10
  export type PluginClass = typeof Plugin & PluginWithId;
11
11
  export const BasePluginEventTypes = {
12
- pageview: 'pageview',
13
- event: 'event',
12
+ pageview: 'pageview',
13
+ event: 'event',
14
14
  };
15
15
 
16
- export type PluginOptions = {client: AnalyticsClient; uuidGenerator?: typeof uuidv4};
16
+ export type PluginOptions = {
17
+ client: AnalyticsClient;
18
+ uuidGenerator?: typeof uuidv4;
19
+ };
17
20
 
18
21
  export abstract class Plugin {
19
- protected client: AnalyticsClient;
20
- protected uuidGenerator: typeof uuidv4;
21
- constructor({client, uuidGenerator = uuidv4}: PluginOptions) {
22
- this.client = client;
23
- this.uuidGenerator = uuidGenerator;
24
- }
25
- public abstract getApi(name: string): any;
22
+ protected client: AnalyticsClient;
23
+ protected uuidGenerator: typeof uuidv4;
24
+ constructor({client, uuidGenerator = uuidv4}: PluginOptions) {
25
+ this.client = client;
26
+ this.uuidGenerator = uuidGenerator;
27
+ }
28
+ public abstract getApi(name: string): any;
26
29
  }
27
30
 
28
31
  export abstract class BasePlugin extends Plugin {
29
- protected action?: string;
30
- protected actionData: {[name: string]: string} = {};
31
- private pageViewId: string;
32
- private nextPageViewId: string;
33
- private hasSentFirstPageView?: boolean;
34
- private currentLocation: string;
35
- private lastReferrer: string;
36
-
37
- constructor({client, uuidGenerator = uuidv4}: PluginOptions) {
38
- super({client, uuidGenerator});
39
- this.pageViewId = uuidGenerator();
40
- this.nextPageViewId = this.pageViewId;
41
- this.currentLocation = getFormattedLocation(window.location);
42
- this.lastReferrer = hasDocument() ? document.referrer : '';
43
-
44
- this.addHooks();
45
- }
46
- protected abstract addHooks(): void;
47
- protected abstract clearPluginData(): void;
48
-
49
- public getApi(name: string): Function | null {
50
- switch (name) {
51
- case 'setAction':
52
- return this.setAction;
53
- default:
54
- return null;
55
- }
56
- }
57
-
58
- public setAction(action: string, options?: any) {
59
- this.action = action;
60
- this.actionData = options;
61
- }
62
-
63
- public clearData() {
64
- this.clearPluginData();
65
- this.action = undefined;
66
- this.actionData = {};
67
- }
68
-
69
- public getLocationInformation(eventType: string, payload: any) {
70
- return {
71
- hitType: eventType,
72
- ...this.getNextValues(eventType, payload),
73
- };
74
- }
75
-
76
- protected updateLocationInformation(eventType: string, payload: any) {
77
- this.updateLocationForNextPageView(eventType, payload);
78
- }
79
-
80
- public getDefaultContextInformation(eventType: string) {
81
- const documentContext = {
82
- title: hasDocument() ? document.title : '',
83
- encoding: hasDocument() ? document.characterSet : 'UTF-8',
84
- };
85
- const screenContext = {
86
- screenResolution: `${screen.width}x${screen.height}`,
87
- screenColor: `${screen.colorDepth}-bit`,
88
- };
89
- const navigatorContext = {
90
- language: navigator.language,
91
- userAgent: navigator.userAgent,
92
- };
93
- const eventContext = {
94
- time: Date.now(),
95
- eventId: this.uuidGenerator(),
96
- };
97
- return {
98
- ...eventContext,
99
- ...screenContext,
100
- ...navigatorContext,
101
- ...documentContext,
102
- };
32
+ protected action?: string;
33
+ protected actionData: {[name: string]: string} = {};
34
+ private pageViewId: string;
35
+ private nextPageViewId: string;
36
+ private hasSentFirstPageView?: boolean;
37
+ private currentLocation: string;
38
+ private lastReferrer: string;
39
+
40
+ constructor({client, uuidGenerator = uuidv4}: PluginOptions) {
41
+ super({client, uuidGenerator});
42
+ this.pageViewId = uuidGenerator();
43
+ this.nextPageViewId = this.pageViewId;
44
+ this.currentLocation = getFormattedLocation(window.location);
45
+ this.lastReferrer = hasDocument() ? document.referrer : '';
46
+
47
+ this.addHooks();
48
+ }
49
+ protected abstract addHooks(): void;
50
+ protected abstract clearPluginData(): void;
51
+
52
+ public getApi(name: string): Function | null {
53
+ switch (name) {
54
+ case 'setAction':
55
+ return this.setAction;
56
+ default:
57
+ return null;
103
58
  }
104
-
105
- private updateLocationForNextPageView(eventType: string, payload: any) {
106
- const {pageViewId, referrer, location} = this.getNextValues(eventType, payload);
107
-
108
- this.lastReferrer = referrer;
109
- this.pageViewId = pageViewId;
110
- this.currentLocation = location;
111
-
112
- if (eventType === BasePluginEventTypes.pageview) {
113
- this.nextPageViewId = this.uuidGenerator();
114
- this.hasSentFirstPageView = true;
115
- }
59
+ }
60
+
61
+ public setAction(action: string, options?: any) {
62
+ this.action = action;
63
+ this.actionData = options;
64
+ }
65
+
66
+ public clearData() {
67
+ this.clearPluginData();
68
+ this.action = undefined;
69
+ this.actionData = {};
70
+ }
71
+
72
+ public getLocationInformation(eventType: string, payload: any) {
73
+ return {
74
+ hitType: eventType,
75
+ ...this.getNextValues(eventType, payload),
76
+ };
77
+ }
78
+
79
+ protected updateLocationInformation(eventType: string, payload: any) {
80
+ this.updateLocationForNextPageView(eventType, payload);
81
+ }
82
+
83
+ public getDefaultContextInformation(eventType: string) {
84
+ const documentContext = {
85
+ title: hasDocument() ? document.title : '',
86
+ encoding: hasDocument() ? document.characterSet : 'UTF-8',
87
+ };
88
+ const screenContext = {
89
+ screenResolution: `${screen.width}x${screen.height}`,
90
+ screenColor: `${screen.colorDepth}-bit`,
91
+ };
92
+ const navigatorContext = {
93
+ language: navigator.language,
94
+ userAgent: navigator.userAgent,
95
+ };
96
+ const eventContext = {
97
+ time: Date.now(),
98
+ eventId: this.uuidGenerator(),
99
+ };
100
+ return {
101
+ ...eventContext,
102
+ ...screenContext,
103
+ ...navigatorContext,
104
+ ...documentContext,
105
+ };
106
+ }
107
+
108
+ private updateLocationForNextPageView(eventType: string, payload: any) {
109
+ const {pageViewId, referrer, location} = this.getNextValues(eventType, payload);
110
+
111
+ this.lastReferrer = referrer;
112
+ this.pageViewId = pageViewId;
113
+ this.currentLocation = location;
114
+
115
+ if (eventType === BasePluginEventTypes.pageview) {
116
+ this.nextPageViewId = this.uuidGenerator();
117
+ this.hasSentFirstPageView = true;
116
118
  }
119
+ }
117
120
 
118
- /*
121
+ /*
119
122
  When calling getPayload or getParameters, we need to return what would be sent by the API without updating our internal reference.
120
123
  For instance, if you getPayload("pageview"), we want to return the same payload as if you did coveoua("send", "pageview").
121
124
  */
122
- private getNextValues(eventType: string, payload: any) {
123
- /*
125
+ private getNextValues(eventType: string, payload: any) {
126
+ /*
124
127
  When sending a pageview, we need to generate a new pageview ID.
125
128
  For instance, with the following sequence: 1. pageview, 2. event, 3. pageview, 4. event, 1 and 2 will have the pageviewid, whereas 3 and 4 will have a different pageviewid.
126
129
  We pre-generate the "nextPageViewId" in case you send the following sequence: 1. pageview, 2. event, 3. getPayload, 4. pageview. This ensures that 3 and 4 have the same pageviewid.
127
130
  We applied the same logic to the referrer and the location.
128
131
  */
129
- return {
130
- pageViewId: eventType === BasePluginEventTypes.pageview ? this.nextPageViewId : this.pageViewId,
131
- referrer:
132
- eventType === BasePluginEventTypes.pageview && this.hasSentFirstPageView
133
- ? this.currentLocation
134
- : this.lastReferrer,
135
- location:
136
- eventType === BasePluginEventTypes.pageview
137
- ? this.getCurrentLocationFromPayload(payload)
138
- : this.currentLocation,
139
- };
140
- }
141
-
142
- private getCurrentLocationFromPayload(payload: any) {
143
- if (!!payload.page) {
144
- const removeStartingSlash = (page: string) => page.replace(/^\/?(.*)$/, '/$1');
145
- const extractHostnamePart = (location: string) => location.split('/').slice(0, 3).join('/');
146
- return `${extractHostnamePart(this.currentLocation)}${removeStartingSlash(payload.page)}`;
147
- } else {
148
- return getFormattedLocation(window.location);
149
- }
132
+ return {
133
+ pageViewId:
134
+ eventType === BasePluginEventTypes.pageview ? this.nextPageViewId : this.pageViewId,
135
+ referrer:
136
+ eventType === BasePluginEventTypes.pageview && this.hasSentFirstPageView
137
+ ? this.currentLocation
138
+ : this.lastReferrer,
139
+ location:
140
+ eventType === BasePluginEventTypes.pageview
141
+ ? this.getCurrentLocationFromPayload(payload)
142
+ : this.currentLocation,
143
+ };
144
+ }
145
+
146
+ private getCurrentLocationFromPayload(payload: any) {
147
+ if (payload.page) {
148
+ const removeStartingSlash = (page: string) => page.replace(/^\/?(.*)$/, '/$1');
149
+ const extractHostnamePart = (location: string) => location.split('/').slice(0, 3).join('/');
150
+ return `${extractHostnamePart(this.currentLocation)}${removeStartingSlash(payload.page)}`;
151
+ } else {
152
+ return getFormattedLocation(window.location);
150
153
  }
154
+ }
151
155
  }