coveo.analytics 2.28.9 → 2.28.11

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.
@@ -111,7 +111,7 @@ export declare class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdP
111
111
  private lowercaseKeys;
112
112
  private validateParams;
113
113
  private ensureAnonymousUserWhenUsingApiKey;
114
- private setTrackingIdFromContextWebsiteIfTrackingIdNotPresent;
114
+ private setTrackingIdIfTrackingIdNotPresent;
115
115
  private limit;
116
116
  private get baseUrl();
117
117
  }
@@ -1 +1 @@
1
- export declare const libVersion = "2.28.9";
1
+ export declare const libVersion = "2.28.11";
@@ -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.9" ;
599
+ const libVersion = "2.28.11" ;
600
600
 
601
601
  const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
602
602
 
@@ -1385,7 +1385,7 @@ class CoveoAnalyticsClient {
1385
1385
  resolvePayloadForParameters(eventType, parameters) {
1386
1386
  return __awaiter(this, void 0, void 0, function* () {
1387
1387
  const { usesMeasurementProtocol = false } = this.eventTypeMapping[eventType] || {};
1388
- const addTrackingIdStep = (currentPayload) => this.setTrackingIdFromContextWebsiteIfTrackingIdNotPresent(currentPayload);
1388
+ const addTrackingIdStep = (currentPayload) => this.setTrackingIdIfTrackingIdNotPresent(currentPayload);
1389
1389
  const cleanPayloadStep = (currentPayload) => this.removeEmptyPayloadValues(currentPayload, eventType);
1390
1390
  const validateParams = (currentPayload) => this.validateParams(currentPayload, eventType);
1391
1391
  const processMeasurementProtocolConversionStep = (currentPayload) => usesMeasurementProtocol ? convertKeysToMeasurementProtocol(currentPayload) : currentPayload;
@@ -1623,15 +1623,22 @@ class CoveoAnalyticsClient {
1623
1623
  return payload;
1624
1624
  }
1625
1625
  }
1626
- setTrackingIdFromContextWebsiteIfTrackingIdNotPresent(payload) {
1627
- const { trackingId, custom } = payload, rest = __rest(payload, ["trackingId", "custom"]);
1628
- if (!trackingId && custom && isObject(custom) && 'context_website' in custom) {
1629
- rest['trackingId'] = custom.context_website;
1630
- return Object.assign({ custom: custom }, rest);
1631
- }
1632
- else {
1626
+ setTrackingIdIfTrackingIdNotPresent(payload) {
1627
+ const { trackingId } = payload, rest = __rest(payload, ["trackingId"]);
1628
+ if (trackingId) {
1633
1629
  return payload;
1634
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;
1635
1642
  }
1636
1643
  limit(input, length) {
1637
1644
  if (typeof input !== 'string') {
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.9" ;
734
+ var libVersion = "2.28.11" ;
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);
@@ -83317,7 +83317,7 @@ var CoveoAnalyticsClient = (function () {
83317
83317
  case 0:
83318
83318
  _a = (this.eventTypeMapping[eventType] || {}).usesMeasurementProtocol, usesMeasurementProtocol = _a === void 0 ? false : _a;
83319
83319
  addTrackingIdStep = function (currentPayload) {
83320
- return _this.setTrackingIdFromContextWebsiteIfTrackingIdNotPresent(currentPayload);
83320
+ return _this.setTrackingIdIfTrackingIdNotPresent(currentPayload);
83321
83321
  };
83322
83322
  cleanPayloadStep = function (currentPayload) {
83323
83323
  return _this.removeEmptyPayloadValues(currentPayload, eventType);
@@ -83667,15 +83667,22 @@ var CoveoAnalyticsClient = (function () {
83667
83667
  return payload;
83668
83668
  }
83669
83669
  };
83670
- CoveoAnalyticsClient.prototype.setTrackingIdFromContextWebsiteIfTrackingIdNotPresent = function (payload) {
83671
- var trackingId = payload.trackingId, custom = payload.custom, rest = __rest(payload, ["trackingId", "custom"]);
83672
- if (!trackingId && custom && isObject(custom) && 'context_website' in custom) {
83673
- rest['trackingId'] = custom.context_website;
83674
- return __assign({ custom: custom }, rest);
83675
- }
83676
- else {
83670
+ CoveoAnalyticsClient.prototype.setTrackingIdIfTrackingIdNotPresent = function (payload) {
83671
+ var trackingId = payload.trackingId, rest = __rest(payload, ["trackingId"]);
83672
+ if (trackingId) {
83677
83673
  return payload;
83678
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;
83679
83686
  };
83680
83687
  CoveoAnalyticsClient.prototype.limit = function (input, length) {
83681
83688
  if (typeof input !== 'string') {
@@ -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.9" ;
661
+ const libVersion = "2.28.11" ;
662
662
 
663
663
  const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
664
664
 
@@ -1386,7 +1386,7 @@ class CoveoAnalyticsClient {
1386
1386
  resolvePayloadForParameters(eventType, parameters) {
1387
1387
  return __awaiter(this, void 0, void 0, function* () {
1388
1388
  const { usesMeasurementProtocol = false } = this.eventTypeMapping[eventType] || {};
1389
- const addTrackingIdStep = (currentPayload) => this.setTrackingIdFromContextWebsiteIfTrackingIdNotPresent(currentPayload);
1389
+ const addTrackingIdStep = (currentPayload) => this.setTrackingIdIfTrackingIdNotPresent(currentPayload);
1390
1390
  const cleanPayloadStep = (currentPayload) => this.removeEmptyPayloadValues(currentPayload, eventType);
1391
1391
  const validateParams = (currentPayload) => this.validateParams(currentPayload, eventType);
1392
1392
  const processMeasurementProtocolConversionStep = (currentPayload) => usesMeasurementProtocol ? convertKeysToMeasurementProtocol(currentPayload) : currentPayload;
@@ -1624,15 +1624,22 @@ class CoveoAnalyticsClient {
1624
1624
  return payload;
1625
1625
  }
1626
1626
  }
1627
- setTrackingIdFromContextWebsiteIfTrackingIdNotPresent(payload) {
1628
- const { trackingId, custom } = payload, rest = __rest(payload, ["trackingId", "custom"]);
1629
- if (!trackingId && custom && isObject(custom) && 'context_website' in custom) {
1630
- rest['trackingId'] = custom.context_website;
1631
- return Object.assign({ custom: custom }, rest);
1632
- }
1633
- else {
1627
+ setTrackingIdIfTrackingIdNotPresent(payload) {
1628
+ const { trackingId } = payload, rest = __rest(payload, ["trackingId"]);
1629
+ if (trackingId) {
1634
1630
  return payload;
1635
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;
1636
1643
  }
1637
1644
  limit(input, length) {
1638
1645
  if (typeof input !== 'string') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coveo.analytics",
3
- "version": "2.28.9",
3
+ "version": "2.28.11",
4
4
  "description": "📈 Coveo analytics client (node and browser compatible) ",
5
5
  "main": "dist/library.js",
6
6
  "module": "dist/library.es.js",
@@ -439,9 +439,9 @@ describe('Analytics', () => {
439
439
  });
440
440
  });
441
441
 
442
- describe('with context_website is set', () => {
442
+ describe('with context_website is set in customData', () => {
443
443
  const contextWebsite = 'yourbestfriend.com';
444
- const trackingId = 'yourfavaritefood.ca ';
444
+ const trackingId = 'yourfavoritefood.ca ';
445
445
  beforeEach(() => {
446
446
  client = new CoveoAnalyticsClient({
447
447
  token: 'xtoken',
@@ -452,13 +452,41 @@ describe('Analytics', () => {
452
452
  });
453
453
 
454
454
  it('should set trackingId when trackingId is not specified', async () => {
455
- await client.sendEvent(EventType.view, {custom: {context_website: contextWebsite}});
455
+ await client.sendEvent(EventType.view, {customData: {context_website: contextWebsite}});
456
456
  const [body] = getParsedBodyCalls();
457
457
  expect(body.trackingId).toBe(contextWebsite);
458
458
  });
459
459
 
460
- it('should not set trackingId when trackingId is specified', async () => {
461
- await client.sendEvent(EventType.view, {trackingId: trackingId, custom: {context_website: contextWebsite}});
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}});
462
490
  const [body] = getParsedBodyCalls();
463
491
  expect(body.trackingId).toBe(trackingId);
464
492
  });
@@ -345,7 +345,7 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
345
345
  const {usesMeasurementProtocol = false} = this.eventTypeMapping[eventType] || {};
346
346
 
347
347
  const addTrackingIdStep: ProcessPayloadStep = (currentPayload) =>
348
- this.setTrackingIdFromContextWebsiteIfTrackingIdNotPresent(currentPayload);
348
+ this.setTrackingIdIfTrackingIdNotPresent(currentPayload);
349
349
  const cleanPayloadStep: ProcessPayloadStep = (currentPayload) =>
350
350
  this.removeEmptyPayloadValues(currentPayload, eventType);
351
351
  const validateParams: ProcessPayloadStep = (currentPayload) => this.validateParams(currentPayload, eventType);
@@ -625,14 +625,25 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
625
625
  }
626
626
  }
627
627
 
628
- private setTrackingIdFromContextWebsiteIfTrackingIdNotPresent(payload: IRequestPayload): IRequestPayload {
629
- const {trackingId, custom, ...rest} = payload;
630
- if (!trackingId && custom && isObject(custom) && 'context_website' in custom) {
631
- rest['trackingId'] = custom.context_website;
632
- return {custom: custom, ...rest};
633
- } else {
628
+ private setTrackingIdIfTrackingIdNotPresent(payload: IRequestPayload): IRequestPayload {
629
+ const {trackingId, ...rest} = payload;
630
+ if (trackingId) {
634
631
  return payload;
635
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;
636
647
  }
637
648
 
638
649
  private limit(input: string, length: number): string | undefined | null {