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.
- package/README.md +37 -43
- package/dist/browser.mjs +513 -357
- package/dist/coveoua.browser.js +1 -1
- package/dist/coveoua.browser.js.map +1 -1
- package/dist/coveoua.debug.js +542 -359
- package/dist/coveoua.debug.js.map +1 -1
- package/dist/coveoua.js +1 -1
- package/dist/coveoua.js.map +1 -1
- package/dist/definitions/client/analytics.d.ts +3 -2
- package/dist/definitions/client/runtimeEnvironment.d.ts +1 -1
- package/dist/definitions/donottrack.d.ts +1 -0
- package/dist/definitions/react-native/index.d.ts +1 -2
- package/dist/definitions/version.d.ts +1 -1
- package/dist/library.cjs +15350 -3699
- package/dist/library.es.js +513 -357
- package/dist/library.js +15350 -3699
- package/dist/library.mjs +15350 -3699
- package/dist/react-native.es.js +634 -460
- package/modules/package.json +9 -9
- package/package.json +60 -91
- package/react-native/package.json +7 -7
- package/src/caseAssist/caseAssistActions.ts +51 -50
- package/src/caseAssist/caseAssistClient.spec.ts +328 -297
- package/src/caseAssist/caseAssistClient.ts +201 -185
- package/src/client/analytics.spec.ts +724 -703
- package/src/client/analytics.ts +677 -602
- package/src/client/analyticsBeaconClient.spec.ts +195 -188
- package/src/client/analyticsBeaconClient.ts +99 -88
- package/src/client/analyticsFetchClient.ts +77 -61
- package/src/client/analyticsRequestClient.ts +17 -17
- package/src/client/location.ts +3 -3
- package/src/client/measurementProtocolMapper.ts +54 -45
- package/src/client/measurementProtocolMapping/baseMeasurementProtocolMapper.ts +48 -44
- package/src/client/measurementProtocolMapping/commerceMeasurementProtocolMapper.ts +133 -121
- package/src/client/measurementProtocolMapping/serviceMeasurementProtocolMapper.ts +17 -17
- package/src/client/noopAnalytics.ts +80 -68
- package/src/client/runtimeEnvironment.ts +50 -41
- package/src/client/utils.spec.ts +112 -97
- package/src/client/utils.ts +39 -39
- package/src/cookieutils.spec.ts +59 -0
- package/src/cookieutils.ts +40 -39
- package/src/coveoua/browser.ts +14 -12
- package/src/coveoua/library.ts +4 -4
- package/src/coveoua/plugins.ts +36 -34
- package/src/coveoua/simpleanalytics.spec.ts +467 -452
- package/src/coveoua/simpleanalytics.ts +146 -140
- package/src/detector.ts +17 -17
- package/src/donottrack.spec.ts +199 -121
- package/src/donottrack.ts +31 -8
- package/src/events.ts +86 -79
- package/src/formatting/format-array-for-coveo-custom-data.spec.ts +13 -12
- package/src/formatting/format-array-for-coveo-custom-data.ts +18 -18
- package/src/formatting/format-omnibox-metadata.ts +16 -12
- package/src/history.spec.ts +197 -195
- package/src/history.ts +143 -133
- package/src/hook/addDefaultValues.ts +13 -8
- package/src/hook/enhanceViewEvent.ts +17 -17
- package/src/insight/insightClient.spec.ts +1848 -1717
- package/src/insight/insightClient.ts +866 -761
- package/src/insight/insightEvents.ts +57 -56
- package/src/plugins/BasePlugin.ts +125 -121
- package/src/plugins/ec.spec.ts +457 -429
- package/src/plugins/ec.ts +202 -199
- package/src/plugins/link.spec.ts +183 -159
- package/src/plugins/link.ts +88 -85
- package/src/plugins/svc.spec.ts +161 -155
- package/src/plugins/svc.ts +93 -91
- package/src/react-native/index.ts +8 -1
- package/src/react-native/react-native-runtime.ts +33 -33
- package/src/react-native/react-native-utils.ts +1 -1
- package/src/react-native/react-native.spec.ts +31 -21
- package/src/searchPage/searchPageClient.spec.ts +1944 -1794
- package/src/searchPage/searchPageClient.ts +1261 -1040
- package/src/searchPage/searchPageEvents.ts +524 -511
- package/src/storage.spec.ts +51 -51
- package/src/storage.ts +47 -47
- package/dist/definitions/bundle/browser-fetch.d.ts +0 -1
- package/dist/definitions/src/coveoua/browser.d.ts +0 -6
- package/dist/definitions/src/coveoua/headless.d.ts +0 -6
- package/dist/definitions/src/coveoua/library.d.ts +0 -17
- package/dist/definitions/src/coveoua/plugins.d.ts +0 -10
- package/dist/definitions/src/coveoua/simpleanalytics.d.ts +0 -33
- package/dist/definitions/src/react-native/index.d.ts +0 -3
- 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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
57
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
100
|
+
this.client = new CoveoAnalyticsClient({
|
|
101
|
+
endpoint: endpoint,
|
|
102
|
+
isCustomEndpoint: isCustomEndpoint,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
128
105
|
|
|
129
|
-
|
|
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
|
-
|
|
133
|
-
|
|
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
|
-
|
|
137
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
157
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
2
|
+
return typeof window !== 'undefined';
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export function hasNavigator(): boolean {
|
|
6
|
-
|
|
6
|
+
return typeof navigator !== 'undefined';
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export function hasDocument(): boolean {
|
|
10
|
-
|
|
10
|
+
return typeof document !== 'undefined';
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function hasLocalStorage(): boolean {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
30
|
+
return hasNavigator() && navigator.cookieEnabled;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export function hasCrypto(): boolean {
|
|
34
|
-
|
|
34
|
+
return typeof crypto !== 'undefined';
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export function hasCryptoRandomValues(): boolean {
|
|
38
|
-
|
|
38
|
+
return hasCrypto() && typeof crypto.getRandomValues !== 'undefined';
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export function hasLocation(): boolean {
|
|
42
|
-
|
|
42
|
+
return typeof location !== 'undefined';
|
|
43
43
|
}
|