@schibsted/pulse-sdk 8.0.0-rc.20 → 8.0.0-rc.21

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 (74) hide show
  1. package/dist/cjs/Tracker.js +170 -334
  2. package/dist/cjs/builders/session-browser.js +4 -79
  3. package/dist/cjs/session/store.js +96 -0
  4. package/dist/cjs/tpaas-builders/builders/device.js +42 -70
  5. package/dist/cjs/tpaas-builders/builders/pageInfo.js +2 -3
  6. package/dist/cjs/tpaas-builders/builders/session.js +2 -114
  7. package/dist/cjs/tpaas-builders/builders/utm.js +2 -8
  8. package/dist/cjs/tpaas-builders/builders.js +135 -148
  9. package/dist/cjs/tpaas-context/adapters.js +85 -0
  10. package/dist/cjs/tpaas-context/browser.js +51 -0
  11. package/dist/cjs/tpaas-context/index.js +6 -0
  12. package/dist/cjs/tpaas-context/prepare.js +177 -0
  13. package/dist/cjs/tpaas-context/session.js +23 -0
  14. package/dist/cjs/tpaas-schemas/constants.js +68 -75
  15. package/dist/cjs/tracker-proxy/consts.js +1 -2
  16. package/dist/cjs/version.js +1 -1
  17. package/dist/ejs/Tracker.js +171 -335
  18. package/dist/ejs/builders/session-browser.js +4 -77
  19. package/dist/ejs/session/store.js +90 -0
  20. package/dist/ejs/tpaas-builders/builders/device.js +42 -70
  21. package/dist/ejs/tpaas-builders/builders/pageInfo.js +2 -3
  22. package/dist/ejs/tpaas-builders/builders/session.js +1 -111
  23. package/dist/ejs/tpaas-builders/builders/utm.js +2 -8
  24. package/dist/ejs/tpaas-builders/builders.js +135 -147
  25. package/dist/ejs/tpaas-context/adapters.js +80 -0
  26. package/dist/ejs/tpaas-context/browser.js +47 -0
  27. package/dist/ejs/tpaas-context/index.js +1 -0
  28. package/dist/ejs/tpaas-context/prepare.js +137 -0
  29. package/dist/ejs/tpaas-context/session.js +19 -0
  30. package/dist/ejs/tpaas-schemas/constants.js +66 -73
  31. package/dist/ejs/tracker-proxy/consts.js +1 -2
  32. package/dist/ejs/version.js +1 -1
  33. package/dist/types/Tracker.d.ts +27 -23
  34. package/dist/types/builders/session-browser.d.ts +0 -13
  35. package/dist/types/session/store.d.ts +34 -0
  36. package/dist/types/tpaas-builders/builders/consents.d.ts +2 -2
  37. package/dist/types/tpaas-builders/builders/device.d.ts +2 -2
  38. package/dist/types/tpaas-builders/builders/experiments.d.ts +2 -2
  39. package/dist/types/tpaas-builders/builders/pageInfo.d.ts +2 -1
  40. package/dist/types/tpaas-builders/builders/pageviewId.d.ts +2 -2
  41. package/dist/types/tpaas-builders/builders/provider.d.ts +2 -2
  42. package/dist/types/tpaas-builders/builders/session.d.ts +1 -12
  43. package/dist/types/tpaas-builders/builders/trackerBuilder.d.ts +2 -2
  44. package/dist/types/tpaas-builders/builders/user.d.ts +2 -2
  45. package/dist/types/tpaas-builders/builders/utm.d.ts +2 -1
  46. package/dist/types/tpaas-builders/builders.d.ts +70 -70
  47. package/dist/types/tpaas-builders/index.d.ts +0 -1
  48. package/dist/types/tpaas-context/adapters.d.ts +26 -0
  49. package/dist/types/tpaas-context/browser.d.ts +8 -0
  50. package/dist/types/tpaas-context/index.d.ts +2 -0
  51. package/dist/types/tpaas-context/prepare.d.ts +38 -0
  52. package/dist/types/tpaas-context/session.d.ts +10 -0
  53. package/dist/types/tpaas-context/types.d.ts +66 -0
  54. package/dist/types/tpaas-schemas/constants.d.ts +66 -73
  55. package/dist/types/tpaas-schemas/types/ITpaasEvent.d.ts +2 -4
  56. package/dist/types/tpaas-schemas/types/schemas/{IAnonymousViewUIElement.d.ts → IAnonymousImpressionUIElement.d.ts} +2 -2
  57. package/dist/types/tpaas-schemas/types/schemas/IEngagementAudio.d.ts +6 -2
  58. package/dist/types/tpaas-schemas/types/schemas/IEngagementTeaser.d.ts +2 -2
  59. package/dist/types/tpaas-schemas/types/schemas/IEngagementTvModule.d.ts +4 -1
  60. package/dist/types/tpaas-schemas/types/schemas/IEngagementTvSearch.d.ts +4 -4
  61. package/dist/types/tpaas-schemas/types/schemas/IEngagementVideo.d.ts +6 -2
  62. package/dist/types/tpaas-schemas/types/schemas/IEngagementVideoAd.d.ts +10 -8
  63. package/dist/types/tpaas-schemas/types/schemas/IImpressionTeaser.d.ts +2 -2
  64. package/dist/types/tpaas-schemas/types/schemas/ILeaveWeather.d.ts +2 -0
  65. package/dist/types/tpaas-schemas/types/schemas/index.d.ts +1 -2
  66. package/dist/types/tpaas-schemas/types.d.ts +2 -2
  67. package/dist/types/tracker-proxy/consts.d.ts +1 -1
  68. package/dist/types/types.d.ts +2 -4
  69. package/dist/types/version.d.ts +1 -1
  70. package/package.json +1 -1
  71. package/dist/types/tpaas-builders/types.d.ts +0 -36
  72. package/dist/types/tpaas-schemas/types/schemas/IRequestAd.d.ts +0 -95
  73. /package/dist/cjs/{tpaas-builders → tpaas-context}/types.js +0 -0
  74. /package/dist/ejs/{tpaas-builders → tpaas-context}/types.js +0 -0
