@schibsted/pulse-sdk 8.0.0-rc.5 → 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.
@@ -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
@@ -578,7 +577,7 @@ export default class Tracker {
578
577
  * @param options
579
578
  * @category TPaaS Tracking
580
579
  */
581
- trackViewArticle(input: InputParams<IViewArticle>, options: TrackViewEventOptions): Promise<unknown>;
580
+ trackViewArticle(input: InputParams<IViewArticle>, options: TrackViewEventOptions<IViewArticle>): Promise<unknown>;
582
581
  /**
583
582
  * Tracks a View AudioPage event and automatically fires a Leave AudioPage event when the user
584
583
  * navigates away.
@@ -619,13 +618,13 @@ export default class Tracker {
619
618
  * @param options
620
619
  * @category TPaaS Tracking
621
620
  */
622
- trackViewAudioPage(input: InputParams<IViewAudioPage>, options: TrackViewAudioPageOptions): Promise<unknown>;
621
+ trackViewAudioPage(input: InputParams<IViewAudioPage>, options: TrackViewEventOptions<IViewAudioPage>): Promise<unknown>;
623
622
  /**
624
623
  * @param input
625
624
  * @param options
626
625
  * @category TPaaS Tracking
627
626
  */
628
- trackViewError(input: InputParams<IViewError>, options: TrackViewEventOptions): Promise<unknown>;
627
+ trackViewError(input: InputParams<IViewError>, options: TrackViewEventOptions<IViewError>): Promise<unknown>;
629
628
  /**
630
629
  * @param input
631
630
  * @category TPaaS Tracking
@@ -656,37 +655,37 @@ export default class Tracker {
656
655
  * @param options
657
656
  * @category TPaaS Tracking
658
657
  */
659
- trackViewFrontpage(input: InputParams<IViewFrontpage>, options: TrackViewEventOptions): Promise<unknown>;
658
+ trackViewFrontpage(input: InputParams<IViewFrontpage>, options: TrackViewEventOptions<IViewFrontpage>): Promise<unknown>;
660
659
  /**
661
660
  * @param input
662
661
  * @param options
663
662
  * @category TPaaS Tracking
664
663
  */
665
- trackViewLandingpage(input: InputParams<IViewLandingpage>, options: TrackViewEventOptions): Promise<unknown>;
664
+ trackViewLandingpage(input: InputParams<IViewLandingpage>, options: TrackViewEventOptions<IViewLandingpage>): Promise<unknown>;
666
665
  /**
667
666
  * @param input
668
667
  * @param options
669
668
  * @category TPaaS Tracking
670
669
  */
671
- trackViewListing(input: InputParams<IViewListing>, options: TrackViewEventOptions): Promise<unknown>;
670
+ trackViewListing(input: InputParams<IViewListing>, options: TrackViewEventOptions<IViewListing>): Promise<unknown>;
672
671
  /**
673
672
  * @param input
674
673
  * @param options
675
674
  * @category TPaaS Tracking
676
675
  */
677
- trackViewLockedArticle(input: InputParams<IViewLockedArticle>, options: TrackViewEventOptions): Promise<unknown>;
676
+ trackViewLockedArticle(input: InputParams<IViewLockedArticle>, options: TrackViewEventOptions<IViewLockedArticle>): Promise<unknown>;
678
677
  /**
679
678
  * @param input
680
679
  * @param options
681
680
  * @category TPaaS Tracking
682
681
  */
683
- trackViewLockedAudioPage(input: InputParams<IViewLockedAudioPage>, options: TrackViewEventOptions): Promise<unknown>;
682
+ trackViewLockedAudioPage(input: InputParams<IViewLockedAudioPage>, options: TrackViewEventOptions<IViewLockedAudioPage>): Promise<unknown>;
684
683
  /**
685
684
  * @param input
686
685
  * @param options
687
686
  * @category TPaaS Tracking
688
687
  */
689
- trackViewLockedVideoPage(input: InputParams<IViewLockedVideoPage>, options: TrackViewEventOptions): Promise<unknown>;
688
+ trackViewLockedVideoPage(input: InputParams<IViewLockedVideoPage>, options: TrackViewEventOptions<IViewLockedVideoPage>): Promise<unknown>;
690
689
  /**
691
690
  * Tracks a View VideoPage event and automatically fires a Leave VideoPage event when the user
692
691
  * navigates away.
@@ -729,13 +728,13 @@ export default class Tracker {
729
728
  * @param options
730
729
  * @category TPaaS Tracking
731
730
  */
732
- trackViewVideoPage(input: InputParams<IViewVideoPage>, options: TrackViewVideoPageOptions): Promise<unknown>;
731
+ trackViewVideoPage(input: InputParams<IViewVideoPage>, options: TrackViewEventOptions<IViewVideoPage>): Promise<unknown>;
733
732
  /**
734
733
  * @param input
735
734
  * @param options
736
735
  * @category TPaaS Tracking
737
736
  */
738
- trackViewWeather(input: InputParams<IViewWeather>, options: TrackViewEventOptions): Promise<unknown>;
737
+ trackViewWeather(input: InputParams<IViewWeather>, options: TrackViewEventOptions<IViewWeather>): Promise<unknown>;
739
738
  /**
740
739
  * @param input
741
740
  * @category TPaaS Tracking
@@ -1244,7 +1243,7 @@ export default class Tracker {
1244
1243
  * with the added guarantee that a second Leave event will not be triggered if one already has been sent.
1245
1244
  * @category TPaaS Leave Tracking
1246
1245
  */
1247
- trackTpaasActiveLeave(): void;
1246
+ trackTpaasActiveLeave(): Promise<void>;
1248
1247
  /**
1249
1248
  * Check if leave tracking is enabled (if an event will be sent when the user leaves the page)
1250
1249
  * ```
@@ -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", "trackImpressionForm", "trackImpressionHealthUIElement", "trackImpressionOffer", "trackImpressionPlayer", "trackImpressionTeaser", "trackImpressionUIElement", "trackImpressionWidget", "trackLeaveArticle", "trackLeaveAudioPage", "trackLeaveError", "trackLeaveFrontpage", "trackLeaveLandingpage", "trackLeaveListing", "trackLeaveLockedArticle", "trackLeaveLockedAudioPage", "trackLeaveLockedVideoPage", "trackLeavePage", "trackLeaveVideoPage", "trackLeaveWeather", "trackViewArticle", "trackViewAudioPage", "trackViewError", "trackViewFrontpage", "trackViewHealthPage", "trackViewLandingpage", "trackViewListing", "trackViewLockedArticle", "trackViewLockedAudioPage", "trackViewLockedVideoPage", "trackViewPage", "trackViewTitle", "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.5";
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
  }
@@ -4941,7 +4941,7 @@ type DeepOmit<T, K extends string> = T extends readonly unknown[] ? T : T extend
4941
4941
  } extends infer Result ? {
4942
4942
  [P in keyof Result as Result[P] extends Record<string, never> ? never : P]: Result[P];
4943
4943
  } : never : T;
4944
- type OptionalNavigationType<T extends ITpaasEvent> = T extends {
4944
+ type OptionalNavigationType<T> = T extends {
4945
4945
  page: {
4946
4946
  navigationType: infer N;
4947
4947
  };
@@ -4949,6 +4949,14 @@ type OptionalNavigationType<T extends ITpaasEvent> = T extends {
4949
4949
  page: Omit<T["page"], "navigationType"> & {
4950
4950
  navigationType?: N;
4951
4951
  };
4952
+ } : T extends {
4953
+ page?: {
4954
+ navigationType: infer N;
4955
+ };
4956
+ } ? Omit<T, "page"> & {
4957
+ page?: Omit<NonNullable<T["page"]>, "navigationType"> & {
4958
+ navigationType?: N;
4959
+ };
4952
4960
  } : T;
4953
4961
  /**
4954
4962
  * InputParams is a utility type that omits certain properties from a given type T.
@@ -4957,7 +4965,7 @@ type OptionalNavigationType<T extends ITpaasEvent> = T extends {
4957
4965
  *
4958
4966
  * @privateRemarks
4959
4967
  */
4960
- export type InputParams<T extends ITpaasEvent> = DeepOmit<WithOptionalPage<OptionalNavigationType<T>>, OmittedProperties>;
4968
+ export type InputParams<T extends ITpaasEvent> = DeepOmit<OptionalNavigationType<WithOptionalPage<T>>, OmittedProperties>;
4961
4969
  type WithOptionalPage<T> = T extends TpaasOptionalPageSchemas ? Omit<T, "page"> & {
4962
4970
  page?: T["page"];
4963
4971
  } : T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schibsted/pulse-sdk",
3
- "version": "8.0.0-rc.5",
3
+ "version": "8.0.0-rc.6",
4
4
  "description": "Node.js / Browser Pulse SDK",
5
5
  "author": "Schibsted Data&Tech",
6
6
  "license": "UNLICENSED",
@@ -42,10 +42,10 @@
42
42
  "ts-deepmerge": "7.0.3",
43
43
  "ua-parser-js": "2.0.9",
44
44
  "uuid": "13.0.0",
45
+ "@schibsted/tpaas-event-builder": "1.0.0",
45
46
  "@schibsted/pulse-cis-sync": "2.0.18",
46
47
  "@schibsted/pulse-utils": "1.0.2",
47
- "@schibsted/tpaas-schemas": "1.0.0",
48
- "@schibsted/tpaas-event-builder": "1.0.0"
48
+ "@schibsted/tpaas-schemas": "1.0.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@testing-library/dom": "10.4.1",