coveo.analytics 2.28.13 → 2.28.14
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/dist/coveoua.browser.js +1 -1
- package/dist/coveoua.browser.js.map +1 -1
- package/dist/coveoua.debug.js +17 -6
- 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 +1 -1
- package/dist/definitions/client/analyticsBeaconClient.d.ts +1 -0
- package/dist/definitions/client/runtimeEnvironment.d.ts +6 -0
- package/dist/definitions/react-native/react-native-runtime.d.ts +1 -0
- package/dist/definitions/src/react-native/react-native-runtime.d.ts +1 -0
- package/dist/definitions/version.d.ts +1 -1
- package/dist/library.es.js +17 -6
- package/dist/library.js +17 -6
- package/dist/react-native.es.js +20 -6
- package/package.json +1 -1
- package/src/client/analytics.ts +3 -3
- package/src/client/analyticsBeaconClient.ts +5 -3
- package/src/client/runtimeEnvironment.ts +14 -0
- package/src/react-native/react-native-runtime.ts +4 -0
|
@@ -85,7 +85,7 @@ export declare class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdP
|
|
|
85
85
|
makeEvent<TPreparedRequest, TCompleteRequest, TResponse extends AnyEventResponse>(eventType: EventType | string, ...payload: VariableArgumentsPayload): Promise<PreparedEvent<TPreparedRequest, TCompleteRequest, TResponse>>;
|
|
86
86
|
sendEvent(eventType: EventType | string, ...payload: VariableArgumentsPayload): Promise<void | AnyEventResponse>;
|
|
87
87
|
private deferExecution;
|
|
88
|
-
private
|
|
88
|
+
private sendFromBuffer;
|
|
89
89
|
clear(): void;
|
|
90
90
|
deleteHttpOnlyVisitorId(): void;
|
|
91
91
|
makeSearchEvent(request: PreparedSearchEventRequest): Promise<PreparedEvent<PreparedSearchEventRequest, SearchEventRequest, SearchEventResponse>>;
|
|
@@ -4,6 +4,7 @@ export declare class AnalyticsBeaconClient implements AnalyticsRequestClient {
|
|
|
4
4
|
private opts;
|
|
5
5
|
constructor(opts: IAnalyticsClientOptions);
|
|
6
6
|
sendEvent(eventType: EventType, payload: IRequestPayload): Promise<void>;
|
|
7
|
+
isAvailable(): boolean;
|
|
7
8
|
deleteHttpCookieVisitorId(): Promise<void>;
|
|
8
9
|
private encodeForEventType;
|
|
9
10
|
private getQueryParamsForEventType;
|
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
import { WebStorage, NullStorage } from '../storage';
|
|
2
|
+
import { AnalyticsBeaconClient } from './analyticsBeaconClient';
|
|
2
3
|
import { AnalyticsRequestClient, IAnalyticsClientOptions, NoopAnalyticsClient } from './analyticsRequestClient';
|
|
3
4
|
import { AnalyticsFetchClient } from './analyticsFetchClient';
|
|
4
5
|
import { BufferedRequest } from './analytics';
|
|
6
|
+
import { EventType } from '../events';
|
|
5
7
|
export interface IRuntimeEnvironment {
|
|
6
8
|
storage: WebStorage;
|
|
7
9
|
client: AnalyticsRequestClient;
|
|
10
|
+
getClientDependingOnEventType(eventType: EventType): AnalyticsRequestClient;
|
|
8
11
|
}
|
|
9
12
|
export declare class BrowserRuntime implements IRuntimeEnvironment {
|
|
10
13
|
storage: WebStorage;
|
|
11
14
|
client: AnalyticsFetchClient;
|
|
12
15
|
private beaconClient;
|
|
13
16
|
constructor(clientOptions: IAnalyticsClientOptions, getUnprocessedRequests: () => Array<BufferedRequest>);
|
|
17
|
+
getClientDependingOnEventType(eventType: EventType): AnalyticsFetchClient | AnalyticsBeaconClient;
|
|
14
18
|
}
|
|
15
19
|
export declare class NodeJSRuntime implements IRuntimeEnvironment {
|
|
16
20
|
storage: WebStorage;
|
|
17
21
|
client: AnalyticsFetchClient;
|
|
18
22
|
constructor(clientOptions: IAnalyticsClientOptions, storage?: WebStorage);
|
|
23
|
+
getClientDependingOnEventType(eventType: EventType): AnalyticsRequestClient;
|
|
19
24
|
}
|
|
20
25
|
export declare class NoopRuntime implements IRuntimeEnvironment {
|
|
21
26
|
storage: NullStorage;
|
|
22
27
|
client: NoopAnalyticsClient;
|
|
28
|
+
getClientDependingOnEventType(eventType: EventType): AnalyticsRequestClient;
|
|
23
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const libVersion = "2.28.
|
|
1
|
+
export declare const libVersion = "2.28.14";
|
package/dist/library.es.js
CHANGED
|
@@ -596,7 +596,7 @@ function sha1(bytes) {
|
|
|
596
596
|
const v5 = v35('v5', 0x50, sha1);
|
|
597
597
|
var uuidv5 = v5;
|
|
598
598
|
|
|
599
|
-
const libVersion = "2.28.
|
|
599
|
+
const libVersion = "2.28.14" ;
|
|
600
600
|
|
|
601
601
|
const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
|
|
602
602
|
|
|
@@ -1009,7 +1009,7 @@ class AnalyticsBeaconClient {
|
|
|
1009
1009
|
}
|
|
1010
1010
|
sendEvent(eventType, payload) {
|
|
1011
1011
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1012
|
-
if (!
|
|
1012
|
+
if (!this.isAvailable()) {
|
|
1013
1013
|
throw new Error(`navigator.sendBeacon is not supported in this browser. Consider adding a polyfill like "sendbeacon-polyfill".`);
|
|
1014
1014
|
}
|
|
1015
1015
|
const { baseUrl, preprocessRequest } = this.opts;
|
|
@@ -1022,11 +1022,13 @@ class AnalyticsBeaconClient {
|
|
|
1022
1022
|
}),
|
|
1023
1023
|
};
|
|
1024
1024
|
const { url, body } = Object.assign(Object.assign({}, defaultOptions), (preprocessRequest ? yield preprocessRequest(defaultOptions, 'analyticsBeacon') : {}));
|
|
1025
|
-
console.log(`Sending beacon for "${eventType}" with: `, JSON.stringify(payload));
|
|
1026
1025
|
navigator.sendBeacon(url, body);
|
|
1027
1026
|
return;
|
|
1028
1027
|
});
|
|
1029
1028
|
}
|
|
1029
|
+
isAvailable() {
|
|
1030
|
+
return 'sendBeacon' in navigator;
|
|
1031
|
+
}
|
|
1030
1032
|
deleteHttpCookieVisitorId() {
|
|
1031
1033
|
return Promise.resolve();
|
|
1032
1034
|
}
|
|
@@ -1162,18 +1164,27 @@ class BrowserRuntime {
|
|
|
1162
1164
|
}
|
|
1163
1165
|
});
|
|
1164
1166
|
}
|
|
1167
|
+
getClientDependingOnEventType(eventType) {
|
|
1168
|
+
return eventType === 'click' && this.beaconClient.isAvailable() ? this.beaconClient : this.client;
|
|
1169
|
+
}
|
|
1165
1170
|
}
|
|
1166
1171
|
class NodeJSRuntime {
|
|
1167
1172
|
constructor(clientOptions, storage) {
|
|
1168
1173
|
this.storage = storage || new NullStorage();
|
|
1169
1174
|
this.client = new AnalyticsFetchClient(clientOptions);
|
|
1170
1175
|
}
|
|
1176
|
+
getClientDependingOnEventType(eventType) {
|
|
1177
|
+
return this.client;
|
|
1178
|
+
}
|
|
1171
1179
|
}
|
|
1172
1180
|
class NoopRuntime {
|
|
1173
1181
|
constructor() {
|
|
1174
1182
|
this.storage = new NullStorage();
|
|
1175
1183
|
this.client = new NoopAnalyticsClient();
|
|
1176
1184
|
}
|
|
1185
|
+
getClientDependingOnEventType(eventType) {
|
|
1186
|
+
return this.client;
|
|
1187
|
+
}
|
|
1177
1188
|
}
|
|
1178
1189
|
|
|
1179
1190
|
const API_KEY_PREFIX = 'xx';
|
|
@@ -1422,7 +1433,7 @@ class CoveoAnalyticsClient {
|
|
|
1422
1433
|
});
|
|
1423
1434
|
yield Promise.all(this.afterSendHooks.map((hook) => hook(eventType, Object.assign(Object.assign({}, parametersToSend), remainingPayload))));
|
|
1424
1435
|
yield this.deferExecution();
|
|
1425
|
-
return (yield this.
|
|
1436
|
+
return (yield this.sendFromBuffer());
|
|
1426
1437
|
}),
|
|
1427
1438
|
};
|
|
1428
1439
|
});
|
|
@@ -1435,12 +1446,12 @@ class CoveoAnalyticsClient {
|
|
|
1435
1446
|
deferExecution() {
|
|
1436
1447
|
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
1437
1448
|
}
|
|
1438
|
-
|
|
1449
|
+
sendFromBuffer() {
|
|
1439
1450
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1440
1451
|
const popped = this.bufferedRequests.shift();
|
|
1441
1452
|
if (popped) {
|
|
1442
1453
|
const { eventType, payload } = popped;
|
|
1443
|
-
return this.runtime.
|
|
1454
|
+
return this.runtime.getClientDependingOnEventType(eventType).sendEvent(eventType, payload);
|
|
1444
1455
|
}
|
|
1445
1456
|
});
|
|
1446
1457
|
}
|
package/dist/library.js
CHANGED
|
@@ -731,7 +731,7 @@ function sha1(bytes) {
|
|
|
731
731
|
const v5 = v35('v5', 0x50, sha1);
|
|
732
732
|
var uuidv5 = v5;
|
|
733
733
|
|
|
734
|
-
var libVersion = "2.28.
|
|
734
|
+
var libVersion = "2.28.14" ;
|
|
735
735
|
|
|
736
736
|
var getFormattedLocation = function (location) {
|
|
737
737
|
return "".concat(location.protocol, "//").concat(location.hostname).concat(location.pathname.indexOf('/') === 0 ? location.pathname : "/".concat(location.pathname)).concat(location.search);
|
|
@@ -1211,7 +1211,7 @@ var AnalyticsBeaconClient = (function () {
|
|
|
1211
1211
|
return __generator(this, function (_e) {
|
|
1212
1212
|
switch (_e.label) {
|
|
1213
1213
|
case 0:
|
|
1214
|
-
if (!
|
|
1214
|
+
if (!this.isAvailable()) {
|
|
1215
1215
|
throw new Error("navigator.sendBeacon is not supported in this browser. Consider adding a polyfill like \"sendbeacon-polyfill\".");
|
|
1216
1216
|
}
|
|
1217
1217
|
_a = this.opts, baseUrl = _a.baseUrl, preprocessRequest = _a.preprocessRequest;
|
|
@@ -1236,13 +1236,15 @@ var AnalyticsBeaconClient = (function () {
|
|
|
1236
1236
|
_e.label = 4;
|
|
1237
1237
|
case 4:
|
|
1238
1238
|
_b = __assign.apply(void 0, _c.concat([(_d)])), url = _b.url, body = _b.body;
|
|
1239
|
-
console.log("Sending beacon for \"".concat(eventType, "\" with: "), JSON.stringify(payload));
|
|
1240
1239
|
navigator.sendBeacon(url, body);
|
|
1241
1240
|
return [2];
|
|
1242
1241
|
}
|
|
1243
1242
|
});
|
|
1244
1243
|
});
|
|
1245
1244
|
};
|
|
1245
|
+
AnalyticsBeaconClient.prototype.isAvailable = function () {
|
|
1246
|
+
return 'sendBeacon' in navigator;
|
|
1247
|
+
};
|
|
1246
1248
|
AnalyticsBeaconClient.prototype.deleteHttpCookieVisitorId = function () {
|
|
1247
1249
|
return Promise.resolve();
|
|
1248
1250
|
};
|
|
@@ -82949,6 +82951,9 @@ var BrowserRuntime = (function () {
|
|
|
82949
82951
|
}
|
|
82950
82952
|
});
|
|
82951
82953
|
}
|
|
82954
|
+
BrowserRuntime.prototype.getClientDependingOnEventType = function (eventType) {
|
|
82955
|
+
return eventType === 'click' && this.beaconClient.isAvailable() ? this.beaconClient : this.client;
|
|
82956
|
+
};
|
|
82952
82957
|
return BrowserRuntime;
|
|
82953
82958
|
}());
|
|
82954
82959
|
var NodeJSRuntime = (function () {
|
|
@@ -82956,6 +82961,9 @@ var NodeJSRuntime = (function () {
|
|
|
82956
82961
|
this.storage = storage || new NullStorage();
|
|
82957
82962
|
this.client = new AnalyticsFetchClient(clientOptions);
|
|
82958
82963
|
}
|
|
82964
|
+
NodeJSRuntime.prototype.getClientDependingOnEventType = function (eventType) {
|
|
82965
|
+
return this.client;
|
|
82966
|
+
};
|
|
82959
82967
|
return NodeJSRuntime;
|
|
82960
82968
|
}());
|
|
82961
82969
|
var NoopRuntime = (function () {
|
|
@@ -82963,6 +82971,9 @@ var NoopRuntime = (function () {
|
|
|
82963
82971
|
this.storage = new NullStorage();
|
|
82964
82972
|
this.client = new NoopAnalyticsClient();
|
|
82965
82973
|
}
|
|
82974
|
+
NoopRuntime.prototype.getClientDependingOnEventType = function (eventType) {
|
|
82975
|
+
return this.client;
|
|
82976
|
+
};
|
|
82966
82977
|
return NoopRuntime;
|
|
82967
82978
|
}());
|
|
82968
82979
|
|
|
@@ -83395,7 +83406,7 @@ var CoveoAnalyticsClient = (function () {
|
|
|
83395
83406
|
return [4, this.deferExecution()];
|
|
83396
83407
|
case 2:
|
|
83397
83408
|
_a.sent();
|
|
83398
|
-
return [4, this.
|
|
83409
|
+
return [4, this.sendFromBuffer()];
|
|
83399
83410
|
case 3: return [2, (_a.sent())];
|
|
83400
83411
|
}
|
|
83401
83412
|
});
|
|
@@ -83422,14 +83433,14 @@ var CoveoAnalyticsClient = (function () {
|
|
|
83422
83433
|
CoveoAnalyticsClient.prototype.deferExecution = function () {
|
|
83423
83434
|
return new Promise(function (resolve) { return setTimeout(resolve, 0); });
|
|
83424
83435
|
};
|
|
83425
|
-
CoveoAnalyticsClient.prototype.
|
|
83436
|
+
CoveoAnalyticsClient.prototype.sendFromBuffer = function () {
|
|
83426
83437
|
return __awaiter(this, void 0, void 0, function () {
|
|
83427
83438
|
var popped, eventType, payload;
|
|
83428
83439
|
return __generator(this, function (_a) {
|
|
83429
83440
|
popped = this.bufferedRequests.shift();
|
|
83430
83441
|
if (popped) {
|
|
83431
83442
|
eventType = popped.eventType, payload = popped.payload;
|
|
83432
|
-
return [2, this.runtime.
|
|
83443
|
+
return [2, this.runtime.getClientDependingOnEventType(eventType).sendEvent(eventType, payload)];
|
|
83433
83444
|
}
|
|
83434
83445
|
return [2];
|
|
83435
83446
|
});
|
package/dist/react-native.es.js
CHANGED
|
@@ -658,7 +658,7 @@ const addPageViewToHistory = (pageViewValue) => __awaiter(void 0, void 0, void 0
|
|
|
658
658
|
yield store.addElementAsync(historyElement);
|
|
659
659
|
});
|
|
660
660
|
|
|
661
|
-
const libVersion = "2.28.
|
|
661
|
+
const libVersion = "2.28.14" ;
|
|
662
662
|
|
|
663
663
|
const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
|
|
664
664
|
|
|
@@ -1071,7 +1071,7 @@ class AnalyticsBeaconClient {
|
|
|
1071
1071
|
}
|
|
1072
1072
|
sendEvent(eventType, payload) {
|
|
1073
1073
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1074
|
-
if (!
|
|
1074
|
+
if (!this.isAvailable()) {
|
|
1075
1075
|
throw new Error(`navigator.sendBeacon is not supported in this browser. Consider adding a polyfill like "sendbeacon-polyfill".`);
|
|
1076
1076
|
}
|
|
1077
1077
|
const { baseUrl, preprocessRequest } = this.opts;
|
|
@@ -1084,11 +1084,13 @@ class AnalyticsBeaconClient {
|
|
|
1084
1084
|
}),
|
|
1085
1085
|
};
|
|
1086
1086
|
const { url, body } = Object.assign(Object.assign({}, defaultOptions), (preprocessRequest ? yield preprocessRequest(defaultOptions, 'analyticsBeacon') : {}));
|
|
1087
|
-
console.log(`Sending beacon for "${eventType}" with: `, JSON.stringify(payload));
|
|
1088
1087
|
navigator.sendBeacon(url, body);
|
|
1089
1088
|
return;
|
|
1090
1089
|
});
|
|
1091
1090
|
}
|
|
1091
|
+
isAvailable() {
|
|
1092
|
+
return 'sendBeacon' in navigator;
|
|
1093
|
+
}
|
|
1092
1094
|
deleteHttpCookieVisitorId() {
|
|
1093
1095
|
return Promise.resolve();
|
|
1094
1096
|
}
|
|
@@ -1163,18 +1165,27 @@ class BrowserRuntime {
|
|
|
1163
1165
|
}
|
|
1164
1166
|
});
|
|
1165
1167
|
}
|
|
1168
|
+
getClientDependingOnEventType(eventType) {
|
|
1169
|
+
return eventType === 'click' && this.beaconClient.isAvailable() ? this.beaconClient : this.client;
|
|
1170
|
+
}
|
|
1166
1171
|
}
|
|
1167
1172
|
class NodeJSRuntime {
|
|
1168
1173
|
constructor(clientOptions, storage) {
|
|
1169
1174
|
this.storage = storage || new NullStorage();
|
|
1170
1175
|
this.client = new AnalyticsFetchClient(clientOptions);
|
|
1171
1176
|
}
|
|
1177
|
+
getClientDependingOnEventType(eventType) {
|
|
1178
|
+
return this.client;
|
|
1179
|
+
}
|
|
1172
1180
|
}
|
|
1173
1181
|
class NoopRuntime {
|
|
1174
1182
|
constructor() {
|
|
1175
1183
|
this.storage = new NullStorage();
|
|
1176
1184
|
this.client = new NoopAnalyticsClient();
|
|
1177
1185
|
}
|
|
1186
|
+
getClientDependingOnEventType(eventType) {
|
|
1187
|
+
return this.client;
|
|
1188
|
+
}
|
|
1178
1189
|
}
|
|
1179
1190
|
|
|
1180
1191
|
const API_KEY_PREFIX = 'xx';
|
|
@@ -1423,7 +1434,7 @@ class CoveoAnalyticsClient {
|
|
|
1423
1434
|
});
|
|
1424
1435
|
yield Promise.all(this.afterSendHooks.map((hook) => hook(eventType, Object.assign(Object.assign({}, parametersToSend), remainingPayload))));
|
|
1425
1436
|
yield this.deferExecution();
|
|
1426
|
-
return (yield this.
|
|
1437
|
+
return (yield this.sendFromBuffer());
|
|
1427
1438
|
}),
|
|
1428
1439
|
};
|
|
1429
1440
|
});
|
|
@@ -1436,12 +1447,12 @@ class CoveoAnalyticsClient {
|
|
|
1436
1447
|
deferExecution() {
|
|
1437
1448
|
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
1438
1449
|
}
|
|
1439
|
-
|
|
1450
|
+
sendFromBuffer() {
|
|
1440
1451
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1441
1452
|
const popped = this.bufferedRequests.shift();
|
|
1442
1453
|
if (popped) {
|
|
1443
1454
|
const { eventType, payload } = popped;
|
|
1444
|
-
return this.runtime.
|
|
1455
|
+
return this.runtime.getClientDependingOnEventType(eventType).sendEvent(eventType, payload);
|
|
1445
1456
|
}
|
|
1446
1457
|
});
|
|
1447
1458
|
}
|
|
@@ -1667,6 +1678,9 @@ class ReactNativeRuntime {
|
|
|
1667
1678
|
},
|
|
1668
1679
|
});
|
|
1669
1680
|
}
|
|
1681
|
+
getClientDependingOnEventType() {
|
|
1682
|
+
return this.client;
|
|
1683
|
+
}
|
|
1670
1684
|
}
|
|
1671
1685
|
|
|
1672
1686
|
var InsightEvents;
|
package/package.json
CHANGED
package/src/client/analytics.ts
CHANGED
|
@@ -393,7 +393,7 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
|
|
|
393
393
|
this.afterSendHooks.map((hook) => hook(eventType, {...parametersToSend, ...remainingPayload}))
|
|
394
394
|
);
|
|
395
395
|
await this.deferExecution();
|
|
396
|
-
return (await this.
|
|
396
|
+
return (await this.sendFromBuffer()) as TResponse | void;
|
|
397
397
|
},
|
|
398
398
|
};
|
|
399
399
|
}
|
|
@@ -406,11 +406,11 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
|
|
|
406
406
|
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
407
407
|
}
|
|
408
408
|
|
|
409
|
-
private async
|
|
409
|
+
private async sendFromBuffer(): Promise<AnyEventResponse | void> {
|
|
410
410
|
const popped = this.bufferedRequests.shift();
|
|
411
411
|
if (popped) {
|
|
412
412
|
const {eventType, payload} = popped;
|
|
413
|
-
return this.runtime.
|
|
413
|
+
return this.runtime.getClientDependingOnEventType(eventType).sendEvent(eventType, payload);
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
416
|
|
|
@@ -5,7 +5,7 @@ export class AnalyticsBeaconClient implements AnalyticsRequestClient {
|
|
|
5
5
|
constructor(private opts: IAnalyticsClientOptions) {}
|
|
6
6
|
|
|
7
7
|
public async sendEvent(eventType: EventType, payload: IRequestPayload): Promise<void> {
|
|
8
|
-
if (!
|
|
8
|
+
if (!this.isAvailable()) {
|
|
9
9
|
throw new Error(
|
|
10
10
|
`navigator.sendBeacon is not supported in this browser. Consider adding a polyfill like "sendbeacon-polyfill".`
|
|
11
11
|
);
|
|
@@ -25,12 +25,14 @@ export class AnalyticsBeaconClient implements AnalyticsRequestClient {
|
|
|
25
25
|
...(preprocessRequest ? await preprocessRequest(defaultOptions, 'analyticsBeacon') : {}),
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
// tslint:disable-next-line: no-console
|
|
29
|
-
console.log(`Sending beacon for "${eventType}" with: `, JSON.stringify(payload));
|
|
30
28
|
navigator.sendBeacon(url, body as any); // https://github.com/microsoft/TypeScript/issues/38715
|
|
31
29
|
return;
|
|
32
30
|
}
|
|
33
31
|
|
|
32
|
+
public isAvailable() {
|
|
33
|
+
return 'sendBeacon' in navigator;
|
|
34
|
+
}
|
|
35
|
+
|
|
34
36
|
public deleteHttpCookieVisitorId() {
|
|
35
37
|
return Promise.resolve();
|
|
36
38
|
}
|
|
@@ -4,10 +4,12 @@ import {hasLocalStorage, hasCookieStorage} from '../detector';
|
|
|
4
4
|
import {AnalyticsRequestClient, IAnalyticsClientOptions, NoopAnalyticsClient} from './analyticsRequestClient';
|
|
5
5
|
import {AnalyticsFetchClient} from './analyticsFetchClient';
|
|
6
6
|
import {BufferedRequest} from './analytics';
|
|
7
|
+
import {EventType} from '../events';
|
|
7
8
|
|
|
8
9
|
export interface IRuntimeEnvironment {
|
|
9
10
|
storage: WebStorage;
|
|
10
11
|
client: AnalyticsRequestClient;
|
|
12
|
+
getClientDependingOnEventType(eventType: EventType): AnalyticsRequestClient;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export class BrowserRuntime implements IRuntimeEnvironment {
|
|
@@ -33,6 +35,10 @@ export class BrowserRuntime implements IRuntimeEnvironment {
|
|
|
33
35
|
}
|
|
34
36
|
});
|
|
35
37
|
}
|
|
38
|
+
|
|
39
|
+
public getClientDependingOnEventType(eventType: EventType) {
|
|
40
|
+
return eventType === 'click' && this.beaconClient.isAvailable() ? this.beaconClient : this.client;
|
|
41
|
+
}
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
export class NodeJSRuntime implements IRuntimeEnvironment {
|
|
@@ -43,9 +49,17 @@ export class NodeJSRuntime implements IRuntimeEnvironment {
|
|
|
43
49
|
this.storage = storage || new NullStorage();
|
|
44
50
|
this.client = new AnalyticsFetchClient(clientOptions);
|
|
45
51
|
}
|
|
52
|
+
|
|
53
|
+
getClientDependingOnEventType(eventType: EventType): AnalyticsRequestClient {
|
|
54
|
+
return this.client;
|
|
55
|
+
}
|
|
46
56
|
}
|
|
47
57
|
|
|
48
58
|
export class NoopRuntime implements IRuntimeEnvironment {
|
|
49
59
|
public storage = new NullStorage();
|
|
50
60
|
public client = new NoopAnalyticsClient();
|
|
61
|
+
|
|
62
|
+
getClientDependingOnEventType(eventType: EventType): AnalyticsRequestClient {
|
|
63
|
+
return this.client;
|
|
64
|
+
}
|
|
51
65
|
}
|