@schibsted/pulse-sdk 8.0.0-rc.0 → 8.0.0-rc.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.
Files changed (101) hide show
  1. package/dist/cjs/Tracker.js +201 -209
  2. package/dist/cjs/Tracker.test-d.js +2 -2
  3. package/dist/cjs/builders/actor.js +3 -3
  4. package/dist/cjs/builders/consents.js +2 -2
  5. package/dist/cjs/builders/events-anonymous-node.js +1 -1
  6. package/dist/cjs/builders/events-node.js +3 -3
  7. package/dist/cjs/builders/experiments.js +1 -0
  8. package/dist/cjs/builders/tracker-node.js +2 -5
  9. package/dist/cjs/identity/actor.js +18 -6
  10. package/dist/cjs/identity/cis.js +4 -6
  11. package/dist/cjs/leaveTrackingTpaas/constants.js +2 -7
  12. package/dist/cjs/leaveTrackingTpaas/index.js +52 -40
  13. package/dist/cjs/tracker-proxy/consts.js +12 -6
  14. package/dist/cjs/tracker-proxy/proxy-provider.js +6 -0
  15. package/dist/cjs/version.js +5 -0
  16. package/dist/cjs/visibility-observer/index.js +9 -7
  17. package/dist/cjs/wrapper/types/event.js +5 -0
  18. package/dist/ejs/Tracker.js +203 -211
  19. package/dist/ejs/Tracker.test-d.js +2 -2
  20. package/dist/ejs/builders/actor.js +2 -2
  21. package/dist/ejs/builders/consents.js +2 -2
  22. package/dist/ejs/builders/events-anonymous-node.js +1 -1
  23. package/dist/ejs/builders/events-node.js +3 -3
  24. package/dist/ejs/builders/experiments.js +1 -1
  25. package/dist/ejs/builders/tracker-node.js +2 -2
  26. package/dist/ejs/identity/actor.js +19 -7
  27. package/dist/ejs/identity/cis.js +4 -3
  28. package/dist/ejs/leaveTrackingTpaas/constants.js +1 -5
  29. package/dist/ejs/leaveTrackingTpaas/index.js +53 -41
  30. package/dist/ejs/tracker-proxy/consts.js +12 -6
  31. package/dist/ejs/tracker-proxy/proxy-provider.js +6 -0
  32. package/dist/ejs/version.js +2 -0
  33. package/dist/ejs/visibility-observer/index.js +9 -7
  34. package/dist/ejs/wrapper/types/event.js +4 -1
  35. package/dist/types/Tracker.d.ts +92 -87
  36. package/dist/types/builders/actor.d.ts +3 -2
  37. package/dist/types/builders/consents.d.ts +2 -2
  38. package/dist/types/builders/experiments.d.ts +1 -0
  39. package/dist/types/builders/index.d.ts +1 -1
  40. package/dist/types/identity/actor.d.ts +2 -2
  41. package/dist/types/identity/cis.d.ts +1 -1
  42. package/dist/types/index.d.ts +1 -2
  43. package/dist/types/leaveTrackingTpaas/constants.d.ts +1 -5
  44. package/dist/types/leaveTrackingTpaas/index.d.ts +6 -6
  45. package/dist/types/leaveTrackingTpaas/types.d.ts +1 -9
  46. package/dist/types/tracker-proxy/consts.d.ts +1 -1
  47. package/dist/types/types.d.ts +19 -13
  48. package/dist/types/version.d.ts +1 -0
  49. package/dist/types/visibility-observer/index.d.ts +6 -1
  50. package/dist/types/wrapper/engagement/ui-element/types.d.ts +1 -0
  51. package/dist/types/wrapper/types/event.d.ts +3 -1
  52. package/dist/types/wrapper/view/ui-element/types.d.ts +1 -0
  53. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/cis-browser.d.ts +1 -0
  54. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/cis-browser.js +17 -3
  55. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/cis-browser.js.map +1 -1
  56. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/storage/pulseStorage.d.ts +4 -0
  57. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/storage/pulseStorage.js +15 -5
  58. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/storage/pulseStorage.js.map +1 -1
  59. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/storage/storage.d.ts +1 -0
  60. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/storage/storage.js +5 -0
  61. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/storage/storage.js.map +1 -1
  62. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/cis-browser.d.ts +1 -0
  63. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/cis-browser.js +16 -2
  64. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/cis-browser.js.map +1 -1
  65. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/storage/pulseStorage.d.ts +4 -0
  66. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/storage/pulseStorage.js +12 -3
  67. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/storage/pulseStorage.js.map +1 -1
  68. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/storage/storage.d.ts +1 -0
  69. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/storage/storage.js +5 -0
  70. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/storage/storage.js.map +1 -1
  71. package/node_modules/@schibsted/pulse-cis-sync/dist/types/cis-browser.d.ts +1 -0
  72. package/node_modules/@schibsted/pulse-cis-sync/dist/types/storage/pulseStorage.d.ts +4 -0
  73. package/node_modules/@schibsted/pulse-cis-sync/dist/types/storage/storage.d.ts +1 -0
  74. package/node_modules/@schibsted/pulse-utils/package.json +1 -1
  75. package/node_modules/@schibsted/tpaas-event-builder/dist/cjs/builders/catalogVersion.js +9 -0
  76. package/node_modules/@schibsted/tpaas-event-builder/dist/cjs/builders/device.js +8 -2
  77. package/node_modules/@schibsted/tpaas-event-builder/dist/cjs/builders/provider.js +3 -1
  78. package/node_modules/@schibsted/tpaas-event-builder/dist/cjs/builders/session.js +19 -6
  79. package/node_modules/@schibsted/tpaas-event-builder/dist/cjs/builders.js +75 -76
  80. package/node_modules/@schibsted/tpaas-event-builder/dist/cjs/guards.js +7 -0
  81. package/node_modules/@schibsted/tpaas-event-builder/dist/cjs/index.js +3 -0
  82. package/node_modules/@schibsted/tpaas-event-builder/dist/ejs/builders/catalogVersion.js +6 -0
  83. package/node_modules/@schibsted/tpaas-event-builder/dist/ejs/builders/device.js +8 -2
  84. package/node_modules/@schibsted/tpaas-event-builder/dist/ejs/builders/provider.js +3 -1
  85. package/node_modules/@schibsted/tpaas-event-builder/dist/ejs/builders/session.js +19 -6
  86. package/node_modules/@schibsted/tpaas-event-builder/dist/ejs/builders.js +74 -71
  87. package/node_modules/@schibsted/tpaas-event-builder/dist/ejs/guards.js +4 -0
  88. package/node_modules/@schibsted/tpaas-event-builder/dist/ejs/index.js +1 -0
  89. package/node_modules/@schibsted/tpaas-event-builder/dist/index.d.ts +1730 -1127
  90. package/node_modules/@schibsted/tpaas-event-builder/package.json +3 -2
  91. package/node_modules/@schibsted/tpaas-schemas/dist/cjs/constants.js +136 -103
  92. package/node_modules/@schibsted/tpaas-schemas/dist/cjs/index.js +1 -0
  93. package/node_modules/@schibsted/tpaas-schemas/dist/cjs/types.js +2 -0
  94. package/node_modules/@schibsted/tpaas-schemas/dist/ejs/constants.js +134 -101
  95. package/node_modules/@schibsted/tpaas-schemas/dist/ejs/index.js +1 -0
  96. package/node_modules/@schibsted/tpaas-schemas/dist/ejs/types.js +1 -0
  97. package/node_modules/@schibsted/tpaas-schemas/dist/index.d.ts +1940 -1266
  98. package/node_modules/@schibsted/tpaas-schemas/package.json +1 -1
  99. package/package.json +7 -6
  100. package/dist/cjs/version.json +0 -1
  101. package/dist/ejs/version.json +0 -1
