@schibsted/pulse-sdk 8.0.0-rc.4 → 8.0.0-rc.6

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 (35) hide show
  1. package/dist/cjs/Tracker.js +75 -188
  2. package/dist/cjs/builders/actor.js +3 -3
  3. package/dist/cjs/identity/actor.js +18 -6
  4. package/dist/cjs/leaveTrackingTpaas/constants.js +2 -7
  5. package/dist/cjs/leaveTrackingTpaas/index.js +52 -40
  6. package/dist/cjs/tracker-proxy/consts.js +2 -7
  7. package/dist/cjs/version.js +1 -1
  8. package/dist/ejs/Tracker.js +77 -190
  9. package/dist/ejs/builders/actor.js +2 -2
  10. package/dist/ejs/identity/actor.js +19 -7
  11. package/dist/ejs/leaveTrackingTpaas/constants.js +1 -5
  12. package/dist/ejs/leaveTrackingTpaas/index.js +53 -41
  13. package/dist/ejs/tracker-proxy/consts.js +2 -7
  14. package/dist/ejs/version.js +1 -1
  15. package/dist/types/Tracker.d.ts +18 -56
  16. package/dist/types/builders/actor.d.ts +3 -2
  17. package/dist/types/identity/actor.d.ts +2 -2
  18. package/dist/types/identity/cis.d.ts +1 -1
  19. package/dist/types/index.d.ts +1 -1
  20. package/dist/types/leaveTrackingTpaas/constants.d.ts +1 -5
  21. package/dist/types/leaveTrackingTpaas/index.d.ts +6 -6
  22. package/dist/types/leaveTrackingTpaas/types.d.ts +1 -9
  23. package/dist/types/tracker-proxy/consts.d.ts +1 -1
  24. package/dist/types/types.d.ts +19 -13
  25. package/dist/types/version.d.ts +1 -1
  26. package/node_modules/@schibsted/pulse-utils/package.json +1 -1
  27. package/node_modules/@schibsted/tpaas-event-builder/dist/cjs/builders/catalogVersion.js +9 -0
  28. package/node_modules/@schibsted/tpaas-event-builder/dist/cjs/builders.js +63 -78
  29. package/node_modules/@schibsted/tpaas-event-builder/dist/ejs/builders/catalogVersion.js +6 -0
  30. package/node_modules/@schibsted/tpaas-event-builder/dist/ejs/builders.js +64 -72
  31. package/node_modules/@schibsted/tpaas-event-builder/dist/index.d.ts +607 -1018
  32. package/node_modules/@schibsted/tpaas-schemas/dist/cjs/constants.js +67 -109
  33. package/node_modules/@schibsted/tpaas-schemas/dist/ejs/constants.js +65 -107
  34. package/node_modules/@schibsted/tpaas-schemas/dist/index.d.ts +722 -1215
  35. package/package.json +2 -2
@@ -1,6 +1,6 @@
1
1
  import { isBrowser, isFunction, throttle } from '@schibsted/pulse-utils';
2
2
  import * as logger from 'loglevel';
3
- import { DEFAULT_ACTIVITY_DURATION, DEFAULT_PAGE_LEAVE_EVENT } from './constants';
3
+ import { ACTIVITY_DURATION_LIMIT_MS, DEFAULT_PAGE_LEAVE_EVENT } from './constants';
4
4
  import { BrowserEvents } from './types';
5
5
  let currentLeaveSchema;
6
6
  let currentTrackMethod;
@@ -9,19 +9,42 @@ let updateViewedContentListeners = [];
9
9
  let activityListeners = [];
10
10
  let resizeObserver = null;
11
11
  let throttledUpdateFn = throttle(() => undefined, 0);
12
- let startTime = 0;
13
- let activityDuration = DEFAULT_ACTIVITY_DURATION();
12
+ let durationStartTime = 0;
13
+ let activityStartTime = 0;
14
14
  let currentLeaveEvent = DEFAULT_PAGE_LEAVE_EVENT();
15
15
  let additionalHeightBuilder;
16
+ /**
17
+ * Resolves a DOM element from either a CSS selector string or an Element instance.
18
+ */
19
+ function resolveDomElement(element) {
20
+ try {
21
+ return typeof element === 'string' ? document.querySelector(element) : element || null;
22
+ }
23
+ catch (e) {
24
+ logger.error('Error while resolving DOM element', e);
25
+ return null;
26
+ }
27
+ }
16
28
  /*
17
29
  Add leave tracking
18
30
  */
