coveo.analytics 2.28.8 → 2.28.10
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 +24 -2
- 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 -0
- package/dist/definitions/version.d.ts +1 -1
- package/dist/library.es.js +21 -1
- package/dist/library.js +24 -2
- package/dist/react-native.es.js +21 -1
- package/package.json +1 -1
- package/src/client/analytics.spec.ts +53 -0
- package/src/client/analytics.ts +24 -1
- package/src/client/measurementProtocolMapping/baseMeasurementProtocolMapper.ts +1 -0
- package/src/coveoua/simpleanalytics.spec.ts +24 -0
|
@@ -111,6 +111,7 @@ export declare class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdP
|
|
|
111
111
|
private lowercaseKeys;
|
|
112
112
|
private validateParams;
|
|
113
113
|
private ensureAnonymousUserWhenUsingApiKey;
|
|
114
|
+
private setTrackingIdIfTrackingIdNotPresent;
|
|
114
115
|
private limit;
|
|
115
116
|
private get baseUrl();
|
|
116
117
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const libVersion = "2.28.
|
|
1
|
+
export declare const libVersion = "2.28.10";
|
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.10" ;
|
|
600
600
|
|
|
601
601
|
const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
|
|
602
602
|
|
|
@@ -961,6 +961,7 @@ const coveoExtensionsKeys = [
|
|
|
961
961
|
'searchUid',
|
|
962
962
|
'permanentId',
|
|
963
963
|
'contentLocale',
|
|
964
|
+
'trackingId',
|
|
964
965
|
];
|
|
965
966
|
const baseMeasurementProtocolKeysMapping = Object.assign(Object.assign(Object.assign(Object.assign({}, globalParamKeysMapping), eventKeysMapping), contextInformationMapping), coveoExtensionsKeys.reduce((all, key) => (Object.assign(Object.assign({}, all), { [key]: key })), {}));
|
|
966
967
|
|
|
@@ -1384,6 +1385,7 @@ class CoveoAnalyticsClient {
|
|
|
1384
1385
|
resolvePayloadForParameters(eventType, parameters) {
|
|
1385
1386
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1386
1387
|
const { usesMeasurementProtocol = false } = this.eventTypeMapping[eventType] || {};
|
|
1388
|
+
const addTrackingIdStep = (currentPayload) => this.setTrackingIdIfTrackingIdNotPresent(currentPayload);
|
|
1387
1389
|
const cleanPayloadStep = (currentPayload) => this.removeEmptyPayloadValues(currentPayload, eventType);
|
|
1388
1390
|
const validateParams = (currentPayload) => this.validateParams(currentPayload, eventType);
|
|
1389
1391
|
const processMeasurementProtocolConversionStep = (currentPayload) => usesMeasurementProtocol ? convertKeysToMeasurementProtocol(currentPayload) : currentPayload;
|
|
@@ -1392,6 +1394,7 @@ class CoveoAnalyticsClient {
|
|
|
1392
1394
|
? this.processCustomParameters(currentPayload)
|
|
1393
1395
|
: this.mapCustomParametersToCustomData(currentPayload);
|
|
1394
1396
|
const payloadToSend = yield [
|
|
1397
|
+
addTrackingIdStep,
|
|
1395
1398
|
cleanPayloadStep,
|
|
1396
1399
|
validateParams,
|
|
1397
1400
|
processMeasurementProtocolConversionStep,
|
|
@@ -1620,6 +1623,23 @@ class CoveoAnalyticsClient {
|
|
|
1620
1623
|
return payload;
|
|
1621
1624
|
}
|
|
1622
1625
|
}
|
|
1626
|
+
setTrackingIdIfTrackingIdNotPresent(payload) {
|
|
1627
|
+
const { trackingId } = payload, rest = __rest(payload, ["trackingId"]);
|
|
1628
|
+
if (trackingId) {
|
|
1629
|
+
return payload;
|
|
1630
|
+
}
|
|
1631
|
+
if (rest.hasOwnProperty('custom') && isObject(rest.custom)) {
|
|
1632
|
+
if (rest.custom.hasOwnProperty('context_website') || rest.custom.hasOwnProperty('siteName')) {
|
|
1633
|
+
rest['trackingId'] = rest.custom.context_website || rest.custom.siteName;
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
if (rest.hasOwnProperty('customData') && isObject(rest.customData)) {
|
|
1637
|
+
if (rest.customData.hasOwnProperty('context_website') || rest.customData.hasOwnProperty('siteName')) {
|
|
1638
|
+
rest['trackingId'] = rest.customData.context_website || rest.customData.siteName;
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
return rest;
|
|
1642
|
+
}
|
|
1623
1643
|
limit(input, length) {
|
|
1624
1644
|
if (typeof input !== 'string') {
|
|
1625
1645
|
return input;
|
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.10" ;
|
|
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);
|
|
@@ -1151,6 +1151,7 @@ var coveoExtensionsKeys = [
|
|
|
1151
1151
|
'searchUid',
|
|
1152
1152
|
'permanentId',
|
|
1153
1153
|
'contentLocale',
|
|
1154
|
+
'trackingId',
|
|
1154
1155
|
];
|
|
1155
1156
|
var baseMeasurementProtocolKeysMapping = __assign(__assign(__assign(__assign({}, globalParamKeysMapping), eventKeysMapping), contextInformationMapping), coveoExtensionsKeys.reduce(function (all, key) {
|
|
1156
1157
|
var _a;
|
|
@@ -83309,12 +83310,15 @@ var CoveoAnalyticsClient = (function () {
|
|
|
83309
83310
|
};
|
|
83310
83311
|
CoveoAnalyticsClient.prototype.resolvePayloadForParameters = function (eventType, parameters) {
|
|
83311
83312
|
return __awaiter(this, void 0, void 0, function () {
|
|
83312
|
-
var _a, usesMeasurementProtocol, cleanPayloadStep, validateParams, processMeasurementProtocolConversionStep, removeUnknownParameters, processCustomParameters, payloadToSend;
|
|
83313
|
+
var _a, usesMeasurementProtocol, addTrackingIdStep, cleanPayloadStep, validateParams, processMeasurementProtocolConversionStep, removeUnknownParameters, processCustomParameters, payloadToSend;
|
|
83313
83314
|
var _this = this;
|
|
83314
83315
|
return __generator(this, function (_b) {
|
|
83315
83316
|
switch (_b.label) {
|
|
83316
83317
|
case 0:
|
|
83317
83318
|
_a = (this.eventTypeMapping[eventType] || {}).usesMeasurementProtocol, usesMeasurementProtocol = _a === void 0 ? false : _a;
|
|
83319
|
+
addTrackingIdStep = function (currentPayload) {
|
|
83320
|
+
return _this.setTrackingIdIfTrackingIdNotPresent(currentPayload);
|
|
83321
|
+
};
|
|
83318
83322
|
cleanPayloadStep = function (currentPayload) {
|
|
83319
83323
|
return _this.removeEmptyPayloadValues(currentPayload, eventType);
|
|
83320
83324
|
};
|
|
@@ -83331,6 +83335,7 @@ var CoveoAnalyticsClient = (function () {
|
|
|
83331
83335
|
: _this.mapCustomParametersToCustomData(currentPayload);
|
|
83332
83336
|
};
|
|
83333
83337
|
return [4, [
|
|
83338
|
+
addTrackingIdStep,
|
|
83334
83339
|
cleanPayloadStep,
|
|
83335
83340
|
validateParams,
|
|
83336
83341
|
processMeasurementProtocolConversionStep,
|
|
@@ -83662,6 +83667,23 @@ var CoveoAnalyticsClient = (function () {
|
|
|
83662
83667
|
return payload;
|
|
83663
83668
|
}
|
|
83664
83669
|
};
|
|
83670
|
+
CoveoAnalyticsClient.prototype.setTrackingIdIfTrackingIdNotPresent = function (payload) {
|
|
83671
|
+
var trackingId = payload.trackingId, rest = __rest(payload, ["trackingId"]);
|
|
83672
|
+
if (trackingId) {
|
|
83673
|
+
return payload;
|
|
83674
|
+
}
|
|
83675
|
+
if (rest.hasOwnProperty('custom') && isObject(rest.custom)) {
|
|
83676
|
+
if (rest.custom.hasOwnProperty('context_website') || rest.custom.hasOwnProperty('siteName')) {
|
|
83677
|
+
rest['trackingId'] = rest.custom.context_website || rest.custom.siteName;
|
|
83678
|
+
}
|
|
83679
|
+
}
|
|
83680
|
+
if (rest.hasOwnProperty('customData') && isObject(rest.customData)) {
|
|
83681
|
+
if (rest.customData.hasOwnProperty('context_website') || rest.customData.hasOwnProperty('siteName')) {
|
|
83682
|
+
rest['trackingId'] = rest.customData.context_website || rest.customData.siteName;
|
|
83683
|
+
}
|
|
83684
|
+
}
|
|
83685
|
+
return rest;
|
|
83686
|
+
};
|
|
83665
83687
|
CoveoAnalyticsClient.prototype.limit = function (input, length) {
|
|
83666
83688
|
if (typeof input !== 'string') {
|
|
83667
83689
|
return input;
|
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.10" ;
|
|
662
662
|
|
|
663
663
|
const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
|
|
664
664
|
|
|
@@ -1023,6 +1023,7 @@ const coveoExtensionsKeys = [
|
|
|
1023
1023
|
'searchUid',
|
|
1024
1024
|
'permanentId',
|
|
1025
1025
|
'contentLocale',
|
|
1026
|
+
'trackingId',
|
|
1026
1027
|
];
|
|
1027
1028
|
const baseMeasurementProtocolKeysMapping = Object.assign(Object.assign(Object.assign(Object.assign({}, globalParamKeysMapping), eventKeysMapping), contextInformationMapping), coveoExtensionsKeys.reduce((all, key) => (Object.assign(Object.assign({}, all), { [key]: key })), {}));
|
|
1028
1029
|
|
|
@@ -1385,6 +1386,7 @@ class CoveoAnalyticsClient {
|
|
|
1385
1386
|
resolvePayloadForParameters(eventType, parameters) {
|
|
1386
1387
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1387
1388
|
const { usesMeasurementProtocol = false } = this.eventTypeMapping[eventType] || {};
|
|
1389
|
+
const addTrackingIdStep = (currentPayload) => this.setTrackingIdIfTrackingIdNotPresent(currentPayload);
|
|
1388
1390
|
const cleanPayloadStep = (currentPayload) => this.removeEmptyPayloadValues(currentPayload, eventType);
|
|
1389
1391
|
const validateParams = (currentPayload) => this.validateParams(currentPayload, eventType);
|
|
1390
1392
|
const processMeasurementProtocolConversionStep = (currentPayload) => usesMeasurementProtocol ? convertKeysToMeasurementProtocol(currentPayload) : currentPayload;
|
|
@@ -1393,6 +1395,7 @@ class CoveoAnalyticsClient {
|
|
|
1393
1395
|
? this.processCustomParameters(currentPayload)
|
|
1394
1396
|
: this.mapCustomParametersToCustomData(currentPayload);
|
|
1395
1397
|
const payloadToSend = yield [
|
|
1398
|
+
addTrackingIdStep,
|
|
1396
1399
|
cleanPayloadStep,
|
|
1397
1400
|
validateParams,
|
|
1398
1401
|
processMeasurementProtocolConversionStep,
|
|
@@ -1621,6 +1624,23 @@ class CoveoAnalyticsClient {
|
|
|
1621
1624
|
return payload;
|
|
1622
1625
|
}
|
|
1623
1626
|
}
|
|
1627
|
+
setTrackingIdIfTrackingIdNotPresent(payload) {
|
|
1628
|
+
const { trackingId } = payload, rest = __rest(payload, ["trackingId"]);
|
|
1629
|
+
if (trackingId) {
|
|
1630
|
+
return payload;
|
|
1631
|
+
}
|
|
1632
|
+
if (rest.hasOwnProperty('custom') && isObject(rest.custom)) {
|
|
1633
|
+
if (rest.custom.hasOwnProperty('context_website') || rest.custom.hasOwnProperty('siteName')) {
|
|
1634
|
+
rest['trackingId'] = rest.custom.context_website || rest.custom.siteName;
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
if (rest.hasOwnProperty('customData') && isObject(rest.customData)) {
|
|
1638
|
+
if (rest.customData.hasOwnProperty('context_website') || rest.customData.hasOwnProperty('siteName')) {
|
|
1639
|
+
rest['trackingId'] = rest.customData.context_website || rest.customData.siteName;
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
return rest;
|
|
1643
|
+
}
|
|
1624
1644
|
limit(input, length) {
|
|
1625
1645
|
if (typeof input !== 'string') {
|
|
1626
1646
|
return input;
|
package/package.json
CHANGED
|
@@ -439,6 +439,59 @@ describe('Analytics', () => {
|
|
|
439
439
|
});
|
|
440
440
|
});
|
|
441
441
|
|
|
442
|
+
describe('with context_website is set in customData', () => {
|
|
443
|
+
const contextWebsite = 'yourbestfriend.com';
|
|
444
|
+
const trackingId = 'yourfavoritefood.ca ';
|
|
445
|
+
beforeEach(() => {
|
|
446
|
+
client = new CoveoAnalyticsClient({
|
|
447
|
+
token: 'xtoken',
|
|
448
|
+
endpoint: anEndpoint,
|
|
449
|
+
version: A_VERSION,
|
|
450
|
+
});
|
|
451
|
+
mockFetchRequestForEventType(EventType.view);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it('should set trackingId when trackingId is not specified', async () => {
|
|
455
|
+
await client.sendEvent(EventType.view, {customData: {context_website: contextWebsite}});
|
|
456
|
+
const [body] = getParsedBodyCalls();
|
|
457
|
+
expect(body.trackingId).toBe(contextWebsite);
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
it('should not overwrite trackingId when trackingId is specified', async () => {
|
|
461
|
+
await client.sendEvent(EventType.view, {
|
|
462
|
+
trackingId: trackingId,
|
|
463
|
+
customData: {context_website: contextWebsite},
|
|
464
|
+
});
|
|
465
|
+
const [body] = getParsedBodyCalls();
|
|
466
|
+
expect(body.trackingId).toBe(trackingId);
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
describe('with siteName is set in customData', () => {
|
|
471
|
+
const website = 'yourbestfriend.com';
|
|
472
|
+
const trackingId = 'yourfavoritefood.ca ';
|
|
473
|
+
beforeEach(() => {
|
|
474
|
+
client = new CoveoAnalyticsClient({
|
|
475
|
+
token: 'xtoken',
|
|
476
|
+
endpoint: anEndpoint,
|
|
477
|
+
version: A_VERSION,
|
|
478
|
+
});
|
|
479
|
+
mockFetchRequestForEventType(EventType.view);
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
it('should set trackingId when trackingId is not specified', async () => {
|
|
483
|
+
await client.sendEvent(EventType.view, {customData: {siteName: website}});
|
|
484
|
+
const [body] = getParsedBodyCalls();
|
|
485
|
+
expect(body.trackingId).toBe(website);
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it('should not overwrite trackingId when trackingId is specified', async () => {
|
|
489
|
+
await client.sendEvent(EventType.view, {trackingId: trackingId, customData: {siteName: website}});
|
|
490
|
+
const [body] = getParsedBodyCalls();
|
|
491
|
+
expect(body.trackingId).toBe(trackingId);
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
|
|
442
495
|
it('should support clearing cookies for visitorId and historyStore', () => {
|
|
443
496
|
const visitorId = 'foo';
|
|
444
497
|
const history = {name: 'foo', time: '123', value: 'bar'};
|
package/src/client/analytics.ts
CHANGED
|
@@ -344,6 +344,8 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
|
|
|
344
344
|
async resolvePayloadForParameters(eventType: EventType | string, parameters: any) {
|
|
345
345
|
const {usesMeasurementProtocol = false} = this.eventTypeMapping[eventType] || {};
|
|
346
346
|
|
|
347
|
+
const addTrackingIdStep: ProcessPayloadStep = (currentPayload) =>
|
|
348
|
+
this.setTrackingIdIfTrackingIdNotPresent(currentPayload);
|
|
347
349
|
const cleanPayloadStep: ProcessPayloadStep = (currentPayload) =>
|
|
348
350
|
this.removeEmptyPayloadValues(currentPayload, eventType);
|
|
349
351
|
const validateParams: ProcessPayloadStep = (currentPayload) => this.validateParams(currentPayload, eventType);
|
|
@@ -357,6 +359,7 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
|
|
|
357
359
|
: this.mapCustomParametersToCustomData(currentPayload);
|
|
358
360
|
|
|
359
361
|
const payloadToSend = await [
|
|
362
|
+
addTrackingIdStep,
|
|
360
363
|
cleanPayloadStep,
|
|
361
364
|
validateParams,
|
|
362
365
|
processMeasurementProtocolConversionStep,
|
|
@@ -378,7 +381,6 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
|
|
|
378
381
|
|
|
379
382
|
const parametersToSend = await this.resolveParameters(eventType, ...payload);
|
|
380
383
|
const payloadToSend = await this.resolvePayloadForParameters(eventType, parametersToSend);
|
|
381
|
-
|
|
382
384
|
return {
|
|
383
385
|
eventType: eventTypeToSend,
|
|
384
386
|
payload: payloadToSend,
|
|
@@ -623,6 +625,27 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
|
|
|
623
625
|
}
|
|
624
626
|
}
|
|
625
627
|
|
|
628
|
+
private setTrackingIdIfTrackingIdNotPresent(payload: IRequestPayload): IRequestPayload {
|
|
629
|
+
const {trackingId, ...rest} = payload;
|
|
630
|
+
if (trackingId) {
|
|
631
|
+
return payload;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
if (rest.hasOwnProperty('custom') && isObject(rest.custom)) {
|
|
635
|
+
if (rest.custom.hasOwnProperty('context_website') || rest.custom.hasOwnProperty('siteName')) {
|
|
636
|
+
rest['trackingId'] = rest.custom.context_website || rest.custom.siteName;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
if (rest.hasOwnProperty('customData') && isObject(rest.customData)) {
|
|
641
|
+
if (rest.customData.hasOwnProperty('context_website') || rest.customData.hasOwnProperty('siteName')) {
|
|
642
|
+
rest['trackingId'] = rest.customData.context_website || rest.customData.siteName;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
return rest;
|
|
647
|
+
}
|
|
648
|
+
|
|
626
649
|
private limit(input: string, length: number): string | undefined | null {
|
|
627
650
|
if (typeof input !== 'string') {
|
|
628
651
|
return input;
|
|
@@ -387,6 +387,30 @@ describe('simpleanalytics', () => {
|
|
|
387
387
|
expect(result).toHaveProperty('somedata', 'something');
|
|
388
388
|
expect(result).toHaveProperty('customData.context_website', 'MY_OTHER_WEBSITE');
|
|
389
389
|
});
|
|
390
|
+
|
|
391
|
+
it('can set trackingId', async () => {
|
|
392
|
+
const trackingId = 'yourbestfriend';
|
|
393
|
+
coveoua('init', 'MYTOKEN');
|
|
394
|
+
coveoua('set', 'trackingId', trackingId);
|
|
395
|
+
await coveoua('send', someRandomEventName);
|
|
396
|
+
|
|
397
|
+
expect(fetchMock.calls().length).toBe(1);
|
|
398
|
+
expect(fetchMock.lastUrl()).toBe(`${analyticsEndpoint}/${someRandomEventName}`);
|
|
399
|
+
expect(JSON.parse(lastCallBody(fetchMock))).toHaveProperty('trackingId', trackingId);
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
it('context_website does not overwrite trackingId', async () => {
|
|
403
|
+
const trackingId = 'yourbestfriend';
|
|
404
|
+
const contextWebsite = 'yoursite';
|
|
405
|
+
coveoua('init', 'MYTOKEN');
|
|
406
|
+
coveoua('set', 'custom', {context_website: contextWebsite});
|
|
407
|
+
coveoua('set', 'trackingId', trackingId);
|
|
408
|
+
await coveoua('send', someRandomEventName);
|
|
409
|
+
|
|
410
|
+
expect(fetchMock.calls().length).toBe(1);
|
|
411
|
+
expect(fetchMock.lastUrl()).toBe(`${analyticsEndpoint}/${someRandomEventName}`);
|
|
412
|
+
expect(JSON.parse(lastCallBody(fetchMock))).toHaveProperty('trackingId', trackingId);
|
|
413
|
+
});
|
|
390
414
|
});
|
|
391
415
|
|
|
392
416
|
describe('onLoad', () => {
|