@@ -10,6 +10,8 @@ const ARTICLE_PAYLOAD = {
10
10
  {
11
11
  name: 'test-experiment',
12
12
  variant: 'test-variant',
13
+ platform: 'web',
14
+ experimentSdrn: 'sdrn:the-standard:experiment:test-experiment',
13
15
  },
14
16
  ],
15
17
  object: {
@@ -35,8 +37,6 @@ const ARTICLE_PAYLOAD = {
35
37
  },
36
38
  },
37
39
  provider: {
38
- component: 'test-component',
39
- componentVersion: '1.0.0',
40
40
  product: 'test-product',
41
41
  stage: 'Dev',
42
42
  version: '1.0.0',
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultValue = void 0;
4
4
  exports.generateActorSDRN = generateActorSDRN;
5
- exports.isActorInput = isActorInput;
5
+ exports.hasActorBuilder = hasActorBuilder;
6
6
  exports.default = actor;
7
7
  const pulse_utils_1 = require("@schibsted/pulse-utils");
8
8
  /**
@@ -18,11 +18,11 @@ function generateActorSDRN(id, realm = '__REALM_NOT_SET__') {
18
18
  return `sdrn:${realm}:user:${outputId}`;
19
19
  }
20
20
  /**
21
- * Type guard to check if the input is an ActorInput
21
+ * Type guard to check if the input has an Actor Builder
22
22
  * @param input
23
23
  * @internal
24
24
  */
25
- function isActorInput(input) {
25
+ function hasActorBuilder(input) {
26
26
  // biome-ignore lint/suspicious/noPrototypeBuiltins: Object.hasOwn is not available in ES2020
27
27
  return (0, pulse_utils_1.isPlainObject)(input) && Object.prototype.hasOwnProperty.call(input, 'actor');
28
28
  }
@@ -14,7 +14,7 @@ const pulse_utils_1 = require("@schibsted/pulse-utils");
14
14
  const warnOnce_1 = __importDefault(require("../warnOnce"));
15
15
  const consent_manager_1 = require("./consent-manager");
16
16
  /**
17
- * @enum ConsentCategory
17
+ * @enum ConsentsCategory
18
18
  */
19
19
  var ConsentsCategory;
20
20
  (function (ConsentsCategory) {
@@ -23,7 +23,7 @@ var ConsentsCategory;
23
23
  ConsentsCategory["CMP_ADVERTISING"] = "CMP_ADVERTISING";
24
24
  ConsentsCategory["CMP_PERSONALIZATION"] = "CMP_PERSONALIZATION";
25
25
  })(ConsentsCategory || (exports.ConsentsCategory = ConsentsCategory = {}));
26
- exports.ConsentsSourceValues = ['default', 'cmp', 'cache'];
26
+ exports.ConsentsSourceValues = ['default', 'cmp', 'cache', 'url'];
27
27
  exports.ConsentsPurposeCategoryStatusValues = ['accepted', 'rejected', 'unknown'];
28
28
  const isLegacyConsentsPurpose = (consentsPurposeCategory) => {
29
29
  return !consentsPurposeCategory?.status;
@@ -65,7 +65,7 @@ function anonymousTrackerEvent({ eventInput, sdkConfig } = {}) {
65
65
  return Object.assign({}, (0, pulse_utils_1.omit)(eventInput, ['type']), {
66
66
  '@type': eventInput?.type || 'View',
67
67
  schema: eventInput?.schema ||
68
- `http://${sdkConfig?.schemaLocation || events_node_1.DEFAULT_SCHEMA_LOCATION}/events/tracker-event.json/351.json`,
68
+ `http://${sdkConfig?.schemaLocation || events_node_1.DEFAULT_SCHEMA_LOCATION}/events/tracker-event.json/360.json`,
69
69
  consents: (0, consents_1.default)(parentInput),
70
70
  experiments: (0, experiments_1.default)(parentInput),
71
71
  experimentMetadata: (0, experimentMetadata_1.default)(parentInput),
@@ -65,7 +65,7 @@ function routableEventDefaults(eventInput) {
65
65
  function routableEvent({ eventInput, sdkConfig } = {}) {
66
66
  return Object.assign({}, eventInput, {
67
67
  schema: eventInput?.schema ||
68
- `http://${sdkConfig?.schemaLocation || exports.DEFAULT_SCHEMA_LOCATION}/events/base-routable-event.json/246.json#`,
68
+ `http://${sdkConfig?.schemaLocation || exports.DEFAULT_SCHEMA_LOCATION}/events/base-routable-event.json/248.json#`,
69
69
  provider: (0, provider_1.default)(eventInput),
70
70
  actor: (0, actor_1.default)(eventInput),
71
71
  });
@@ -98,7 +98,7 @@ function trackerEvent({ eventInput, sdkConfig } = {}) {
98
98
  '@type': eventInput?.type || 'View',
99
99
  pageViewId: pageViewIdInput || pageViewIdSdk,
100
100
  schema: eventInput?.schema ||
101
- `http://${sdkConfig?.schemaLocation || exports.DEFAULT_SCHEMA_LOCATION}/events/tracker-event.json/359.json`,
101
+ `http://${sdkConfig?.schemaLocation || exports.DEFAULT_SCHEMA_LOCATION}/events/tracker-event.json/361.json`,
102
102
  actor: (0, actor_1.default)(parentInput),
103
103
  consents: (0, consents_1.default)(parentInput),
104
104
  experiments: (0, experiments_1.default)(parentInput),
@@ -116,7 +116,7 @@ trackerEvent.defaults = trackerEventInput;
116
116
  function engagementEvent({ eventInput, sdkConfig } = {}) {
117
117
  return Object.assign(trackerEvent({ eventInput, sdkConfig }), {
118
118
  schema: eventInput?.schema ||
119
- `http://${sdkConfig?.schemaLocation || exports.DEFAULT_SCHEMA_LOCATION}/events/engagement-event.json/386.json`,
119
+ `http://${sdkConfig?.schemaLocation || exports.DEFAULT_SCHEMA_LOCATION}/events/engagement-event.json/388.json`,
120
120
  '@type': 'Engagement',
121
121
  });
122
122
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultValue = void 0;
4
+ exports.generateExperimentSDRN = generateExperimentSDRN;
4
5
  exports.default = experiments;
5
6
  function generateExperimentSDRN(id, experimentationPlatform) {
6
7
  return `sdrn:${experimentationPlatform}:experiment:${id}`;
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.defaultValue = void 0;
7
4
  exports.default = tracker;
8
- const version_json_1 = __importDefault(require("../version.json"));
5
+ const version_1 = require("../version");
9
6
  /**
10
7
  * Format tracker objects
11
8
  */
@@ -14,7 +11,7 @@ function tracker(input) {
14
11
  const base = {
15
12
  name: 'Pulse Node.js SDK',
16
13
  type: 'JS',
17
- version: version_json_1.default.SDK_VERSION,
14
+ version: version_1.SDK_VERSION,
18
15
  };
19
16
  return Object.assign({}, base, trackerInput);
20
17
  }
@@ -10,9 +10,7 @@ const warnOnce_1 = __importDefault(require("../warnOnce"));
10
10
  /**
11
11
  * @internal exported for testing
12
12
  */
13
- exports.WARN_CIS_SYNC_LOGIN_UNDEFINED = 'Cis sync initiated with no actor builder and no event available. If you do not use a login system, please indicate' +
14
- ' this using tracker.update({ actor: undefined }), otherwise do tracker.update({ actor: somePromise }) with a' +
15
- ' promise that resolves to the login state.';
13
+ exports.WARN_CIS_SYNC_LOGIN_UNDEFINED = 'No Actor Builder found in event input or tracker builders. Please provide an Actor Builder to ensure the SDK resolves logged-in and logged-out scenarios correctly.';
16
14
  /**
17
15
  * Get the actor id (userId) from the current browser. A promise is returned
18
16
  * because a call may be made to complete the login process.
@@ -33,6 +31,19 @@ const getActor = async (builders) => {
33
31
  return await evaluateActor(builders);
34
32
  };
35
33
  exports.getActor = getActor;
34
+ /**
35
+ * Pinpoints the Actor Builder from the Event payload or the available Builders
36
+ * @param eventInput - The event input which may contain an `actor` property
37
+ * @param builders - The builders managed by the SDK.
38
+ */
39
+ function getActorSource(eventInput = {}, builders = {}) {
40
+ if ((0, actor_1.hasActorBuilder)(eventInput)) {
41
+ return eventInput.actor;
42
+ }
43
+ if ((0, actor_1.hasActorBuilder)(builders)) {
44
+ return builders.actor;
45
+ }
46
+ }
36
47
  const userIsLoggedIn = async (builders) => {
37
48
  const actor = await getActor(builders);
38
49
  return !!actor?.id;
@@ -45,8 +56,9 @@ exports.userIsLoggedIn = userIsLoggedIn;
45
56
  * @private
46
57
  */
47
58
  const evaluateActor = async (eventInput = {}, builders = {}) => {
48
- if ((0, actor_1.isActorInput)(eventInput) || (0, actor_1.isActorInput)(builders)) {
49
- const evaluatedActor = await (0, pulse_utils_1.evaluateAndFlatten)(eventInput.actor || builders.actor);
59
+ const actorSource = getActorSource(eventInput, builders);
60
+ if (actorSource) {
61
+ const evaluatedActor = await (0, pulse_utils_1.evaluateAndFlatten)(actorSource);
50
62
  if (evaluatedActor) {
51
63
  return evaluatedActor;
52
64
  }
@@ -54,7 +66,7 @@ const evaluateActor = async (eventInput = {}, builders = {}) => {
54
66
  // We allow an empty actor object, because it is a sign that the application is not setting nor updating Actor correctly.
55
67
  // Inferring "id: undefined" as a fallback would mask that bug.
56
68
  // Hence, the warning below.
57
- (0, warnOnce_1.default)('no-actor-builder-and-no-event-present', exports.WARN_CIS_SYNC_LOGIN_UNDEFINED);
69
+ (0, warnOnce_1.default)('no-actor-builder', exports.WARN_CIS_SYNC_LOGIN_UNDEFINED);
58
70
  return {};
59
71
  };
60
72
  exports.evaluateActor = evaluateActor;
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.requireCisSyncCallForAdvertisingIds = exports.cisSync = exports.clearCookieJweIfStale = void 0;
7
4
  const pulse_cis_sync_1 = require("@schibsted/pulse-cis-sync");
8
5
  Object.defineProperty(exports, "clearCookieJweIfStale", { enumerable: true, get: function () { return pulse_cis_sync_1.clearCookieJweIfStale; } });
9
- const version_json_1 = __importDefault(require("../version.json"));
6
+ const version_1 = require("../version");
10
7
  const actor_1 = require("./actor");
11
8
  const requireCisSyncCallForAdvertisingIds = () => {
12
9
  (0, pulse_cis_sync_1.resetRefreshAfter)(new Date());
@@ -48,14 +45,15 @@ const cisSync = async (data, builders, config) => {
48
45
  // _pulse2data cookie, or just not do the sync.
49
46
  //
50
47
  const actorPromise = (0, actor_1.evaluateActor)(data, builders);
51
- const { cisBaseUrl, cisEnabled, includeAdvertising: includeAdvertisingPromise, isHybrid, nativeJwe, providerId, trackerId, vendors, } = config || {};
48
+ const { adChoicesEnabled, cisBaseUrl, cisEnabled, includeAdvertising: includeAdvertisingPromise, isHybrid, nativeJwe, providerId, trackerId, vendors, } = config || {};
52
49
  const [includeAdvertising, actor] = await Promise.all([includeAdvertisingPromise, actorPromise]);
53
50
  const { id, realm } = actor;
54
51
  if (cisEnabled) {
55
52
  // @ts-expect-error
56
53
  return (0, pulse_cis_sync_1.syncWithCis)(
57
54
  // @ts-expect-error
58
- id, nativeJwe, cisBaseUrl, realm, providerId, isHybrid ? 'Hybrid' : 'Web', version_json_1.default.SDK_VERSION, {
55
+ id, nativeJwe, cisBaseUrl, realm, providerId, isHybrid ? 'Hybrid' : 'Web', version_1.SDK_VERSION, {
56
+ adChoicesEnabled,
59
57
  includeAdvertising,
60
58
  vendors,
61
59
  trackerId,
@@ -1,12 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_PAGE_LEAVE_EVENT = exports.DEFAULT_ACTIVITY_DURATION = void 0;
4
- const DEFAULT_ACTIVITY_DURATION = () => ({
5
- value: 0,
6
- interval: undefined,
7
- timeSinceLastActivity: 0,
8
- });
9
- exports.DEFAULT_ACTIVITY_DURATION = DEFAULT_ACTIVITY_DURATION;
3
+ exports.ACTIVITY_DURATION_LIMIT_MS = exports.DEFAULT_PAGE_LEAVE_EVENT = void 0;
10
4
  const DEFAULT_PAGE_LEAVE_EVENT = () => ({
11
5
  objectViewPercentage: 0,
12
6
  maxObjectViewPercentage: 0,
@@ -16,3 +10,4 @@ const DEFAULT_PAGE_LEAVE_EVENT = () => ({
16
10
  maxPageScrollPosition: 0,
17
11
  });
18
12
  exports.DEFAULT_PAGE_LEAVE_EVENT = DEFAULT_PAGE_LEAVE_EVENT;
13
+ exports.ACTIVITY_DURATION_LIMIT_MS = 30000;
@@ -56,19 +56,42 @@ let updateViewedContentListeners = [];
56
56
  let activityListeners = [];
57
57
  let resizeObserver = null;
58
58
  let throttledUpdateFn = (0, pulse_utils_1.throttle)(() => undefined, 0);
59
- let startTime = 0;
60
- let activityDuration = (0, constants_1.DEFAULT_ACTIVITY_DURATION)();
59
+ let durationStartTime = 0;
60
+ let activityStartTime = 0;
61
61
  let currentLeaveEvent = (0, constants_1.DEFAULT_PAGE_LEAVE_EVENT)();
62
62
  let additionalHeightBuilder;
63
+ /**
64
+ * Resolves a DOM element from either a CSS selector string or an Element instance.
65
+ */
66
+ function resolveDomElement(element) {
67
+ try {
68
+ return typeof element === 'string' ? document.querySelector(element) : element || null;
69
+ }
70
+ catch (e) {
71
+ logger.error('Error while resolving DOM element', e);
72
+ return null;
73
+ }
74
+ }
63
75
  /*
64
76
  Add leave tracking
65
77
  */
66
78
  function addTpaasLeaveTracking({ objectElement, pageElement, schema, objectResizable, heightBuilder, trackMethod, }) {
67
79
  function _addLeaveTracking() {
80
+ const objectDomElement = resolveDomElement(objectElement);
81
+ if (objectDomElement == null) {
82
+ logger.error('Could not find object element for leave tracking');
83
+ return;
84
+ }
85
+ let pageDomElement = resolveDomElement(pageElement);
86
+ if (pageDomElement == null) {
87
+ logger.warn('Could not find page element for leave tracking, defaulting to document.body');
88
+ pageDomElement = document.body;
89
+ }
68
90
  additionalHeightBuilder = heightBuilder;
69
91
  addTpaasLeaveListeners();
70
- addUpdateEventListeners(objectElement, pageElement || document.body, objectResizable);
71
- startTime = resetTime();
92
+ addUpdateEventListeners(objectDomElement, pageDomElement, objectResizable);
93
+ activityStartTime = resetTime();
94
+ durationStartTime = resetTime();
72
95
  currentLeaveSchema = schema;
73
96
  currentTrackMethod = trackMethod;
74
97
  logger.debug('addLeaveTracking:after:state', currentLeaveEvent);
@@ -160,12 +183,8 @@ function removeUpdateEventListeners() {
160
183
  */
161
184
  const resetEventDefaults = () => {
162
185
  currentLeaveEvent = (0, constants_1.DEFAULT_PAGE_LEAVE_EVENT)();
163
- startTime = resetTime();
164
- activityDuration = resetActivityDuration();
165
- };
166
- const resetActivityDuration = () => {
167
- clearInterval(activityDuration.interval);
168
- return (0, constants_1.DEFAULT_ACTIVITY_DURATION)();
186
+ durationStartTime = resetTime();
187
+ activityStartTime = resetTime();
169
188
  };
170
189
  const resetTpaasViewedContent = () => {
171
190
  currentLeaveEvent = (0, constants_1.DEFAULT_PAGE_LEAVE_EVENT)();
@@ -174,34 +193,41 @@ exports.resetTpaasViewedContent = resetTpaasViewedContent;
174
193
  const resetTime = () => Date.now();
175
194
  /*
176
195
  Send a Leave event only if Page Leave tracking is active in the SDK
177
- The event that is ultimately sent is a merge between the default event
178
- saved in this file and the event supplied by the brand, with preference going
179
- to the brand event. After the event has been sent, leave page tracking is removed
196
+ The event that is ultimately sent is the View event saved in the currentTrackMethod callback.
197
+ After the event has been sent, leave page tracking is removed
180
198
  and must be explicitly re-added if needed.
181
199
  */
182
- function trackTpaasActiveLeave() {
200
+ async function trackTpaasActiveLeave() {
183
201
  if (leaveTpaasTrackingIsActive()) {
184
- trackTpaasLeave();
202
+ await trackTpaasLeave();
185
203
  }
186
204
  }
187
205
  /*
188
206
  Send a Leave event regardless of whether Page Leave tracking is active in the SDK
189
- The event that is ultimately sent is a merge between the default event
190
- saved in this file and the event supplied by the brand, with preference going
191
- to the brand event. After the event has been sent, leave page tracking is removed
207
+ The event that is ultimately sent is the View event saved in the currentTrackMethod callback.
208
+ After the event has been sent, leave page tracking is removed
192
209
  and must be explicitly re-added if needed.
193
210
  */
194
- function trackTpaasLeave() {
211
+ async function trackTpaasLeave() {
195
212
  const leave = getTpaasLeaveObject();
196
- currentTrackMethod(leave);
213
+ // Capture currentTrackMethod and remove tracking synchronously before awaiting.
214
+ // If removal happened after the await, a new trackView* call arriving during the async
215
+ // gap would see tracking still active with the same schema and silently discard its
216
+ // new callback (e.g. a fresh leaveAudioBuilder), causing the next leave event to
217
+ // never fire or to use the wrong builder.
218
+ const trackMethod = currentTrackMethod;
197
219
  removeTpaasLeaveTracking();
220
+ await trackMethod(leave);
198
221
  }
199
222
  function getTpaasLeaveObject() {
200
223
  const endTime = Date.now();
201
- const duration = endTime - startTime;
224
+ // TPaaS leave event requires duration/activity to be at least 1ms, otherwise the event is rejected
225
+ // also, in practice, it's almost impossible to have an activity or duration of 0ms
226
+ const durationMs = Math.max(endTime - durationStartTime, 1);
227
+ const activityDurationMs = Math.max(Math.min(endTime - activityStartTime, constants_1.ACTIVITY_DURATION_LIMIT_MS), 1);
202
228
  const leave = {
203
- durationMs: duration,
204
- activityDurationMs: activityDuration.value,
229
+ durationMs,
230
+ activityDurationMs,
205
231
  ...currentLeaveEvent,
206
232
  };
207
233
  logger.debug('trackTpaasLeave: event', leave);
@@ -276,18 +302,10 @@ exports.calculateScrollPosition = calculateScrollPosition;
276
302
  'mousedown', 'mousemove', 'keydown', 'scroll' and/or 'touchstart' browser events.
277
303
  */
278
304
  function addUpdateActivityDurationListeners() {
279
- if (activityDuration.interval !== undefined) {
280
- // If the interval is already set, do not set it again
305
+ // if there are already listeners for activity, do not add more
306
+ if (activityListeners.length > 0) {
281
307
  return;
282
308
  }
283
- const interval = 1000;
284
- const activityTimeout = 30 * 1000;
285
- activityDuration.interval = window.setInterval(() => {
286
- activityDuration.timeSinceLastActivity += interval;
287
- if (activityDuration.timeSinceLastActivity < activityTimeout) {
288
- activityDuration.value += interval;
289
- }
290
- }, interval);
291
309
  const activityEvents = [
292
310
  types_1.BrowserEvents.SCROLL,
293
311
  types_1.BrowserEvents.MOUSEDOWN,
@@ -296,15 +314,9 @@ function addUpdateActivityDurationListeners() {
296
314
  types_1.BrowserEvents.TOUCHSTART,
297
315
  ];
298
316
  activityListeners = addEventListeners(activityEvents, () => {
299
- activityDuration = resetLastActivity(activityDuration);
317
+ activityStartTime = resetTime();
300
318
  }, { passive: true });
301
319
  }
302
- function resetLastActivity(activityDuration) {
303
- return {
304
- ...activityDuration,
305
- timeSinceLastActivity: 0,
306
- };
307
- }
308
320
  /*
309
321
  Add listeners to a set of browser events.
310
322
  */
@@ -37,15 +37,13 @@ exports.TPAAS_ALLOWED_METHODS = [
37
37
  'trackLeaveLandingpage',
38
38
  'trackLeaveListing',
39
39
  'trackLeaveLockedArticle',
40
- 'trackLeaveLockedAudio',
41
40
  'trackLeaveLockedAudioPage',
42
- 'trackLeaveLockedVideo',
43
41
  'trackLeaveLockedVideoPage',
44
42
  'trackLeavePage',
43
+ 'trackLeaveSportsPage',
45
44
  'trackLeaveVideoPage',
46
45
  'trackLeaveWeather',
47
46
  'trackViewArticle',
48
- 'trackViewAudio',
49
47
  'trackViewAudioPage',
50
48
  'trackViewError',
51
49
  'trackViewFrontpage',
@@ -53,15 +51,23 @@ exports.TPAAS_ALLOWED_METHODS = [
53
51
  'trackViewLandingpage',
54
52
  'trackViewListing',
55
53
  'trackViewLockedArticle',
56
- 'trackViewLockedAudio',
57
54
  'trackViewLockedAudioPage',
58
- 'trackViewLockedVideo',
59
55
  'trackViewLockedVideoPage',
60
56
  'trackViewPage',
57
+ 'trackViewSportsPage',
61
58
  'trackViewTitle',
62
- 'trackViewVideo',
63
59
  'trackViewVideoPage',
64
60
  'trackViewWeather',
61
+ // these are not TPaaS methods,
62
+ // but they're part of this list to not have to duplicate the tracker-tpaas-proxy.ts implementation in tracker-proxy.ts
63
+ 'trackLegacyViewArticle',
64
+ 'trackLegacyViewLoginPoster',
65
+ 'trackLegacyViewSalesPoster',
66
+ 'trackLegacyViewListing',
67
+ 'trackLegacyViewFrontpage',
68
+ 'trackLegacyViewPage',
69
+ 'trackLegacyViewUIElement',
70
+ 'trackLegacyClickUIElement',
65
71
  ];
66
72
  function isPulseProxyMessage(message) {
67
73
  return (message !== null &&
@@ -13,6 +13,11 @@ function startProxyProviderListener(tracker) {
13
13
  loglevel_1.default.debug('Proxy Provider - Not in browser environment, skipping message listener');
14
14
  return () => { };
15
15
  }
16
+ if (tracker.hasProxyListener) {
17
+ loglevel_1.default.debug('Proxy Provider - Message listener already registered for this tracker, skipping');
18
+ return () => { };
19
+ }
20
+ tracker.hasProxyListener = true;
16
21
  loglevel_1.default.debug('Proxy Provider - Added message listener for proxy provider');
17
22
  const listener = async (event) => {
18
23
  loglevel_1.default.debug('Proxy Provider - message received', event.data);
@@ -64,5 +69,6 @@ function startProxyProviderListener(tracker) {
64
69
  window.addEventListener('message', listener);
65
70
  return () => {
66
71
  window.removeEventListener('message', listener);
72
+ tracker.hasProxyListener = false;
67
73
  };
68
74
  }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SDK_VERSION = void 0;
4
+ // This file is auto-generated by bin/generate-version.js. Do not edit manually.
5
+ exports.SDK_VERSION = '8.0.0-rc.10';
@@ -16,14 +16,16 @@ class VisibilityObserver {
16
16
  * Uses {@link https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver | MutationObserver} to monitor the DOM for dynamically loaded content.
17
17
  * Callback is invoked only once per element.
18
18
  * @param selector The CSS selector for elements to track.
19
+ * @param options {ObserverOptions} Optional configuration for the observer.
20
+ * @param options.threshold Which ratio triggers the Observer callback.
19
21
  * @throws Error if called more than once.
20
22
  */
21
- observe(selector) {
23
+ observe(selector, { threshold = 0.67 }) {
22
24
  if (this.selector) {
23
25
  throw new Error(`Cannot observe selector ${selector}. A visibility observer has already been set up for selector ${this.selector}.`);
24
26
  }
25
27
  this.selector = selector;
26
- this.setupObservers();
28
+ this.setupObservers({ threshold });
27
29
  // biome-ignore lint/suspicious/useIterableCallbackReturn: -
28
30
  this.elements().forEach((elementToTrack) => this.observeIntersection(elementToTrack));
29
31
  }
@@ -33,14 +35,14 @@ class VisibilityObserver {
33
35
  elements() {
34
36
  return Array.from(document.querySelectorAll(this.selector));
35
37
  }
36
- // Initialize both observers and start watching for DOM changes
37
- setupObservers() {
38
- this.setupIntersectionObserver();
38
+ // Initialise both observers and start watching for DOM changes
39
+ setupObservers({ threshold }) {
40
+ this.setupIntersectionObserver({ threshold });
39
41
  this.setupMutationObserver();
40
42
  this.observeMutations();
41
43
  }
42
44
  // Create observer to detect when elements become visible in the viewport
43
- setupIntersectionObserver() {
45
+ setupIntersectionObserver({ threshold }) {
44
46
  this.intersectionObserver = new IntersectionObserver((entries) => {
45
47
  entries.forEach((entry) => {
46
48
  if (entry.isIntersecting) {
@@ -49,7 +51,7 @@ class VisibilityObserver {
49
51
  this.intersectionObserver.unobserve(node);
50
52
  }
51
53
  });
52
- }, { threshold: 2 / 3 });
54
+ }, { threshold });
53
55
  }
54
56
  // Create observer to detect DOM changes that may add/remove tracked elements
55
57
  setupMutationObserver() {
@@ -1,2 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isLegacyPageType = isLegacyPageType;
4
+ const LEGACY_PAGE_TYPE_VALUES = ['Article', 'Listing', 'Frontpage', 'SalesPoster', 'Page', 'LoginPoster'];
5
+ function isLegacyPageType(value) {
6
+ return LEGACY_PAGE_TYPE_VALUES.includes(value);
7
+ }