19
31
  export function addTpaasLeaveTracking({ objectElement, pageElement, schema, objectResizable, heightBuilder, trackMethod, }) {
20
32
  function _addLeaveTracking() {
33
+ const objectDomElement = resolveDomElement(objectElement);
34
+ if (objectDomElement == null) {
35
+ logger.error('Could not find object element for leave tracking');
36
+ return;
37
+ }
38
+ let pageDomElement = resolveDomElement(pageElement);
39
+ if (pageDomElement == null) {
40
+ logger.warn('Could not find page element for leave tracking, defaulting to document.body');
41
+ pageDomElement = document.body;
42
+ }
21
43
  additionalHeightBuilder = heightBuilder;
22
44
  addTpaasLeaveListeners();
23
- addUpdateEventListeners(objectElement, pageElement || document.body, objectResizable);
24
- startTime = resetTime();
45
+ addUpdateEventListeners(objectDomElement, pageDomElement, objectResizable);
46
+ activityStartTime = resetTime();
47
+ durationStartTime = resetTime();
25
48
  currentLeaveSchema = schema;
26
49
  currentTrackMethod = trackMethod;
27
50
  logger.debug('addLeaveTracking:after:state', currentLeaveEvent);
@@ -113,12 +136,8 @@ function removeUpdateEventListeners() {
113
136
  */
114
137
  const resetEventDefaults = () => {
115
138
  currentLeaveEvent = DEFAULT_PAGE_LEAVE_EVENT();
116
- startTime = resetTime();
117
- activityDuration = resetActivityDuration();
118
- };
119
- const resetActivityDuration = () => {
120
- clearInterval(activityDuration.interval);
121
- return DEFAULT_ACTIVITY_DURATION();
139
+ durationStartTime = resetTime();
140
+ activityStartTime = resetTime();
122
141
  };
123
142
  export const resetTpaasViewedContent = () => {
124
143
  currentLeaveEvent = DEFAULT_PAGE_LEAVE_EVENT();
@@ -126,34 +145,41 @@ export const resetTpaasViewedContent = () => {
126
145
  const resetTime = () => Date.now();
127
146
  /*
128
147
  Send a Leave event only if Page Leave tracking is active in the SDK
129
- The event that is ultimately sent is a merge between the default event
130
- saved in this file and the event supplied by the brand, with preference going
131
- to the brand event. After the event has been sent, leave page tracking is removed
148
+ The event that is ultimately sent is the View event saved in the currentTrackMethod callback.
149
+ After the event has been sent, leave page tracking is removed
132
150
  and must be explicitly re-added if needed.
133
151
  */
134
- export function trackTpaasActiveLeave() {
152
+ export async function trackTpaasActiveLeave() {
135
153
  if (leaveTpaasTrackingIsActive()) {
136
- trackTpaasLeave();
154
+ await trackTpaasLeave();
137
155
  }
138
156
  }
139
157
  /*
140
158
  Send a Leave event regardless of whether Page Leave tracking is active in the SDK
141
- The event that is ultimately sent is a merge between the default event
142
- saved in this file and the event supplied by the brand, with preference going
143
- to the brand event. After the event has been sent, leave page tracking is removed
159
+ The event that is ultimately sent is the View event saved in the currentTrackMethod callback.
160
+ After the event has been sent, leave page tracking is removed
144
161
  and must be explicitly re-added if needed.
145
162
  */
146
- export function trackTpaasLeave() {
163
+ export async function trackTpaasLeave() {
147
164
  const leave = getTpaasLeaveObject();
148
- currentTrackMethod(leave);
165
+ // Capture currentTrackMethod and remove tracking synchronously before awaiting.
166
+ // If removal happened after the await, a new trackView* call arriving during the async
167
+ // gap would see tracking still active with the same schema and silently discard its
168
+ // new callback (e.g. a fresh leaveAudioBuilder), causing the next leave event to
169
+ // never fire or to use the wrong builder.
170
+ const trackMethod = currentTrackMethod;
149
171
  removeTpaasLeaveTracking();
172
+ await trackMethod(leave);
150
173
  }
151
174
  export function getTpaasLeaveObject() {
152
175
  const endTime = Date.now();
153
- const duration = endTime - startTime;
176
+ // TPaaS leave event requires duration/activity to be at least 1ms, otherwise the event is rejected
177
+ // also, in practice, it's almost impossible to have an activity or duration of 0ms
178
+ const durationMs = Math.max(endTime - durationStartTime, 1);
179
+ const activityDurationMs = Math.max(Math.min(endTime - activityStartTime, ACTIVITY_DURATION_LIMIT_MS), 1);
154
180
  const leave = {
155
- durationMs: duration,
156
- activityDurationMs: activityDuration.value,
181
+ durationMs,
182
+ activityDurationMs,
157
183
  ...currentLeaveEvent,
158
184
  };
159
185
  logger.debug('trackTpaasLeave: event', leave);
@@ -226,18 +252,10 @@ export const calculateScrollPosition = (element) => Math.abs(Math.min(element.ge
226
252
  'mousedown', 'mousemove', 'keydown', 'scroll' and/or 'touchstart' browser events.
227
253
  */
228
254
  function addUpdateActivityDurationListeners() {
229
- if (activityDuration.interval !== undefined) {
230
- // If the interval is already set, do not set it again
255
+ // if there are already listeners for activity, do not add more
256
+ if (activityListeners.length > 0) {
231
257
  return;
232
258
  }
233
- const interval = 1000;
234
- const activityTimeout = 30 * 1000;
235
- activityDuration.interval = window.setInterval(() => {
236
- activityDuration.timeSinceLastActivity += interval;
237
- if (activityDuration.timeSinceLastActivity < activityTimeout) {
238
- activityDuration.value += interval;
239
- }
240
- }, interval);
241
259
  const activityEvents = [
242
260
  BrowserEvents.SCROLL,
243
261
  BrowserEvents.MOUSEDOWN,
@@ -246,15 +264,9 @@ function addUpdateActivityDurationListeners() {
246
264
  BrowserEvents.TOUCHSTART,
247
265
  ];
248
266
  activityListeners = addEventListeners(activityEvents, () => {
249
- activityDuration = resetLastActivity(activityDuration);
267
+ activityStartTime = resetTime();
250
268
  }, { passive: true });
251
269
  }
252
- function resetLastActivity(activityDuration) {
253
- return {
254
- ...activityDuration,
255
- timeSinceLastActivity: 0,
256
- };
257
- }
258
270
  /*
259
271
  Add listeners to a set of browser events.
260
272
  */
@@ -18,7 +18,6 @@ export const TPAAS_ALLOWED_METHODS = [
18
18
  'trackEngagementVideoAd',
19
19
  'trackEngagementWidget',
20
20
  'trackCompletedHealthAction',
21
- 'trackImpressionAdSlot',
22
21
  'trackImpressionForm',
23
22
  'trackImpressionHealthUIElement',
24
23
  'trackImpressionOffer',
@@ -33,15 +32,13 @@ export const TPAAS_ALLOWED_METHODS = [
33
32
  'trackLeaveLandingpage',
34
33
  'trackLeaveListing',
35
34
  'trackLeaveLockedArticle',
36
- 'trackLeaveLockedAudio',
37
35
  'trackLeaveLockedAudioPage',
38
- 'trackLeaveLockedVideo',
39
36
  'trackLeaveLockedVideoPage',
40
37
  'trackLeavePage',
38
+ 'trackLeaveSportsPage',
41
39
  'trackLeaveVideoPage',
42
40
  'trackLeaveWeather',
43
41
  'trackViewArticle',
44
- 'trackViewAudio',
45
42
  'trackViewAudioPage',
46
43
  'trackViewError',
47
44
  'trackViewFrontpage',
@@ -49,13 +46,11 @@ export const TPAAS_ALLOWED_METHODS = [
49
46
  'trackViewLandingpage',
50
47
  'trackViewListing',
51
48
  'trackViewLockedArticle',
52
- 'trackViewLockedAudio',
53
49
  'trackViewLockedAudioPage',
54
- 'trackViewLockedVideo',
55
50
  'trackViewLockedVideoPage',
56
51
  'trackViewPage',
52
+ 'trackViewSportsPage',
57
53
  'trackViewTitle',
58
- 'trackViewVideo',
59
54
  'trackViewVideoPage',
60
55
  'trackViewWeather',
61
56
  // these are not TPaaS methods,
@@ -1,2 +1,2 @@
1
1
  // This file is auto-generated by bin/generate-version.js. Do not edit manually.
2
- export const SDK_VERSION = '8.0.0-rc.4';
2
+ export const SDK_VERSION = '8.0.0-rc.6';
@@ -1,6 +1,6 @@
1
1
  import { type AdvertisingIdentifiers, type AdvertisingVendor } from '@schibsted/pulse-cis-sync';
2
2
  import { getCommonBuildersOutput, type InputParams } from '@schibsted/tpaas-event-builder';
3
- import { type IAnonymousViewUIElement, type ICompletedHealthAction, type IEngagementAudio, type IEngagementForm, type IEngagementHealthUIElement, type IEngagementOffer, type IEngagementTeaser, type IEngagementUIElement, type IEngagementVideo, type IEngagementVideoAd, type IEngagementWidget, type IImpressionAdSlot, type IImpressionForm, type IImpressionHealthUIElement, type IImpressionOffer, type IImpressionPlayer, type IImpressionTeaser, type IImpressionUIElement, type IImpressionWidget, type ILeave, type ILeaveArticle, type ILeaveAudioPage, type ILeaveError, type ILeaveFrontpage, type ILeaveLandingpage, type ILeaveListing, type ILeaveLockedArticle, type ILeaveLockedAudio, type ILeaveLockedAudioPage, type ILeaveLockedVideo, type ILeaveLockedVideoPage, type ILeavePage, type ILeaveSportsPage, type ILeaveVideoPage, type ILeaveWeather, type ITpaasEvent, type IViewArticle, type IViewAudio, type IViewAudioPage, type IViewError, type IViewFrontpage, type IViewHealthPage, type IViewLandingpage, type IViewListing, type IViewLockedArticle, type IViewLockedAudio, type IViewLockedAudioPage, type IViewLockedVideo, type IViewLockedVideoPage, type IViewPage, type IViewSportsPage, type IViewTitle, type IViewVideo, type IViewVideoPage, type IViewWeather } from '@schibsted/tpaas-schemas';
3
+ import { type IAnonymousViewUIElement, type ICompletedHealthAction, type IEngagementAudio, type IEngagementForm, type IEngagementHealthUIElement, type IEngagementOffer, type IEngagementTeaser, type IEngagementUIElement, type IEngagementVideo, type IEngagementVideoAd, type IEngagementWidget, type IImpressionForm, type IImpressionHealthUIElement, type IImpressionOffer, type IImpressionPlayer, type IImpressionTeaser, type IImpressionUIElement, type IImpressionWidget, type ILeave, type ILeaveArticle, type ILeaveAudioPage, type ILeaveError, type ILeaveFrontpage, type ILeaveLandingpage, type ILeaveListing, type ILeaveLockedArticle, type ILeaveLockedAudioPage, type ILeaveLockedVideoPage, type ILeavePage, type ILeaveSportsPage, type ILeaveVideoPage, type ILeaveWeather, type ITpaasEvent, type IViewArticle, type IViewAudioPage, type IViewError, type IViewFrontpage, type IViewHealthPage, type IViewLandingpage, type IViewListing, type IViewLockedArticle, type IViewLockedAudioPage, type IViewLockedVideoPage, type IViewPage, type IViewSportsPage, type IViewTitle, type IViewVideoPage, type IViewWeather } from '@schibsted/tpaas-schemas';
4
4
  import logger from 'loglevel';
5
5
  import type { ActorInput, Consents, ConsentsInput, DeviceInput, LocationInput, ObjectInput, OriginInput, ProviderInput, TrackerInput } from './builders';
6
6
  import { engagementEvent, identityEvent, routableEvent, trackerEvent } from './builders/events';
@@ -8,7 +8,7 @@ import { anonymousEngagementEvent, anonymousTrackerEvent } from './builders/even
8
8
  import type { Deferred, ResolvedInput } from './defer';
9
9
  import { type Listener } from './EventBus/EventBus';
10
10
  import type { LeaveEvent, LeaveEventBuilder, LeaveEventOptions } from './leaveTracking/types';
11
- import type { AnonymousEventInputTypesByTrackingMethod, EventInput, EventInputTypesByTrackingMethod, TrackViewAudioPageOptions, TrackViewEventOptions, TrackViewVideoPageOptions } from './types';
11
+ import type { AnonymousEventInputTypesByTrackingMethod, EventInput, EventInputTypesByTrackingMethod, TrackViewEventOptions } from './types';
12
12
  import type { ClickUIElementInputProperties } from './wrapper/engagement/ui-element/types';
13
13
  import type { BaseEventExperiment } from './wrapper/types';
14
14
  import type { ViewArticleInputProperties } from './wrapper/view/article/types';
@@ -376,7 +376,6 @@ export default class Tracker {
376
376
  */
377
377
  private prepareAnonymousTpaasEvent;
378
378
  /**
379
- *
380
379
  * @private
381
380
  * @category TPaaS Tracking
382
381
  */
@@ -549,20 +548,20 @@ export default class Tracker {
549
548
  private setCurrentPage;
550
549
  trackCompletedHealthAction(input: InputParams<ICompletedHealthAction>): Promise<unknown>;
551
550
  trackEngagementHealthUIElement(input: InputParams<IEngagementHealthUIElement>): Promise<unknown>;
552
- trackViewHealthPage(input: InputParams<IViewHealthPage>, options: TrackViewEventOptions): Promise<unknown>;
551
+ trackViewHealthPage(input: InputParams<IViewHealthPage>, options: TrackViewEventOptions<IViewHealthPage>): Promise<unknown>;
553
552
  trackImpressionHealthUIElement(input: InputParams<IImpressionHealthUIElement>): Promise<unknown>;
554
553
  /**
555
554
  * @param input
556
555
  * @param options
557
556
  * @category TPaaS Tracking
558
557
  */
559
- trackViewPage(input: InputParams<IViewPage>, options: TrackViewEventOptions): Promise<unknown>;
558
+ trackViewPage(input: InputParams<IViewPage>, options: TrackViewEventOptions<IViewPage>): Promise<unknown>;
560
559
  /**
561
560
  * @param input
562
561
  * @param options
563
562
  * @category TPaaS Tracking
564
563
  */
565
- trackViewSportsPage(input: InputParams<IViewSportsPage>, options: TrackViewEventOptions): Promise<unknown>;
564
+ trackViewSportsPage(input: InputParams<IViewSportsPage>, options: TrackViewEventOptions<IViewSportsPage>): Promise<unknown>;
566
565
  /**
567
566
  * @param input
568
567
  * @category TPaaS Tracking
@@ -573,23 +572,12 @@ export default class Tracker {
573
572
  * @category TPaaS Tracking
574
573
  */
575
574
  trackImpressionWidget(input: InputParams<IImpressionWidget>): Promise<unknown>;
576
- /**
577
- * @param input
578
- * @category TPaaS Tracking
579
- */
580
- trackImpressionAdSlot(input: InputParams<IImpressionAdSlot>): Promise<unknown>;
581
- /**
582
- * @param input
583
- * @param options
584
- * @category TPaaS Tracking
585
- */
586
- trackViewArticle(input: InputParams<IViewArticle>, options: TrackViewEventOptions): Promise<unknown>;
587
575
  /**
588
576
  * @param input
589
577
  * @param options
590
578
  * @category TPaaS Tracking
591
579
  */
592
- trackViewAudio(input: InputParams<IViewAudio>): Promise<unknown>;
580
+ trackViewArticle(input: InputParams<IViewArticle>, options: TrackViewEventOptions<IViewArticle>): Promise<unknown>;
593
581
  /**
594
582
  * Tracks a View AudioPage event and automatically fires a Leave AudioPage event when the user
595
583
  * navigates away.
@@ -630,13 +618,13 @@ export default class Tracker {
630
618
  * @param options
631
619
  * @category TPaaS Tracking
632
620
  */
633
- trackViewAudioPage(input: InputParams<IViewAudioPage>, options: TrackViewAudioPageOptions): Promise<unknown>;
621
+ trackViewAudioPage(input: InputParams<IViewAudioPage>, options: TrackViewEventOptions<IViewAudioPage>): Promise<unknown>;
634
622
  /**
635
623
  * @param input
636
624
  * @param options
637
625
  * @category TPaaS Tracking
638
626
  */
639
- trackViewError(input: InputParams<IViewError>, options: TrackViewEventOptions): Promise<unknown>;
627
+ trackViewError(input: InputParams<IViewError>, options: TrackViewEventOptions<IViewError>): Promise<unknown>;
640
628
  /**
641
629
  * @param input
642
630
  * @category TPaaS Tracking
@@ -667,53 +655,37 @@ export default class Tracker {
667
655
  * @param options
668
656
  * @category TPaaS Tracking
669
657
  */
670
- trackViewFrontpage(input: InputParams<IViewFrontpage>, options: TrackViewEventOptions): Promise<unknown>;
658
+ trackViewFrontpage(input: InputParams<IViewFrontpage>, options: TrackViewEventOptions<IViewFrontpage>): Promise<unknown>;
671
659
  /**
672
660
  * @param input
673
661
  * @param options
674
662
  * @category TPaaS Tracking
675
663
  */
676
- trackViewLandingpage(input: InputParams<IViewLandingpage>, options: TrackViewEventOptions): Promise<unknown>;
664
+ trackViewLandingpage(input: InputParams<IViewLandingpage>, options: TrackViewEventOptions<IViewLandingpage>): Promise<unknown>;
677
665
  /**
678
666
  * @param input
679
667
  * @param options
680
668
  * @category TPaaS Tracking
681
669
  */
682
- trackViewListing(input: InputParams<IViewListing>, options: TrackViewEventOptions): Promise<unknown>;
670
+ trackViewListing(input: InputParams<IViewListing>, options: TrackViewEventOptions<IViewListing>): Promise<unknown>;
683
671
  /**
684
672
  * @param input
685
673
  * @param options
686
674
  * @category TPaaS Tracking
687
675
  */
688
- trackViewLockedArticle(input: InputParams<IViewLockedArticle>, options: TrackViewEventOptions): Promise<unknown>;
676
+ trackViewLockedArticle(input: InputParams<IViewLockedArticle>, options: TrackViewEventOptions<IViewLockedArticle>): Promise<unknown>;
689
677
  /**
690
678
  * @param input
691
679
  * @param options
692
680
  * @category TPaaS Tracking
693
681
  */
694
- trackViewLockedAudio(input: InputParams<IViewLockedAudio>): Promise<unknown>;
682
+ trackViewLockedAudioPage(input: InputParams<IViewLockedAudioPage>, options: TrackViewEventOptions<IViewLockedAudioPage>): Promise<unknown>;
695
683
  /**
696
684
  * @param input
697
685
  * @param options
698
686
  * @category TPaaS Tracking
699
687
  */
700
- trackViewLockedAudioPage(input: InputParams<IViewLockedAudioPage>, options: TrackViewEventOptions): Promise<unknown>;
701
- /**
702
- * @param input
703
- * @category TPaaS Tracking
704
- */
705
- trackViewLockedVideo(input: InputParams<IViewLockedVideo>): Promise<unknown>;
706
- /**
707
- * @param input
708
- * @param options
709
- * @category TPaaS Tracking
710
- */
711
- trackViewLockedVideoPage(input: InputParams<IViewLockedVideoPage>, options: TrackViewEventOptions): Promise<unknown>;
712
- /**
713
- * @param input
714
- * @category TPaaS Tracking
715
- */
716
- trackViewVideo(input: InputParams<IViewVideo>): Promise<unknown>;
688
+ trackViewLockedVideoPage(input: InputParams<IViewLockedVideoPage>, options: TrackViewEventOptions<IViewLockedVideoPage>): Promise<unknown>;
717
689
  /**
718
690
  * Tracks a View VideoPage event and automatically fires a Leave VideoPage event when the user
719
691
  * navigates away.
@@ -756,13 +728,13 @@ export default class Tracker {
756
728
  * @param options
757
729
  * @category TPaaS Tracking
758
730
  */
759
- trackViewVideoPage(input: InputParams<IViewVideoPage>, options: TrackViewVideoPageOptions): Promise<unknown>;
731
+ trackViewVideoPage(input: InputParams<IViewVideoPage>, options: TrackViewEventOptions<IViewVideoPage>): Promise<unknown>;
760
732
  /**
761
733
  * @param input
762
734
  * @param options
763
735
  * @category TPaaS Tracking
764
736
  */
765
- trackViewWeather(input: InputParams<IViewWeather>, options: TrackViewEventOptions): Promise<unknown>;
737
+ trackViewWeather(input: InputParams<IViewWeather>, options: TrackViewEventOptions<IViewWeather>): Promise<unknown>;
766
738
  /**
767
739
  * @param input
768
740
  * @category TPaaS Tracking
@@ -798,21 +770,11 @@ export default class Tracker {
798
770
  * @category TPaaS Tracking
799
771
  */
800
772
  trackLeaveLockedArticle(input: InputParams<ILeaveLockedArticle>): Promise<unknown>;
801
- /**
802
- * @param input
803
- * @category TPaaS Tracking
804
- */
805
- trackLeaveLockedAudio(input: InputParams<ILeaveLockedAudio>): Promise<unknown>;
806
773
  /**
807
774
  * @param input
808
775
  * @category TPaaS Tracking
809
776
  */
810
777
  trackLeaveLockedAudioPage(input: InputParams<ILeaveLockedAudioPage>): Promise<unknown>;
811
- /**
812
- * @param input
813
- * @category TPaaS Tracking
814
- */
815
- trackLeaveLockedVideo(input: InputParams<ILeaveLockedVideo>): Promise<unknown>;
816
778
  /**
817
779
  * @param input
818
780
  * @category TPaaS Tracking
@@ -1069,7 +1031,7 @@ export default class Tracker {
1069
1031
  * @internal
1070
1032
  * @category Configuration
1071
1033
  */
1072
- syncRemoteResources(input?: unknown, builders?: Builders): Promise<{
1034
+ syncRemoteResources(input?: Partial<Builders>, builders?: Builders): Promise<{
1073
1035
  adId?: string;
1074
1036
  doTracking: boolean;
1075
1037
  environmentId?: string;
@@ -1281,7 +1243,7 @@ export default class Tracker {
1281
1243
  * with the added guarantee that a second Leave event will not be triggered if one already has been sent.
1282
1244
  * @category TPaaS Leave Tracking
1283
1245
  */
1284
- trackTpaasActiveLeave(): void;
1246
+ trackTpaasActiveLeave(): Promise<void>;
1285
1247
  /**
1286
1248
  * Check if leave tracking is enabled (if an event will be sent when the user leaves the page)
1287
1249
  * ```
@@ -1,3 +1,4 @@
1
+ import type { Builders } from '../Tracker';
1
2
  import type { TrackerEventInput } from './events';
2
3
  /**
3
4
  * generateActorSDRN
@@ -24,11 +25,11 @@ export type Actor = {
24
25
  'spt:userId': string;
25
26
  };
26
27
  /**
27
- * Type guard to check if the input is an ActorInput
28
+ * Type guard to check if the input has an Actor Builder
28
29
  * @param input
29
30
  * @internal
30
31
  */
31
- export declare function isActorInput(input: unknown): input is ActorInput;
32
+ export declare function hasActorBuilder(input: unknown): input is Pick<Builders, 'actor'>;
32
33
  /**
33
34
  * Function to generate a builder for Actor objects.
34
35
  */
@@ -3,7 +3,7 @@ import type { Builders } from '../Tracker';
3
3
  /**
4
4
  * @internal exported for testing
5
5
  */
6
- export declare const WARN_CIS_SYNC_LOGIN_UNDEFINED: string;
6
+ export declare const 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.";
7
7
  /**
8
8
  * Get the actor id (userId) from the current browser. A promise is returned
9
9
  * because a call may be made to complete the login process.
@@ -24,5 +24,5 @@ declare const userIsLoggedIn: (builders: Builders) => Promise<boolean>;
24
24
  * @category Tracker
25
25
  * @private
26
26
  */
27
- declare const evaluateActor: (eventInput?: unknown, builders?: Builders) => Promise<ActorInput>;
27
+ declare const evaluateActor: (eventInput?: Partial<Builders>, builders?: Builders) => Promise<ActorInput>;
28
28
  export { getUserId, getActor, userIsLoggedIn, evaluateActor };
@@ -12,7 +12,7 @@ declare const requireCisSyncCallForAdvertisingIds: () => void;
12
12
  * @returns the parsed pulse cookie after syncing with cis.
13
13
  * @category Identifiers
14
14
  */
15
- declare const cisSync: (data?: unknown, builders?: Builders, config?: SDKState) => Promise<{
15
+ declare const cisSync: (data?: Partial<Builders>, builders?: Builders, config?: SDKState) => Promise<{
16
16
  adId?: string;
17
17
  doTracking: boolean;
18
18
  environmentId?: string;
@@ -15,7 +15,7 @@ export { subscribe, subscribeOnce, subscribeWithState, unsubscribe } from './Tra
15
15
  /**
16
16
  * TPaaS specific type exports
17
17
  */
18
- export type { AudioPageLeaveTrackingOptions, LeaveAudioInput, LeaveStoriesInput, LeaveTrackingDisabled, LeaveTrackingOptions, TrackViewAudioPageOptions, TrackViewEventOptions, TrackViewVideoPageOptions, VideoPageLeaveTrackingOptions, } from './types';
18
+ export type { LeaveAudioInput, LeaveStoriesInput, LeaveTrackingDisabled, LeaveTrackingOptions, TrackViewEventOptions, TrackViewEventOptionsForProxy, } from './types';
19
19
  /**
20
20
  * Media Wrapper Types exports below
21
21
  */
@@ -1,8 +1,3 @@
1
- export declare const DEFAULT_ACTIVITY_DURATION: () => {
2
- value: number;
3
- interval: undefined;
4
- timeSinceLastActivity: number;
5
- };
6
1
  export declare const DEFAULT_PAGE_LEAVE_EVENT: () => {
7
2
  objectViewPercentage: number;
8
3
  maxObjectViewPercentage: number;
@@ -11,3 +6,4 @@ export declare const DEFAULT_PAGE_LEAVE_EVENT: () => {
11
6
  pageScrollPosition: number;
12
7
  maxPageScrollPosition: number;
13
8
  };
9
+ export declare const ACTIVITY_DURATION_LIMIT_MS = 30000;
@@ -1,7 +1,7 @@
1
- import type { ILeave } from '@schibsted/tpaas-schemas';
2
- import type { LeaveTrackingOptions, TrackViewEventOptions } from '../types';
1
+ import type { ILeave, ITpaasEvent } from '@schibsted/tpaas-schemas';
2
+ import type { LeaveTrackingOptions, LeaveTrackingOptionsForProxy, TrackViewEventOptions } from '../types';
3
3
  import type { LeaveObjectTypes, Listener, TrackMethod } from './types';
4
- export declare function addTpaasLeaveTracking({ objectElement, pageElement, schema, objectResizable, heightBuilder, trackMethod, }: LeaveTrackingOptions & {
4
+ export declare function addTpaasLeaveTracking({ objectElement, pageElement, schema, objectResizable, heightBuilder, trackMethod, }: (LeaveTrackingOptions | LeaveTrackingOptionsForProxy) & {
5
5
  schema: LeaveObjectTypes;
6
6
  trackMethod: TrackMethod;
7
7
  }): void;
@@ -15,8 +15,8 @@ export declare function removeTpaasLeaveTracking(): void;
15
15
  */
16
16
  export declare function updateTpaasLeaveTracking(objectElement: Element, pageElement: Element, resetProperties: boolean): void;
17
17
  export declare const resetTpaasViewedContent: () => void;
18
- export declare function trackTpaasActiveLeave(): void;
19
- export declare function trackTpaasLeave(): void;
18
+ export declare function trackTpaasActiveLeave(): Promise<void>;
19
+ export declare function trackTpaasLeave(): Promise<void>;
20
20
  export declare function getTpaasLeaveObject(): ILeave;
21
21
  export declare function updateTpaasViewedContent(objectElement: Element, pageElement: Element): void;
22
22
  export declare const calculateScrolledPixels: (element: Element) => number;
@@ -25,4 +25,4 @@ export declare function addEventListeners(events: string[], handler: () => void,
25
25
  export declare function removeEventListeners(eventListeners: Listener[], options?: {
26
26
  capture?: boolean;
27
27
  }): Listener[];
28
- export declare function shouldEnableLeaveTracking(leaveOptions: TrackViewEventOptions['leaveTracking']): leaveOptions is LeaveTrackingOptions;
28
+ export declare function shouldEnableLeaveTracking(leaveOptions: TrackViewEventOptions<ITpaasEvent>['leaveTracking']): leaveOptions is LeaveTrackingOptions | LeaveTrackingOptionsForProxy;
@@ -15,14 +15,6 @@ export declare enum BrowserEvents {
15
15
  TOUCHSTART = "touchstart"
16
16
  }
17
17
  export type Listener = [name: string, listener: () => void];
18
- /**
19
- * @typedef ActivityDuration
20
- */
21
- export type ActivityDuration = {
22
- value: number;
23
- interval: number | undefined;
24
- timeSinceLastActivity: number;
25
- };
26
18
  /**
27
19
  * Used to provide extra height to view %-calculations for objects that have fake-scrolls or similar
28
20
  * For instance if you have an element that captures scroll for about 1000px
@@ -39,7 +31,7 @@ export interface AdditionalHeightInfo {
39
31
  */
40
32
  viewedHeight: number;
41
33
  }
42
- export type TrackMethod = (leave: ILeave) => void;
34
+ export type TrackMethod = (leave: ILeave) => Promise<void>;
43
35
  export type LeaveObjectTypes = Extract<ITpaasEvent, {
44
36
  eventType: 'Leave';
45
37
  }>['object']['objectType'];
@@ -17,7 +17,7 @@ export declare const MESSAGE_TYPE_INVOKE = "pulse-tracker-proxy:invoke";
17
17
  export declare const MESSAGE_TYPE_RETURN = "pulse-tracker-proxy:return";
18
18
  export declare const MESSAGE_TYPE_RETURN_ERROR = "pulse-tracker-proxy:return-error";
19
19
  export declare const ALLOWED_METHODS: readonly ["track"];
20
- export declare const TPAAS_ALLOWED_METHODS: readonly ["trackAnonymousViewUIElement", "trackEngagementAudio", "trackEngagementForm", "trackEngagementHealthUIElement", "trackEngagementOffer", "trackEngagementTeaser", "trackEngagementUIElement", "trackEngagementVideo", "trackEngagementVideoAd", "trackEngagementWidget", "trackCompletedHealthAction", "trackImpressionAdSlot", "trackImpressionForm", "trackImpressionHealthUIElement", "trackImpressionOffer", "trackImpressionPlayer", "trackImpressionTeaser", "trackImpressionUIElement", "trackImpressionWidget", "trackLeaveArticle", "trackLeaveAudioPage", "trackLeaveError", "trackLeaveFrontpage", "trackLeaveLandingpage", "trackLeaveListing", "trackLeaveLockedArticle", "trackLeaveLockedAudio", "trackLeaveLockedAudioPage", "trackLeaveLockedVideo", "trackLeaveLockedVideoPage", "trackLeavePage", "trackLeaveVideoPage", "trackLeaveWeather", "trackViewArticle", "trackViewAudio", "trackViewAudioPage", "trackViewError", "trackViewFrontpage", "trackViewHealthPage", "trackViewLandingpage", "trackViewListing", "trackViewLockedArticle", "trackViewLockedAudio", "trackViewLockedAudioPage", "trackViewLockedVideo", "trackViewLockedVideoPage", "trackViewPage", "trackViewTitle", "trackViewVideo", "trackViewVideoPage", "trackViewWeather", "trackLegacyViewArticle", "trackLegacyViewLoginPoster", "trackLegacyViewSalesPoster", "trackLegacyViewListing", "trackLegacyViewFrontpage", "trackLegacyViewPage", "trackLegacyViewUIElement", "trackLegacyClickUIElement"];
20
+ export declare const TPAAS_ALLOWED_METHODS: readonly ["trackAnonymousViewUIElement", "trackEngagementAudio", "trackEngagementForm", "trackEngagementHealthUIElement", "trackEngagementOffer", "trackEngagementTeaser", "trackEngagementUIElement", "trackEngagementVideo", "trackEngagementVideoAd", "trackEngagementWidget", "trackCompletedHealthAction", "trackImpressionForm", "trackImpressionHealthUIElement", "trackImpressionOffer", "trackImpressionPlayer", "trackImpressionTeaser", "trackImpressionUIElement", "trackImpressionWidget", "trackLeaveArticle", "trackLeaveAudioPage", "trackLeaveError", "trackLeaveFrontpage", "trackLeaveLandingpage", "trackLeaveListing", "trackLeaveLockedArticle", "trackLeaveLockedAudioPage", "trackLeaveLockedVideoPage", "trackLeavePage", "trackLeaveSportsPage", "trackLeaveVideoPage", "trackLeaveWeather", "trackViewArticle", "trackViewAudioPage", "trackViewError", "trackViewFrontpage", "trackViewHealthPage", "trackViewLandingpage", "trackViewListing", "trackViewLockedArticle", "trackViewLockedAudioPage", "trackViewLockedVideoPage", "trackViewPage", "trackViewSportsPage", "trackViewTitle", "trackViewVideoPage", "trackViewWeather", "trackLegacyViewArticle", "trackLegacyViewLoginPoster", "trackLegacyViewSalesPoster", "trackLegacyViewListing", "trackLegacyViewFrontpage", "trackLegacyViewPage", "trackLegacyViewUIElement", "trackLegacyClickUIElement"];
21
21
  export declare function isPulseProxyMessage(message: unknown): message is Message;
22
22
  export type TrackInvocation = {
23
23
  method: 'track';
@@ -1,4 +1,4 @@
1
- import type { ILeaveAudio, ILeaveStories } from '@schibsted/tpaas-schemas';
1
+ import type { ILeaveAudio, ILeaveStories, ITpaasEvent, IViewAudioPage, IViewVideoPage } from '@schibsted/tpaas-schemas';
2
2
  import type { v4 } from 'uuid';
3
3
  import type { Session } from './builders';
4
4
  import type { AnonymousTrackerEventInput } from './builders/events-anonymous-node';
@@ -53,41 +53,47 @@ export type LeaveAudioInput = Omit<ILeaveAudio, 'activityDurationMs' | 'duration
53
53
  * metrics when the Leave VideoPage event fires.
54
54
  */
55
55
  export type LeaveStoriesInput = Omit<ILeaveStories, 'activityDurationMs' | 'durationMs'>;
56
- export type TrackViewEventOptions = {
57
- leaveTracking: LeaveTrackingOptions | LeaveTrackingDisabled;
56
+ export type TrackViewEventOptions<T extends ITpaasEvent> = {
57
+ leaveTracking: LeaveTrackingDisabled | LeaveTrackingOptionsForProxy | (T extends IViewAudioPage ? AudioPageLeaveTrackingOptions : T extends IViewVideoPage ? VideoPageLeaveTrackingOptions : LeaveTrackingOptions);
58
+ };
59
+ export type TrackViewEventOptionsForProxy = {
60
+ leaveTracking: LeaveTrackingDisabled | LeaveTrackingOptionsForProxy;
58
61
  };
59
62
  export type LeaveTrackingOptions = {
60
- objectElement: HTMLElement;
61
- pageElement?: HTMLElement;
63
+ objectElement: Element;
64
+ pageElement?: Element;
62
65
  objectResizable?: boolean;
63
66
  heightBuilder?: () => AdditionalHeightInfo;
64
67
  };
68
+ export type LeaveTrackingOptionsForProxy = {
69
+ objectElement: string;
70
+ pageElement?: string;
71
+ objectResizable?: boolean;
72
+ heightBuilder?: never;
73
+ leaveAudioBuilder?: never;
74
+ leaveStoriesBuilder?: never;
75
+ };
65
76
  export type LeaveTrackingDisabled = false;
66
77
  /**
67
78
  * Leave tracking options for {@link Tracker.trackViewAudioPage}.
68
79
  * Extends {@link LeaveTrackingOptions} with an optional builder for audio engagement statistics.
69
80
  */
70
- export type AudioPageLeaveTrackingOptions = LeaveTrackingOptions & {
81
+ type AudioPageLeaveTrackingOptions = LeaveTrackingOptions & {
71
82
  /**
72
83
  * Called at leave time to provide audio engagement statistics for the Leave AudioPage event.
73
84
  * If not provided, all audio engagement fields default to `0`.
74
85
  */
75
86
  leaveAudioBuilder?: () => LeaveAudioInput;
76
87
  };
77
- export type TrackViewAudioPageOptions = {
78
- leaveTracking: AudioPageLeaveTrackingOptions | LeaveTrackingDisabled;
79
- };
80
88
  /**
81
89
  * Leave tracking options for {@link Tracker.trackViewVideoPage}.
82
90
  * Extends {@link LeaveTrackingOptions} with an optional builder for story carousel statistics.
83
91
  */
84
- export type VideoPageLeaveTrackingOptions = LeaveTrackingOptions & {
92
+ type VideoPageLeaveTrackingOptions = LeaveTrackingOptions & {
85
93
  /**
86
94
  * Called at leave time to provide story carousel statistics for the Leave VideoPage event.
87
95
  * If not provided, `leaveStories` will be omitted from the Leave VideoPage event.
88
96
  */
89
97
  leaveStoriesBuilder?: () => LeaveStoriesInput;
90
98
  };
91
- export type TrackViewVideoPageOptions = {
92
- leaveTracking: VideoPageLeaveTrackingOptions | LeaveTrackingDisabled;
93
- };
99
+ export {};
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "8.0.0-rc.4";
1
+ export declare const SDK_VERSION = "8.0.0-rc.6";
@@ -30,7 +30,7 @@
30
30
  "devDependencies": {
31
31
  "@types/lodash": "4.17.24",
32
32
  "@types/node": "24.10.13",
33
- "lodash": "4.17.23",
33
+ "lodash": "4.18.1",
34
34
  "typescript": "5.9.3"
35
35
  }
36
36
  }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.builder = builder;
4
+ const tpaas_schemas_1 = require("@schibsted/tpaas-schemas");
5
+ function builder() {
6
+ return {
7
+ catalogVersion: tpaas_schemas_1.CATALOG_VERSION,
8
+ };
9
+ }