@@ -1,5 +1,5 @@
1
1
  import { merge } from 'ts-deepmerge';
2
- import { AnonymousViewUIElement, CompletedHealthAction, EngagementAd, EngagementAffiliate, EngagementAudio, EngagementForm, EngagementHealthUIElement, EngagementOffer, EngagementSchoolUIElement, EngagementSportsUIElement, EngagementTeaser, EngagementTvModule, EngagementTvSearch, EngagementUIElement, EngagementVideo, EngagementVideoAd, EngagementWidget, HeartbeatCommercialArticle, ImpressionAd, ImpressionAdSlot, ImpressionAffiliate, ImpressionForm, ImpressionHealthUIElement, ImpressionOffer, ImpressionPlayer, ImpressionSchoolUIElement, ImpressionSportsUIElement, ImpressionTeaser, ImpressionUIElement, ImpressionWidget, LeaveArticle, LeaveAudioPage, LeaveError, LeaveFrontpage, LeaveLandingpage, LeaveListing, LeaveLockedArticle, LeaveLockedAudioPage, LeaveLockedPage, LeaveLockedVideoPage, LeavePage, LeaveSchoolPage, LeaveSportsPage, LeaveVideoPage, LeaveWeather, LoadAd, RequestAd, ViewArticle, ViewAudioPage, ViewError, ViewFrontpage, ViewHealthPage, ViewLandingpage, ViewListing, ViewLockedArticle, ViewLockedAudioPage, ViewLockedPage, ViewLockedVideoPage, ViewPage, ViewSchoolPage, ViewSportsPage, ViewTitle, ViewVideoPage, ViewWeather, } from '../tpaas-schemas';
2
+ import { AnonymousImpressionUIElement, CompletedHealthAction, EngagementAd, EngagementAffiliate, EngagementAudio, EngagementForm, EngagementHealthUIElement, EngagementOffer, EngagementSchoolUIElement, EngagementSportsUIElement, EngagementTeaser, EngagementTvModule, EngagementTvSearch, EngagementUIElement, EngagementVideo, EngagementVideoAd, EngagementWidget, HeartbeatCommercialArticle, ImpressionAd, ImpressionAdSlot, ImpressionAffiliate, ImpressionForm, ImpressionHealthUIElement, ImpressionOffer, ImpressionPlayer, ImpressionSchoolUIElement, ImpressionSportsUIElement, ImpressionTeaser, ImpressionUIElement, ImpressionWidget, LeaveArticle, LeaveAudioPage, LeaveError, LeaveFrontpage, LeaveLandingpage, LeaveListing, LeaveLockedArticle, LeaveLockedAudioPage, LeaveLockedPage, LeaveLockedVideoPage, LeavePage, LeaveSchoolPage, LeaveSportsPage, LeaveVideoPage, LeaveWeather, LoadAd, ViewArticle, ViewAudioPage, ViewError, ViewFrontpage, ViewHealthPage, ViewLandingpage, ViewListing, ViewLockedArticle, ViewLockedAudioPage, ViewLockedPage, ViewLockedVideoPage, ViewPage, ViewSchoolPage, ViewSportsPage, ViewTitle, ViewVideoPage, ViewWeather, } from '../tpaas-schemas';
3
3
  import { builder as anonymousBuilder } from './builders/anonymous';
4
4
  import { builder as baseEventBuilder } from './builders/baseEvent';
5
5
  import { builder as catalogVersionBuilder } from './builders/catalogVersion';
@@ -18,19 +18,13 @@ import { builder as timeBuilder } from './builders/time';
18
18
  import { builder as trackerBuilder } from './builders/trackerBuilder';
19
19
  import { builder as userBuilder } from './builders/user';
20
20
  import { builder as utmBuilder } from './builders/utm';
21
- /**
22
- * Common builders output to be merged into all events
23
- * @param createdAt
24
- * @param dependencies {TpaasEventBuilderDependencies}
25
- * @private
26
- */
27
- export const getCommonBuildersOutput = (createdAt, dependencies, input) => {
28
- const { isHybrid, version, environmentId, jwe, user, consents, providerId, providerName, providerGroup, providerStage, providerProduct, providerVersion, component, componentVersion, pageviewId, currentPage, currentPageReferrer, routingStage, } = dependencies;
29
- const { experiments } = input;
30
- return merge(trackerBuilder({ isHybrid, version, routingStage }), timeBuilder(createdAt), sessionBuilder(createdAt), deviceBuilder(environmentId, jwe), userBuilder(user), baseEventBuilder(), consentsBuilder(consents), providerBuilder(providerId, providerStage, providerProduct, providerVersion, component, componentVersion, providerName, providerGroup), pageInfoBuilder(currentPage), pageviewIdBuilder(pageviewId), utmBuilder(), referrerBuilder(currentPageReferrer), catalogVersionBuilder(), experimentsBuilder(dependencies.experiments, experiments));
21
+ export const getCommonBuildersOutput = (context) => {
22
+ const { createdAt, session, isHybrid, version, environmentId, jwe, user, consents, providerId, providerName, providerGroup, providerStage, providerProduct, providerVersion, component, componentVersion, pageviewId, currentPage, currentPageReferrer, routingStage, browser, } = context;
23
+ const { experiments } = context.input;
24
+ return merge(trackerBuilder({ isHybrid, version, routingStage }), timeBuilder(createdAt), sessionBuilder(session), deviceBuilder(environmentId, jwe, browser), userBuilder(user), baseEventBuilder(), consentsBuilder(consents), providerBuilder(providerId, providerStage, providerProduct, providerVersion, component, componentVersion, providerName, providerGroup), pageInfoBuilder(currentPage, browser.url), pageviewIdBuilder(pageviewId), utmBuilder(browser.search), referrerBuilder(currentPageReferrer), catalogVersionBuilder(), experimentsBuilder(context.experiments, experiments));
31
25
  };
32
- const getElementEventBuildersOutput = (createdAt, dependencies, input) => merge(getCommonBuildersOutput(createdAt, dependencies, input), pageContentBuilder(dependencies.currentPageContent));
33
- const getSportsElementEventBuildersOutput = (createdAt, dependencies, input) => merge(getElementEventBuildersOutput(createdAt, dependencies, input), pageSportsBuilder(dependencies.currentPageSports));
26
+ const getElementEventBuildersOutput = (context) => merge(getCommonBuildersOutput(context), pageContentBuilder(context.currentPageContent));
27
+ const getSportsElementEventBuildersOutput = (context) => merge(getElementEventBuildersOutput(context), pageSportsBuilder(context.currentPageSports));
34
28
  // there's a bug in the ts-deepmerge library that doesn't properly resolve merging optionals with required properties
35
29
  // due to this, we need to do 2 things:
36
30
  // (1) manually omit navigationType from the input before merging.
@@ -57,215 +51,209 @@ const normalizePageInput = (input) => {
57
51
  },
58
52
  };
59
53
  };
60
- // #region AnonymousView Event Builders
61
- export function buildAnonymousViewUIElementEvent(input, dependencies) {
62
- const createdAt = new Date();
63
- const { isHybrid, version, pageviewId, providerId, providerName, providerGroup, providerStage, providerProduct, providerVersion, component, componentVersion, currentPageReferrer, routingStage, } = dependencies;
64
- return merge(AnonymousViewUIElement, baseEventBuilder(), trackerBuilder({ isHybrid, version, routingStage }), timeBuilder(createdAt), pageviewIdBuilder(pageviewId), utmBuilder(), anonymousBuilder(), providerBuilder(providerId, providerStage, providerProduct, providerVersion, component, componentVersion, providerName, providerGroup), referrerBuilder(currentPageReferrer), experimentsBuilder(dependencies.experiments, input.experiments), catalogVersionBuilder(), normalizePageInput(input));
54
+ // #region AnonymousImpression Event Builders
55
+ export function buildAnonymousImpressionUIElementEvent(context) {
56
+ const { createdAt, isHybrid, version, pageviewId, providerId, providerName, providerGroup, providerStage, providerProduct, providerVersion, component, componentVersion, currentPageReferrer, routingStage, } = context;
57
+ return merge(AnonymousImpressionUIElement, baseEventBuilder(), trackerBuilder({ isHybrid, version, routingStage }), timeBuilder(createdAt), pageviewIdBuilder(pageviewId), utmBuilder(context.browser.search), anonymousBuilder(), providerBuilder(providerId, providerStage, providerProduct, providerVersion, component, componentVersion, providerName, providerGroup), referrerBuilder(currentPageReferrer), experimentsBuilder(context.experiments, context.input.experiments), catalogVersionBuilder(), normalizePageInput(context.input));
65
58
  }
66
59
  // #endregion
67
60
  // #region View Event Builders
68
- export function buildViewArticleEvent(input, dependencies) {
69
- return merge(ViewArticle, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
61
+ export function buildViewArticleEvent(context) {
62
+ return merge(ViewArticle, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
70
63
  }
71
- export function buildViewAudioPageEvent(input, dependencies) {
72
- return merge(ViewAudioPage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
64
+ export function buildViewAudioPageEvent(context) {
65
+ return merge(ViewAudioPage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
73
66
  }
74
- export function buildViewErrorEvent(input, dependencies) {
75
- return merge(ViewError, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
67
+ export function buildViewErrorEvent(context) {
68
+ return merge(ViewError, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
76
69
  }
77
- export function buildViewFrontpageEvent(input, dependencies) {
78
- return merge(ViewFrontpage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
70
+ export function buildViewFrontpageEvent(context) {
71
+ return merge(ViewFrontpage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
79
72
  }
80
- export function buildViewLandingpageEvent(input, dependencies) {
81
- return merge(ViewLandingpage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
73
+ export function buildViewLandingpageEvent(context) {
74
+ return merge(ViewLandingpage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
82
75
  }
83
- export function buildViewListingEvent(input, dependencies) {
84
- return merge(ViewListing, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
76
+ export function buildViewListingEvent(context) {
77
+ return merge(ViewListing, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
85
78
  }
86
- export function buildViewLockedArticleEvent(input, dependencies) {
87
- return merge(ViewLockedArticle, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
79
+ export function buildViewLockedArticleEvent(context) {
80
+ return merge(ViewLockedArticle, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
88
81
  }
89
- export function buildViewLockedAudioPageEvent(input, dependencies) {
90
- return merge(ViewLockedAudioPage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
82
+ export function buildViewLockedAudioPageEvent(context) {
83
+ return merge(ViewLockedAudioPage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
91
84
  }
92
- export function buildViewLockedPageEvent(input, dependencies) {
93
- return merge(ViewLockedPage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
85
+ export function buildViewLockedPageEvent(context) {
86
+ return merge(ViewLockedPage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
94
87
  }
95
- export function buildViewLockedVideoPageEvent(input, dependencies) {
96
- return merge(ViewLockedVideoPage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
88
+ export function buildViewLockedVideoPageEvent(context) {
89
+ return merge(ViewLockedVideoPage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
97
90
  }
98
- export function buildLeaveLockedVideoPageEvent(input, dependencies) {
99
- return merge(LeaveLockedVideoPage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
91
+ export function buildLeaveLockedVideoPageEvent(context) {
92
+ return merge(LeaveLockedVideoPage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
100
93
  }
101
- export function buildViewPageEvent(input, dependencies) {
102
- return merge(ViewPage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
94
+ export function buildViewPageEvent(context) {
95
+ return merge(ViewPage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
103
96
  }
104
- export function buildViewSportsPageEvent(input, dependencies) {
105
- return merge(ViewSportsPage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
97
+ export function buildViewSportsPageEvent(context) {
98
+ return merge(ViewSportsPage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
106
99
  }
107
- export function buildViewSchoolPageEvent(input, dependencies) {
108
- return merge(ViewSchoolPage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
100
+ export function buildViewSchoolPageEvent(context) {
101
+ return merge(ViewSchoolPage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
109
102
  }
110
- export function buildViewTitleEvent(input, dependencies) {
111
- return merge(ViewTitle, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
103
+ export function buildViewTitleEvent(context) {
104
+ return merge(ViewTitle, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
112
105
  }
113
- export function buildViewVideoPageEvent(input, dependencies) {
114
- return merge(ViewVideoPage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
106
+ export function buildViewVideoPageEvent(context) {
107
+ return merge(ViewVideoPage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
115
108
  }
116
- export function buildViewWeatherEvent(input, dependencies) {
117
- return merge(ViewWeather, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
109
+ export function buildViewWeatherEvent(context) {
110
+ return merge(ViewWeather, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
118
111
  }
119
112
  // #endregion
120
113
  // #region Leave Event Builders
121
- export function buildLeaveArticleEvent(input, dependencies) {
122
- return merge(LeaveArticle, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
114
+ export function buildLeaveArticleEvent(context) {
115
+ return merge(LeaveArticle, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
123
116
  }
124
- export function buildLeaveAudioPageEvent(input, dependencies) {
125
- return merge(LeaveAudioPage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
117
+ export function buildLeaveAudioPageEvent(context) {
118
+ return merge(LeaveAudioPage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
126
119
  }
127
- export function buildLeaveErrorEvent(input, dependencies) {
128
- return merge(LeaveError, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
120
+ export function buildLeaveErrorEvent(context) {
121
+ return merge(LeaveError, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
129
122
  }
130
- export function buildLeaveFrontpageEvent(input, dependencies) {
131
- return merge(LeaveFrontpage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
123
+ export function buildLeaveFrontpageEvent(context) {
124
+ return merge(LeaveFrontpage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
132
125
  }
133
- export function buildLeaveLandingpageEvent(input, dependencies) {
134
- return merge(LeaveLandingpage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
126
+ export function buildLeaveLandingpageEvent(context) {
127
+ return merge(LeaveLandingpage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
135
128
  }
136
- export function buildLeaveListingEvent(input, dependencies) {
137
- return merge(LeaveListing, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
129
+ export function buildLeaveListingEvent(context) {
130
+ return merge(LeaveListing, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
138
131
  }
139
- export function buildLeaveLockedArticleEvent(input, dependencies) {
140
- return merge(LeaveLockedArticle, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
132
+ export function buildLeaveLockedArticleEvent(context) {
133
+ return merge(LeaveLockedArticle, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
141
134
  }
142
- export function buildLeaveLockedAudioPageEvent(input, dependencies) {
143
- return merge(LeaveLockedAudioPage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
135
+ export function buildLeaveLockedAudioPageEvent(context) {
136
+ return merge(LeaveLockedAudioPage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
144
137
  }
145
- export function buildLeaveLockedPageEvent(input, dependencies) {
146
- return merge(LeaveLockedPage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
138
+ export function buildLeaveLockedPageEvent(context) {
139
+ return merge(LeaveLockedPage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
147
140
  }
148
- export function buildLeavePageEvent(input, dependencies) {
149
- return merge(LeavePage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
141
+ export function buildLeavePageEvent(context) {
142
+ return merge(LeavePage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
150
143
  }
151
- export function buildLeaveSportsPageEvent(input, dependencies) {
152
- return merge(LeaveSportsPage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
144
+ export function buildLeaveSportsPageEvent(context) {
145
+ return merge(LeaveSportsPage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
153
146
  }
154
- export function buildLeaveSchoolPageEvent(input, dependencies) {
155
- return merge(LeaveSchoolPage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
147
+ export function buildLeaveSchoolPageEvent(context) {
148
+ return merge(LeaveSchoolPage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
156
149
  }
157
- export function buildLeaveVideoPageEvent(input, dependencies) {
158
- return merge(LeaveVideoPage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
150
+ export function buildLeaveVideoPageEvent(context) {
151
+ return merge(LeaveVideoPage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
159
152
  }
160
- export function buildLeaveWeatherEvent(input, dependencies) {
161
- const createdAt = new Date();
162
- const { isHybrid, version, providerId, providerName, providerGroup, providerStage, providerProduct, providerVersion, component, componentVersion, user, experiments, routingStage, } = dependencies;
163
- return merge(normalizePageInput(input), LeaveWeather, timeBuilder(createdAt), trackerBuilder({ isHybrid, version, routingStage }), baseEventBuilder(), providerBuilder(providerId, providerStage, providerProduct, providerVersion, component, componentVersion, providerName, providerGroup), userBuilder(user), experimentsBuilder(experiments, input.experiments), consentsBuilder(dependencies.consents), deviceBuilder(dependencies.environmentId, dependencies.jwe), catalogVersionBuilder(), navigationTypeBuilder(input.page?.navigationType), pageviewIdBuilder(dependencies.pageviewId), pageInfoBuilder(dependencies.currentPage), referrerBuilder(dependencies.currentPageReferrer));
153
+ export function buildLeaveWeatherEvent(context) {
154
+ return merge(LeaveWeather, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
164
155
  }
165
156
  // #endregion
166
157
  // #region Engagement Event Builders
167
- export function buildEngagementAdEvent(input, dependencies) {
168
- return merge(EngagementAd, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
158
+ export function buildEngagementAdEvent(context) {
159
+ return merge(EngagementAd, getElementEventBuildersOutput(context), normalizePageInput(context.input));
169
160
  }
170
- export function buildEngagementAffiliateEvent(input, dependencies) {
171
- return merge(EngagementAffiliate, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
161
+ export function buildEngagementAffiliateEvent(context) {
162
+ return merge(EngagementAffiliate, getElementEventBuildersOutput(context), normalizePageInput(context.input));
172
163
  }
173
- export function buildEngagementAudioEvent(input, dependencies) {
174
- return merge(EngagementAudio, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
164
+ export function buildEngagementAudioEvent(context) {
165
+ return merge(EngagementAudio, getElementEventBuildersOutput(context), normalizePageInput(context.input));
175
166
  }
176
- export function buildEngagementFormEvent(input, dependencies) {
177
- return merge(EngagementForm, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
167
+ export function buildEngagementFormEvent(context) {
168
+ return merge(EngagementForm, getElementEventBuildersOutput(context), normalizePageInput(context.input));
178
169
  }
179
- export function buildEngagementOfferEvent(input, dependencies) {
180
- return merge(EngagementOffer, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
170
+ export function buildEngagementOfferEvent(context) {
171
+ return merge(EngagementOffer, getElementEventBuildersOutput(context), normalizePageInput(context.input));
181
172
  }
182
- export function buildEngagementSportsUIElementEvent(input, dependencies) {
183
- return merge(EngagementSportsUIElement, getSportsElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
173
+ export function buildEngagementSportsUIElementEvent(context) {
174
+ return merge(EngagementSportsUIElement, getSportsElementEventBuildersOutput(context), normalizePageInput(context.input));
184
175
  }
185
- export function buildEngagementSchoolUIElementEvent(input, dependencies) {
186
- return merge(EngagementSchoolUIElement, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
176
+ export function buildEngagementSchoolUIElementEvent(context) {
177
+ return merge(EngagementSchoolUIElement, getElementEventBuildersOutput(context), normalizePageInput(context.input));
187
178
  }
188
- export function buildEngagementTeaserEvent(input, dependencies) {
189
- return merge(EngagementTeaser, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
179
+ export function buildEngagementTeaserEvent(context) {
180
+ return merge(EngagementTeaser, getElementEventBuildersOutput(context), normalizePageInput(context.input));
190
181
  }
191
- export function buildEngagementTvModuleEvent(input, dependencies) {
192
- return merge(EngagementTvModule, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
182
+ export function buildEngagementTvModuleEvent(context) {
183
+ return merge(EngagementTvModule, getElementEventBuildersOutput(context), normalizePageInput(context.input));
193
184
  }
194
- export function buildEngagementTvSearchEvent(input, dependencies) {
195
- return merge(EngagementTvSearch, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
185
+ export function buildEngagementTvSearchEvent(context) {
186
+ return merge(EngagementTvSearch, getElementEventBuildersOutput(context), normalizePageInput(context.input));
196
187
  }
197
- export function buildEngagementUIElementEvent(input, dependencies) {
198
- return merge(EngagementUIElement, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
188
+ export function buildEngagementUIElementEvent(context) {
189
+ return merge(EngagementUIElement, getElementEventBuildersOutput(context), normalizePageInput(context.input));
199
190
  }
200
- export function buildEngagementVideoEvent(input, dependencies) {
201
- return merge(EngagementVideo, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
191
+ export function buildEngagementVideoEvent(context) {
192
+ return merge(EngagementVideo, getElementEventBuildersOutput(context), normalizePageInput(context.input));
202
193
  }
203
- export function buildEngagementVideoAdEvent(input, dependencies) {
204
- return merge(EngagementVideoAd, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
194
+ export function buildEngagementVideoAdEvent(context) {
195
+ return merge(EngagementVideoAd, getElementEventBuildersOutput(context), normalizePageInput(context.input));
205
196
  }
206
- export function buildEngagementWidgetEvent(input, dependencies) {
207
- return merge(EngagementWidget, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
197
+ export function buildEngagementWidgetEvent(context) {
198
+ return merge(EngagementWidget, getElementEventBuildersOutput(context), normalizePageInput(context.input));
208
199
  }
209
200
  // #endregion
210
201
  // #region Heartbeat Event Builders
211
- export function buildHeartbeatCommercialArticleEvent(input, dependencies) {
212
- return merge(HeartbeatCommercialArticle, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
202
+ export function buildHeartbeatCommercialArticleEvent(context) {
203
+ return merge(HeartbeatCommercialArticle, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
213
204
  }
214
205
  // #endregion
215
206
  // #region Health Event Builders
216
- export function buildCompletedHealthActionEvent(input, dependencies) {
217
- return merge(CompletedHealthAction, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
207
+ export function buildCompletedHealthActionEvent(context) {
208
+ return merge(CompletedHealthAction, getCommonBuildersOutput(context), normalizePageInput(context.input));
218
209
  }
219
- export function buildEngagementHealthUIElementEvent(input, dependencies) {
220
- return merge(EngagementHealthUIElement, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
210
+ export function buildEngagementHealthUIElementEvent(context) {
211
+ return merge(EngagementHealthUIElement, getElementEventBuildersOutput(context), normalizePageInput(context.input));
221
212
  }
222
- export function buildViewHealthPageEvent(input, dependencies) {
223
- return merge(ViewHealthPage, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input), navigationTypeBuilder(input.page?.navigationType));
213
+ export function buildViewHealthPageEvent(context) {
214
+ return merge(ViewHealthPage, getCommonBuildersOutput(context), normalizePageInput(context.input), navigationTypeBuilder(context.input.page?.navigationType));
224
215
  }
225
- export function buildImpressionHealthUIElementEvent(input, dependencies) {
226
- return merge(ImpressionHealthUIElement, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
216
+ export function buildImpressionHealthUIElementEvent(context) {
217
+ return merge(ImpressionHealthUIElement, getCommonBuildersOutput(context), normalizePageInput(context.input));
227
218
  }
228
219
  // #endregion
229
220
  // #region Impression Event Builders
230
- export function buildImpressionAdEvent(input, dependencies) {
231
- return merge(ImpressionAd, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
221
+ export function buildImpressionAdEvent(context) {
222
+ return merge(ImpressionAd, getElementEventBuildersOutput(context), normalizePageInput(context.input));
232
223
  }
233
- export function buildImpressionAdSlotEvent(input, dependencies) {
234
- return merge(ImpressionAdSlot, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
224
+ export function buildImpressionAdSlotEvent(context) {
225
+ return merge(ImpressionAdSlot, getElementEventBuildersOutput(context), normalizePageInput(context.input));
235
226
  }
236
- export function buildImpressionAffiliateEvent(input, dependencies) {
237
- return merge(ImpressionAffiliate, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
227
+ export function buildImpressionAffiliateEvent(context) {
228
+ return merge(ImpressionAffiliate, getElementEventBuildersOutput(context), normalizePageInput(context.input));
238
229
  }
239
- export function buildImpressionFormEvent(input, dependencies) {
240
- return merge(ImpressionForm, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
230
+ export function buildImpressionFormEvent(context) {
231
+ return merge(ImpressionForm, getElementEventBuildersOutput(context), normalizePageInput(context.input));
241
232
  }
242
- export function buildImpressionOfferEvent(input, dependencies) {
243
- return merge(ImpressionOffer, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
233
+ export function buildImpressionOfferEvent(context) {
234
+ return merge(ImpressionOffer, getElementEventBuildersOutput(context), normalizePageInput(context.input));
244
235
  }
245
- export function buildImpressionPlayerEvent(input, dependencies) {
246
- return merge(ImpressionPlayer, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
236
+ export function buildImpressionPlayerEvent(context) {
237
+ return merge(ImpressionPlayer, getElementEventBuildersOutput(context), normalizePageInput(context.input));
247
238
  }
248
- export function buildImpressionSportsUIElementEvent(input, dependencies) {
249
- return merge(ImpressionSportsUIElement, getSportsElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
239
+ export function buildImpressionSportsUIElementEvent(context) {
240
+ return merge(ImpressionSportsUIElement, getSportsElementEventBuildersOutput(context), normalizePageInput(context.input));
250
241
  }
251
- export function buildImpressionSchoolUIElementEvent(input, dependencies) {
252
- return merge(ImpressionSchoolUIElement, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
242
+ export function buildImpressionSchoolUIElementEvent(context) {
243
+ return merge(ImpressionSchoolUIElement, getElementEventBuildersOutput(context), normalizePageInput(context.input));
253
244
  }
254
- export function buildImpressionTeaserEvent(input, dependencies) {
255
- return merge(ImpressionTeaser, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
245
+ export function buildImpressionTeaserEvent(context) {
246
+ return merge(ImpressionTeaser, getElementEventBuildersOutput(context), normalizePageInput(context.input));
256
247
  }
257
- export function buildImpressionUIElementEvent(input, dependencies) {
258
- return merge(ImpressionUIElement, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
248
+ export function buildImpressionUIElementEvent(context) {
249
+ return merge(ImpressionUIElement, getElementEventBuildersOutput(context), normalizePageInput(context.input));
259
250
  }
260
- export function buildImpressionWidgetEvent(input, dependencies) {
261
- return merge(ImpressionWidget, getElementEventBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
251
+ export function buildImpressionWidgetEvent(context) {
252
+ return merge(ImpressionWidget, getElementEventBuildersOutput(context), normalizePageInput(context.input));
262
253
  }
263
254
  // #endregion
264
255
  // #region Ad Lifecycle Event Builders
265
- export function buildLoadAdEvent(input, dependencies) {
266
- return merge(LoadAd, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
267
- }
268
- export function buildRequestAdEvent(input, dependencies) {
269
- return merge(RequestAd, getCommonBuildersOutput(new Date(), dependencies, input), normalizePageInput(input));
256
+ export function buildLoadAdEvent(context) {
257
+ return merge(LoadAd, getCommonBuildersOutput(context), normalizePageInput(context.input));
270
258
  }
271
259
  // #endregion
@@ -0,0 +1,80 @@
1
+ import { generateExperimentSDRN } from '../builders/experiments';
2
+ import { isString } from '../utils';
3
+ /**
4
+ * Adapts the legacy actor input to the TPaaS user format.
5
+ *
6
+ * @privateRemarks
7
+ * This is a temporary solution to adapt the actor to the new format.
8
+ * It should be removed once we have new methods in place to get the actor.
9
+ *
10
+ * @private
11
+ */
12
+ export function adaptActorToNewFormat(actor) {
13
+ if (!actor) {
14
+ return;
15
+ }
16
+ return {
17
+ id: actor.id?.toString() || '',
18
+ realm: actor.realm || '',
19
+ hasAnySubscription: !!actor.hasAnySubscription,
20
+ region: isString(actor.region) ? actor.region : undefined,
21
+ };
22
+ }
23
+ function adaptStatusOrOptIn({ status, optIn }) {
24
+ // doing an unnecessary check for status here
25
+ // because otherwise the code after the switch will be marked as unreachable in the IDE
26
+ if (status) {
27
+ switch (status) {
28
+ case 'accepted':
29
+ return 'Accepted';
30
+ case 'rejected':
31
+ return 'Rejected';
32
+ case 'unknown':
33
+ return 'Unknown';
34
+ }
35
+ }
36
+ if (optIn === true) {
37
+ return 'Accepted';
38
+ }
39
+ if (optIn === false) {
40
+ return 'Rejected';
41
+ }
42
+ return 'Unknown';
43
+ }
44
+ /**
45
+ * Adapts the legacy consents to the TPaaS consents format.
46
+ *
47
+ * @private
48
+ */
49
+ export function adaptConsentsToNewFormat(consents) {
50
+ if (!consents) {
51
+ return;
52
+ }
53
+ const { purposes, source } = consents;
54
+ const { CMP_ADVERTISING, CMP_ANALYTICS, CMP_MARKETING, CMP_PERSONALIZATION } = purposes;
55
+ return {
56
+ advertising: adaptStatusOrOptIn(CMP_ADVERTISING),
57
+ analytics: adaptStatusOrOptIn(CMP_ANALYTICS),
58
+ marketing: adaptStatusOrOptIn(CMP_MARKETING),
59
+ personalization: adaptStatusOrOptIn(CMP_PERSONALIZATION),
60
+ source: source || 'unknown',
61
+ };
62
+ }
63
+ /**
64
+ * Adapts the base experiments stored in the tracker to the TPaaS experiments format.
65
+ *
66
+ * @private
67
+ */
68
+ export function adaptExperiments(baseExperiments = []) {
69
+ return baseExperiments.map((exp) => {
70
+ return {
71
+ name: exp.name || exp.id,
72
+ variant: exp.variant || '',
73
+ // nobody should be sending experiment id with an sdrn format, but in case they do
74
+ // we want to be able to handle it and not generate an invalid sdrn by adding another layer to it
75
+ experimentSdrn: exp.id.startsWith('sdrn:') ? exp.id : generateExperimentSDRN(exp.id, exp.platform),
76
+ platform: exp.platform || '',
77
+ testId: exp.custom?.testId,
78
+ };
79
+ });
80
+ }
@@ -0,0 +1,47 @@
1
+ import { isBrowser } from '../utils';
2
+ /**
3
+ * Reads the browser state that can change between events, such as the URL after an SPA navigation
4
+ * or the viewport after a resize. Call it synchronously, when the event is tracked.
5
+ *
6
+ * @private
7
+ */
8
+ export const captureBrowserContext = () => {
9
+ if (!isBrowser) {
10
+ return {
11
+ url: undefined,
12
+ search: '',
13
+ screenOrientationType: undefined,
14
+ viewportWidth: 0,
15
+ viewportHeight: 0,
16
+ userAgent: undefined,
17
+ };
18
+ }
19
+ const { viewportWidth, viewportHeight } = getViewportDimensions();
20
+ return {
21
+ url: window.location.href,
22
+ search: window.location.search ?? '',
23
+ screenOrientationType: window.screen.orientation?.type,
24
+ viewportWidth,
25
+ viewportHeight,
26
+ userAgent: window.navigator.userAgent,
27
+ };
28
+ };
29
+ function getViewportDimensions() {
30
+ let viewportWidth;
31
+ let viewportHeight;
32
+ const { document } = window;
33
+ if (typeof window.innerWidth !== 'undefined') {
34
+ viewportWidth = window.innerWidth;
35
+ viewportHeight = window.innerHeight;
36
+ }
37
+ else if (typeof document.documentElement.clientWidth !== 'undefined' &&
38
+ document.documentElement.clientWidth !== 0) {
39
+ viewportWidth = document.documentElement.clientWidth;
40
+ viewportHeight = document.documentElement.clientHeight;
41
+ }
42
+ else {
43
+ viewportWidth = document.getElementsByTagName('body')[0].clientWidth;
44
+ viewportHeight = document.getElementsByTagName('body')[0].clientHeight;
45
+ }
46
+ return { viewportWidth, viewportHeight };
47
+ }
@@ -0,0 +1 @@
1
+ export { prepareAnonymousTpaasEventContext, prepareTpaasEventContext } from './prepare';