@schibsted/pulse-sdk 8.0.0-rc.4 → 8.0.0-rc.5
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.
- package/dist/cjs/Tracker.js +11 -79
- package/dist/cjs/builders/actor.js +3 -3
- package/dist/cjs/identity/actor.js +18 -6
- package/dist/cjs/tracker-proxy/consts.js +0 -7
- package/dist/cjs/version.js +1 -1
- package/dist/ejs/Tracker.js +13 -81
- package/dist/ejs/builders/actor.js +2 -2
- package/dist/ejs/identity/actor.js +19 -7
- package/dist/ejs/tracker-proxy/consts.js +0 -7
- package/dist/ejs/version.js +1 -1
- package/dist/types/Tracker.d.ts +2 -39
- package/dist/types/builders/actor.d.ts +3 -2
- package/dist/types/identity/actor.d.ts +2 -2
- package/dist/types/identity/cis.d.ts +1 -1
- package/dist/types/tracker-proxy/consts.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/node_modules/@schibsted/tpaas-event-builder/dist/cjs/builders/catalogVersion.js +9 -0
- package/node_modules/@schibsted/tpaas-event-builder/dist/cjs/builders.js +63 -78
- package/node_modules/@schibsted/tpaas-event-builder/dist/ejs/builders/catalogVersion.js +6 -0
- package/node_modules/@schibsted/tpaas-event-builder/dist/ejs/builders.js +64 -72
- package/node_modules/@schibsted/tpaas-event-builder/dist/index.d.ts +598 -1017
- package/node_modules/@schibsted/tpaas-schemas/dist/cjs/constants.js +67 -109
- package/node_modules/@schibsted/tpaas-schemas/dist/ejs/constants.js +65 -107
- package/node_modules/@schibsted/tpaas-schemas/dist/index.d.ts +722 -1215
- package/package.json +3 -3
package/dist/cjs/Tracker.js
CHANGED
|
@@ -369,6 +369,11 @@ class Tracker {
|
|
|
369
369
|
return queuedEvent.then((result) => result);
|
|
370
370
|
});
|
|
371
371
|
};
|
|
372
|
+
/*
|
|
373
|
+
* Casting `input` as `Partial<Builders>` to formalise the intention of processing the event input in relation to the properties in
|
|
374
|
+
* the Builders type. It would justify changing the public api for `.track`, but as this deals with legacy code, we
|
|
375
|
+
* keep it internal, so dependencies from now on can count on objects being a Partial<Builder>
|
|
376
|
+
*/
|
|
372
377
|
return this.syncRemoteResources(input, currentBuilders).then(_track, _track);
|
|
373
378
|
}
|
|
374
379
|
/**
|
|
@@ -781,7 +786,7 @@ class Tracker {
|
|
|
781
786
|
}
|
|
782
787
|
async trackViewHealthPage(input, options) {
|
|
783
788
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
784
|
-
this.setCurrentPage(input.object.objectId,
|
|
789
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewHealthPage.object.objectType);
|
|
785
790
|
const dependencies = await this.prepareTpaasEvent();
|
|
786
791
|
const event = (0, tpaas_event_builder_1.buildViewHealthPageEvent)(input, dependencies);
|
|
787
792
|
const result = this.sendTpaasEvent(event);
|
|
@@ -855,7 +860,7 @@ class Tracker {
|
|
|
855
860
|
*/
|
|
856
861
|
async trackViewSportsPage(input, options) {
|
|
857
862
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
858
|
-
this.setCurrentPage(input.object.objectId,
|
|
863
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewSportsPage.object.objectType);
|
|
859
864
|
const dependencies = await this.prepareTpaasEvent();
|
|
860
865
|
const event = (0, tpaas_event_builder_1.buildViewSportsPageEvent)(input, dependencies);
|
|
861
866
|
const result = this.sendTpaasEvent(event);
|
|
@@ -899,15 +904,6 @@ class Tracker {
|
|
|
899
904
|
const event = (0, tpaas_event_builder_1.buildImpressionWidgetEvent)(input, dependencies);
|
|
900
905
|
return this.sendTpaasEvent(event);
|
|
901
906
|
}
|
|
902
|
-
/**
|
|
903
|
-
* @param input
|
|
904
|
-
* @category TPaaS Tracking
|
|
905
|
-
*/
|
|
906
|
-
async trackImpressionAdSlot(input) {
|
|
907
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
908
|
-
const event = (0, tpaas_event_builder_1.buildImpressionAdSlotEvent)(input, dependencies);
|
|
909
|
-
return this.sendTpaasEvent(event);
|
|
910
|
-
}
|
|
911
907
|
/**
|
|
912
908
|
* @param input
|
|
913
909
|
* @param options
|
|
@@ -938,18 +934,6 @@ class Tracker {
|
|
|
938
934
|
}
|
|
939
935
|
return result;
|
|
940
936
|
}
|
|
941
|
-
/**
|
|
942
|
-
* @param input
|
|
943
|
-
* @param options
|
|
944
|
-
* @category TPaaS Tracking
|
|
945
|
-
*/
|
|
946
|
-
async trackViewAudio(input) {
|
|
947
|
-
// despite the View event type, this is not a page view event, but rather a media object view event
|
|
948
|
-
// so we shouldn't reset the page view ID here or enable leave tracking
|
|
949
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
950
|
-
const event = (0, tpaas_event_builder_1.buildViewAudioEvent)(input, dependencies);
|
|
951
|
-
return this.sendTpaasEvent(event);
|
|
952
|
-
}
|
|
953
937
|
/**
|
|
954
938
|
* Tracks a View AudioPage event and automatically fires a Leave AudioPage event when the user
|
|
955
939
|
* navigates away.
|
|
@@ -992,7 +976,7 @@ class Tracker {
|
|
|
992
976
|
*/
|
|
993
977
|
async trackViewAudioPage(input, options) {
|
|
994
978
|
this.newPageView();
|
|
995
|
-
this.setCurrentPage(input.object.objectId,
|
|
979
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewAudioPage.object.objectType);
|
|
996
980
|
const dependencies = await this.prepareTpaasEvent();
|
|
997
981
|
const event = (0, tpaas_event_builder_1.buildViewAudioPageEvent)(input, dependencies);
|
|
998
982
|
const result = this.sendTpaasEvent(event);
|
|
@@ -1221,18 +1205,6 @@ class Tracker {
|
|
|
1221
1205
|
}
|
|
1222
1206
|
return result;
|
|
1223
1207
|
}
|
|
1224
|
-
/**
|
|
1225
|
-
* @param input
|
|
1226
|
-
* @param options
|
|
1227
|
-
* @category TPaaS Tracking
|
|
1228
|
-
*/
|
|
1229
|
-
async trackViewLockedAudio(input) {
|
|
1230
|
-
// despite the View event type, this is not a page view event, but rather a media object view event
|
|
1231
|
-
// so we shouldn't reset the page view ID here or enable leave tracking
|
|
1232
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1233
|
-
const event = (0, tpaas_event_builder_1.buildViewLockedAudioEvent)(input, dependencies);
|
|
1234
|
-
return this.sendTpaasEvent(event);
|
|
1235
|
-
}
|
|
1236
1208
|
/**
|
|
1237
1209
|
* @param input
|
|
1238
1210
|
* @param options
|
|
@@ -1240,7 +1212,7 @@ class Tracker {
|
|
|
1240
1212
|
*/
|
|
1241
1213
|
async trackViewLockedAudioPage(input, options) {
|
|
1242
1214
|
this.newPageView();
|
|
1243
|
-
this.setCurrentPage(input.object.objectId,
|
|
1215
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewLockedAudioPage.object.objectType);
|
|
1244
1216
|
const dependencies = await this.prepareTpaasEvent();
|
|
1245
1217
|
const event = (0, tpaas_event_builder_1.buildViewLockedAudioPageEvent)(input, dependencies);
|
|
1246
1218
|
const result = this.sendTpaasEvent(event);
|
|
@@ -1263,17 +1235,6 @@ class Tracker {
|
|
|
1263
1235
|
}
|
|
1264
1236
|
return result;
|
|
1265
1237
|
}
|
|
1266
|
-
/**
|
|
1267
|
-
* @param input
|
|
1268
|
-
* @category TPaaS Tracking
|
|
1269
|
-
*/
|
|
1270
|
-
async trackViewLockedVideo(input) {
|
|
1271
|
-
// despite the name, this is not a page-level event. trackViewLockedVideoPage is a page-level event
|
|
1272
|
-
// as such, we don't support (yet) automatic leave event enabling
|
|
1273
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1274
|
-
const event = (0, tpaas_event_builder_1.buildViewLockedVideoEvent)(input, dependencies);
|
|
1275
|
-
return this.sendTpaasEvent(event);
|
|
1276
|
-
}
|
|
1277
1238
|
/**
|
|
1278
1239
|
* @param input
|
|
1279
1240
|
* @param options
|
|
@@ -1281,7 +1242,7 @@ class Tracker {
|
|
|
1281
1242
|
*/
|
|
1282
1243
|
async trackViewLockedVideoPage(input, options) {
|
|
1283
1244
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
1284
|
-
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.
|
|
1245
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewLockedVideoPage.object.objectType);
|
|
1285
1246
|
const dependencies = await this.prepareTpaasEvent();
|
|
1286
1247
|
const event = (0, tpaas_event_builder_1.buildViewLockedVideoPageEvent)(input, dependencies);
|
|
1287
1248
|
const result = this.sendTpaasEvent(event);
|
|
@@ -1304,17 +1265,6 @@ class Tracker {
|
|
|
1304
1265
|
}
|
|
1305
1266
|
return result;
|
|
1306
1267
|
}
|
|
1307
|
-
/**
|
|
1308
|
-
* @param input
|
|
1309
|
-
* @category TPaaS Tracking
|
|
1310
|
-
*/
|
|
1311
|
-
async trackViewVideo(input) {
|
|
1312
|
-
// despite the View event type, this is not a page view event, but rather a media object view event
|
|
1313
|
-
// so we shouldn't reset the page view ID here or enable leave tracking
|
|
1314
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1315
|
-
const event = (0, tpaas_event_builder_1.buildViewVideoEvent)(input, dependencies);
|
|
1316
|
-
return this.sendTpaasEvent(event);
|
|
1317
|
-
}
|
|
1318
1268
|
/**
|
|
1319
1269
|
* Tracks a View VideoPage event and automatically fires a Leave VideoPage event when the user
|
|
1320
1270
|
* navigates away.
|
|
@@ -1359,7 +1309,7 @@ class Tracker {
|
|
|
1359
1309
|
*/
|
|
1360
1310
|
async trackViewVideoPage(input, options) {
|
|
1361
1311
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
1362
|
-
this.setCurrentPage(input.object.objectId,
|
|
1312
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewVideoPage.object.objectType);
|
|
1363
1313
|
const dependencies = await this.prepareTpaasEvent();
|
|
1364
1314
|
const event = (0, tpaas_event_builder_1.buildViewVideoPageEvent)(input, dependencies);
|
|
1365
1315
|
const result = this.sendTpaasEvent(event);
|
|
@@ -1481,15 +1431,6 @@ class Tracker {
|
|
|
1481
1431
|
const event = (0, tpaas_event_builder_1.buildLeaveLockedArticleEvent)(input, dependencies);
|
|
1482
1432
|
return this.sendTpaasEvent(event);
|
|
1483
1433
|
}
|
|
1484
|
-
/**
|
|
1485
|
-
* @param input
|
|
1486
|
-
* @category TPaaS Tracking
|
|
1487
|
-
*/
|
|
1488
|
-
async trackLeaveLockedAudio(input) {
|
|
1489
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1490
|
-
const event = (0, tpaas_event_builder_1.buildLeaveLockedAudioEvent)(input, dependencies);
|
|
1491
|
-
return this.sendTpaasEvent(event);
|
|
1492
|
-
}
|
|
1493
1434
|
/**
|
|
1494
1435
|
* @param input
|
|
1495
1436
|
* @category TPaaS Tracking
|
|
@@ -1499,15 +1440,6 @@ class Tracker {
|
|
|
1499
1440
|
const event = (0, tpaas_event_builder_1.buildLeaveLockedAudioPageEvent)(input, dependencies);
|
|
1500
1441
|
return this.sendTpaasEvent(event);
|
|
1501
1442
|
}
|
|
1502
|
-
/**
|
|
1503
|
-
* @param input
|
|
1504
|
-
* @category TPaaS Tracking
|
|
1505
|
-
*/
|
|
1506
|
-
async trackLeaveLockedVideo(input) {
|
|
1507
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1508
|
-
const event = (0, tpaas_event_builder_1.buildLeaveLockedVideoEvent)(input, dependencies);
|
|
1509
|
-
return this.sendTpaasEvent(event);
|
|
1510
|
-
}
|
|
1511
1443
|
/**
|
|
1512
1444
|
* @param input
|
|
1513
1445
|
* @category TPaaS Tracking
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultValue = void 0;
|
|
4
4
|
exports.generateActorSDRN = generateActorSDRN;
|
|
5
|
-
exports.
|
|
5
|
+
exports.hasActorBuilder = hasActorBuilder;
|
|
6
6
|
exports.default = actor;
|
|
7
7
|
const pulse_utils_1 = require("@schibsted/pulse-utils");
|
|
8
8
|
/**
|
|
@@ -18,11 +18,11 @@ function generateActorSDRN(id, realm = '__REALM_NOT_SET__') {
|
|
|
18
18
|
return `sdrn:${realm}:user:${outputId}`;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* Type guard to check if the input
|
|
21
|
+
* Type guard to check if the input has an Actor Builder
|
|
22
22
|
* @param input
|
|
23
23
|
* @internal
|
|
24
24
|
*/
|
|
25
|
-
function
|
|
25
|
+
function hasActorBuilder(input) {
|
|
26
26
|
// biome-ignore lint/suspicious/noPrototypeBuiltins: Object.hasOwn is not available in ES2020
|
|
27
27
|
return (0, pulse_utils_1.isPlainObject)(input) && Object.prototype.hasOwnProperty.call(input, 'actor');
|
|
28
28
|
}
|
|
@@ -10,9 +10,7 @@ const warnOnce_1 = __importDefault(require("../warnOnce"));
|
|
|
10
10
|
/**
|
|
11
11
|
* @internal exported for testing
|
|
12
12
|
*/
|
|
13
|
-
exports.WARN_CIS_SYNC_LOGIN_UNDEFINED = '
|
|
14
|
-
' this using tracker.update({ actor: undefined }), otherwise do tracker.update({ actor: somePromise }) with a' +
|
|
15
|
-
' promise that resolves to the login state.';
|
|
13
|
+
exports.WARN_CIS_SYNC_LOGIN_UNDEFINED = 'No Actor Builder found in event input or tracker builders. Please provide an Actor Builder to ensure the SDK resolves logged-in and logged-out scenarios correctly.';
|
|
16
14
|
/**
|
|
17
15
|
* Get the actor id (userId) from the current browser. A promise is returned
|
|
18
16
|
* because a call may be made to complete the login process.
|
|
@@ -33,6 +31,19 @@ const getActor = async (builders) => {
|
|
|
33
31
|
return await evaluateActor(builders);
|
|
34
32
|
};
|
|
35
33
|
exports.getActor = getActor;
|
|
34
|
+
/**
|
|
35
|
+
* Pinpoints the Actor Builder from the Event payload or the available Builders
|
|
36
|
+
* @param eventInput - The event input which may contain an `actor` property
|
|
37
|
+
* @param builders - The builders managed by the SDK.
|
|
38
|
+
*/
|
|
39
|
+
function getActorSource(eventInput = {}, builders = {}) {
|
|
40
|
+
if ((0, actor_1.hasActorBuilder)(eventInput)) {
|
|
41
|
+
return eventInput.actor;
|
|
42
|
+
}
|
|
43
|
+
if ((0, actor_1.hasActorBuilder)(builders)) {
|
|
44
|
+
return builders.actor;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
36
47
|
const userIsLoggedIn = async (builders) => {
|
|
37
48
|
const actor = await getActor(builders);
|
|
38
49
|
return !!actor?.id;
|
|
@@ -45,8 +56,9 @@ exports.userIsLoggedIn = userIsLoggedIn;
|
|
|
45
56
|
* @private
|
|
46
57
|
*/
|
|
47
58
|
const evaluateActor = async (eventInput = {}, builders = {}) => {
|
|
48
|
-
|
|
49
|
-
|
|
59
|
+
const actorSource = getActorSource(eventInput, builders);
|
|
60
|
+
if (actorSource) {
|
|
61
|
+
const evaluatedActor = await (0, pulse_utils_1.evaluateAndFlatten)(actorSource);
|
|
50
62
|
if (evaluatedActor) {
|
|
51
63
|
return evaluatedActor;
|
|
52
64
|
}
|
|
@@ -54,7 +66,7 @@ const evaluateActor = async (eventInput = {}, builders = {}) => {
|
|
|
54
66
|
// We allow an empty actor object, because it is a sign that the application is not setting nor updating Actor correctly.
|
|
55
67
|
// Inferring "id: undefined" as a fallback would mask that bug.
|
|
56
68
|
// Hence, the warning below.
|
|
57
|
-
(0, warnOnce_1.default)('no-actor-builder
|
|
69
|
+
(0, warnOnce_1.default)('no-actor-builder', exports.WARN_CIS_SYNC_LOGIN_UNDEFINED);
|
|
58
70
|
return {};
|
|
59
71
|
};
|
|
60
72
|
exports.evaluateActor = evaluateActor;
|
|
@@ -22,7 +22,6 @@ exports.TPAAS_ALLOWED_METHODS = [
|
|
|
22
22
|
'trackEngagementVideoAd',
|
|
23
23
|
'trackEngagementWidget',
|
|
24
24
|
'trackCompletedHealthAction',
|
|
25
|
-
'trackImpressionAdSlot',
|
|
26
25
|
'trackImpressionForm',
|
|
27
26
|
'trackImpressionHealthUIElement',
|
|
28
27
|
'trackImpressionOffer',
|
|
@@ -37,15 +36,12 @@ exports.TPAAS_ALLOWED_METHODS = [
|
|
|
37
36
|
'trackLeaveLandingpage',
|
|
38
37
|
'trackLeaveListing',
|
|
39
38
|
'trackLeaveLockedArticle',
|
|
40
|
-
'trackLeaveLockedAudio',
|
|
41
39
|
'trackLeaveLockedAudioPage',
|
|
42
|
-
'trackLeaveLockedVideo',
|
|
43
40
|
'trackLeaveLockedVideoPage',
|
|
44
41
|
'trackLeavePage',
|
|
45
42
|
'trackLeaveVideoPage',
|
|
46
43
|
'trackLeaveWeather',
|
|
47
44
|
'trackViewArticle',
|
|
48
|
-
'trackViewAudio',
|
|
49
45
|
'trackViewAudioPage',
|
|
50
46
|
'trackViewError',
|
|
51
47
|
'trackViewFrontpage',
|
|
@@ -53,13 +49,10 @@ exports.TPAAS_ALLOWED_METHODS = [
|
|
|
53
49
|
'trackViewLandingpage',
|
|
54
50
|
'trackViewListing',
|
|
55
51
|
'trackViewLockedArticle',
|
|
56
|
-
'trackViewLockedAudio',
|
|
57
52
|
'trackViewLockedAudioPage',
|
|
58
|
-
'trackViewLockedVideo',
|
|
59
53
|
'trackViewLockedVideoPage',
|
|
60
54
|
'trackViewPage',
|
|
61
55
|
'trackViewTitle',
|
|
62
|
-
'trackViewVideo',
|
|
63
56
|
'trackViewVideoPage',
|
|
64
57
|
'trackViewWeather',
|
|
65
58
|
// these are not TPaaS methods,
|
package/dist/cjs/version.js
CHANGED
package/dist/ejs/Tracker.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parsePulseCookies } from '@schibsted/pulse-cis-sync';
|
|
2
2
|
import { evaluateAndFlatten, isBrowser, isFunction, isPromise, isString, pulseMerge, throttle, } from '@schibsted/pulse-utils';
|
|
3
|
-
import { buildAnonymousViewUIElementEvent, buildCompletedHealthActionEvent, buildEngagementAudioEvent, buildEngagementFormEvent, buildEngagementHealthUIElementEvent, buildEngagementOfferEvent, buildEngagementTeaserEvent, buildEngagementUIElementEvent, buildEngagementVideoAdEvent, buildEngagementVideoEvent, buildEngagementWidgetEvent,
|
|
4
|
-
import { LeaveArticle, LeaveAudioPage, LeaveError, LeaveFrontpage, LeaveLandingpage, LeaveListing, LeaveLockedArticle, LeaveLockedAudioPage, LeaveLockedVideoPage, LeavePage, LeaveSportsPage, LeaveVideoPage, LeaveWeather, ViewArticle, ViewError, ViewFrontpage, ViewLandingpage, ViewListing, ViewLockedArticle,
|
|
3
|
+
import { buildAnonymousViewUIElementEvent, buildCompletedHealthActionEvent, buildEngagementAudioEvent, buildEngagementFormEvent, buildEngagementHealthUIElementEvent, buildEngagementOfferEvent, buildEngagementTeaserEvent, buildEngagementUIElementEvent, buildEngagementVideoAdEvent, buildEngagementVideoEvent, buildEngagementWidgetEvent, buildImpressionFormEvent, buildImpressionHealthUIElementEvent, buildImpressionOfferEvent, buildImpressionPlayerEvent, buildImpressionTeaserEvent, buildImpressionUIElementEvent, buildImpressionWidgetEvent, buildLeaveArticleEvent, buildLeaveAudioPageEvent, buildLeaveErrorEvent, buildLeaveFrontpageEvent, buildLeaveLandingpageEvent, buildLeaveListingEvent, buildLeaveLockedArticleEvent, buildLeaveLockedAudioPageEvent, buildLeaveLockedVideoPageEvent, buildLeavePageEvent, buildLeaveSportsPageEvent, buildLeaveVideoPageEvent, buildLeaveWeatherEvent, buildViewArticleEvent, buildViewAudioPageEvent, buildViewErrorEvent, buildViewFrontpageEvent, buildViewHealthPageEvent, buildViewLandingpageEvent, buildViewListingEvent, buildViewLockedArticleEvent, buildViewLockedAudioPageEvent, buildViewLockedVideoPageEvent, buildViewPageEvent, buildViewSportsPageEvent, buildViewTitleEvent, buildViewVideoPageEvent, buildViewWeatherEvent, getCommonBuildersOutput, } from '@schibsted/tpaas-event-builder';
|
|
4
|
+
import { LeaveArticle, LeaveAudioPage, LeaveError, LeaveFrontpage, LeaveLandingpage, LeaveListing, LeaveLockedArticle, LeaveLockedAudioPage, LeaveLockedVideoPage, LeavePage, LeaveSportsPage, LeaveVideoPage, LeaveWeather, ViewArticle, ViewAudioPage, ViewError, ViewFrontpage, ViewHealthPage, ViewLandingpage, ViewListing, ViewLockedArticle, ViewLockedAudioPage, ViewLockedVideoPage, ViewPage, ViewSportsPage, ViewTitle, ViewVideoPage, ViewWeather, } from '@schibsted/tpaas-schemas';
|
|
5
5
|
import logger from 'loglevel';
|
|
6
6
|
import { v4 } from 'uuid';
|
|
7
7
|
import { getDefaultAltHandler, getDefaultNativeJwe } from './app-integration';
|
|
@@ -326,6 +326,11 @@ export default class Tracker {
|
|
|
326
326
|
return queuedEvent.then((result) => result);
|
|
327
327
|
});
|
|
328
328
|
};
|
|
329
|
+
/*
|
|
330
|
+
* Casting `input` as `Partial<Builders>` to formalise the intention of processing the event input in relation to the properties in
|
|
331
|
+
* the Builders type. It would justify changing the public api for `.track`, but as this deals with legacy code, we
|
|
332
|
+
* keep it internal, so dependencies from now on can count on objects being a Partial<Builder>
|
|
333
|
+
*/
|
|
329
334
|
return this.syncRemoteResources(input, currentBuilders).then(_track, _track);
|
|
330
335
|
}
|
|
331
336
|
/**
|
|
@@ -738,7 +743,7 @@ export default class Tracker {
|
|
|
738
743
|
}
|
|
739
744
|
async trackViewHealthPage(input, options) {
|
|
740
745
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
741
|
-
this.setCurrentPage(input.object.objectId,
|
|
746
|
+
this.setCurrentPage(input.object.objectId, ViewHealthPage.object.objectType);
|
|
742
747
|
const dependencies = await this.prepareTpaasEvent();
|
|
743
748
|
const event = buildViewHealthPageEvent(input, dependencies);
|
|
744
749
|
const result = this.sendTpaasEvent(event);
|
|
@@ -812,7 +817,7 @@ export default class Tracker {
|
|
|
812
817
|
*/
|
|
813
818
|
async trackViewSportsPage(input, options) {
|
|
814
819
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
815
|
-
this.setCurrentPage(input.object.objectId,
|
|
820
|
+
this.setCurrentPage(input.object.objectId, ViewSportsPage.object.objectType);
|
|
816
821
|
const dependencies = await this.prepareTpaasEvent();
|
|
817
822
|
const event = buildViewSportsPageEvent(input, dependencies);
|
|
818
823
|
const result = this.sendTpaasEvent(event);
|
|
@@ -856,15 +861,6 @@ export default class Tracker {
|
|
|
856
861
|
const event = buildImpressionWidgetEvent(input, dependencies);
|
|
857
862
|
return this.sendTpaasEvent(event);
|
|
858
863
|
}
|
|
859
|
-
/**
|
|
860
|
-
* @param input
|
|
861
|
-
* @category TPaaS Tracking
|
|
862
|
-
*/
|
|
863
|
-
async trackImpressionAdSlot(input) {
|
|
864
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
865
|
-
const event = buildImpressionAdSlotEvent(input, dependencies);
|
|
866
|
-
return this.sendTpaasEvent(event);
|
|
867
|
-
}
|
|
868
864
|
/**
|
|
869
865
|
* @param input
|
|
870
866
|
* @param options
|
|
@@ -895,18 +891,6 @@ export default class Tracker {
|
|
|
895
891
|
}
|
|
896
892
|
return result;
|
|
897
893
|
}
|
|
898
|
-
/**
|
|
899
|
-
* @param input
|
|
900
|
-
* @param options
|
|
901
|
-
* @category TPaaS Tracking
|
|
902
|
-
*/
|
|
903
|
-
async trackViewAudio(input) {
|
|
904
|
-
// despite the View event type, this is not a page view event, but rather a media object view event
|
|
905
|
-
// so we shouldn't reset the page view ID here or enable leave tracking
|
|
906
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
907
|
-
const event = buildViewAudioEvent(input, dependencies);
|
|
908
|
-
return this.sendTpaasEvent(event);
|
|
909
|
-
}
|
|
910
894
|
/**
|
|
911
895
|
* Tracks a View AudioPage event and automatically fires a Leave AudioPage event when the user
|
|
912
896
|
* navigates away.
|
|
@@ -949,7 +933,7 @@ export default class Tracker {
|
|
|
949
933
|
*/
|
|
950
934
|
async trackViewAudioPage(input, options) {
|
|
951
935
|
this.newPageView();
|
|
952
|
-
this.setCurrentPage(input.object.objectId,
|
|
936
|
+
this.setCurrentPage(input.object.objectId, ViewAudioPage.object.objectType);
|
|
953
937
|
const dependencies = await this.prepareTpaasEvent();
|
|
954
938
|
const event = buildViewAudioPageEvent(input, dependencies);
|
|
955
939
|
const result = this.sendTpaasEvent(event);
|
|
@@ -1178,18 +1162,6 @@ export default class Tracker {
|
|
|
1178
1162
|
}
|
|
1179
1163
|
return result;
|
|
1180
1164
|
}
|
|
1181
|
-
/**
|
|
1182
|
-
* @param input
|
|
1183
|
-
* @param options
|
|
1184
|
-
* @category TPaaS Tracking
|
|
1185
|
-
*/
|
|
1186
|
-
async trackViewLockedAudio(input) {
|
|
1187
|
-
// despite the View event type, this is not a page view event, but rather a media object view event
|
|
1188
|
-
// so we shouldn't reset the page view ID here or enable leave tracking
|
|
1189
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1190
|
-
const event = buildViewLockedAudioEvent(input, dependencies);
|
|
1191
|
-
return this.sendTpaasEvent(event);
|
|
1192
|
-
}
|
|
1193
1165
|
/**
|
|
1194
1166
|
* @param input
|
|
1195
1167
|
* @param options
|
|
@@ -1197,7 +1169,7 @@ export default class Tracker {
|
|
|
1197
1169
|
*/
|
|
1198
1170
|
async trackViewLockedAudioPage(input, options) {
|
|
1199
1171
|
this.newPageView();
|
|
1200
|
-
this.setCurrentPage(input.object.objectId,
|
|
1172
|
+
this.setCurrentPage(input.object.objectId, ViewLockedAudioPage.object.objectType);
|
|
1201
1173
|
const dependencies = await this.prepareTpaasEvent();
|
|
1202
1174
|
const event = buildViewLockedAudioPageEvent(input, dependencies);
|
|
1203
1175
|
const result = this.sendTpaasEvent(event);
|
|
@@ -1220,17 +1192,6 @@ export default class Tracker {
|
|
|
1220
1192
|
}
|
|
1221
1193
|
return result;
|
|
1222
1194
|
}
|
|
1223
|
-
/**
|
|
1224
|
-
* @param input
|
|
1225
|
-
* @category TPaaS Tracking
|
|
1226
|
-
*/
|
|
1227
|
-
async trackViewLockedVideo(input) {
|
|
1228
|
-
// despite the name, this is not a page-level event. trackViewLockedVideoPage is a page-level event
|
|
1229
|
-
// as such, we don't support (yet) automatic leave event enabling
|
|
1230
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1231
|
-
const event = buildViewLockedVideoEvent(input, dependencies);
|
|
1232
|
-
return this.sendTpaasEvent(event);
|
|
1233
|
-
}
|
|
1234
1195
|
/**
|
|
1235
1196
|
* @param input
|
|
1236
1197
|
* @param options
|
|
@@ -1238,7 +1199,7 @@ export default class Tracker {
|
|
|
1238
1199
|
*/
|
|
1239
1200
|
async trackViewLockedVideoPage(input, options) {
|
|
1240
1201
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
1241
|
-
this.setCurrentPage(input.object.objectId,
|
|
1202
|
+
this.setCurrentPage(input.object.objectId, ViewLockedVideoPage.object.objectType);
|
|
1242
1203
|
const dependencies = await this.prepareTpaasEvent();
|
|
1243
1204
|
const event = buildViewLockedVideoPageEvent(input, dependencies);
|
|
1244
1205
|
const result = this.sendTpaasEvent(event);
|
|
@@ -1261,17 +1222,6 @@ export default class Tracker {
|
|
|
1261
1222
|
}
|
|
1262
1223
|
return result;
|
|
1263
1224
|
}
|
|
1264
|
-
/**
|
|
1265
|
-
* @param input
|
|
1266
|
-
* @category TPaaS Tracking
|
|
1267
|
-
*/
|
|
1268
|
-
async trackViewVideo(input) {
|
|
1269
|
-
// despite the View event type, this is not a page view event, but rather a media object view event
|
|
1270
|
-
// so we shouldn't reset the page view ID here or enable leave tracking
|
|
1271
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1272
|
-
const event = buildViewVideoEvent(input, dependencies);
|
|
1273
|
-
return this.sendTpaasEvent(event);
|
|
1274
|
-
}
|
|
1275
1225
|
/**
|
|
1276
1226
|
* Tracks a View VideoPage event and automatically fires a Leave VideoPage event when the user
|
|
1277
1227
|
* navigates away.
|
|
@@ -1316,7 +1266,7 @@ export default class Tracker {
|
|
|
1316
1266
|
*/
|
|
1317
1267
|
async trackViewVideoPage(input, options) {
|
|
1318
1268
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
1319
|
-
this.setCurrentPage(input.object.objectId,
|
|
1269
|
+
this.setCurrentPage(input.object.objectId, ViewVideoPage.object.objectType);
|
|
1320
1270
|
const dependencies = await this.prepareTpaasEvent();
|
|
1321
1271
|
const event = buildViewVideoPageEvent(input, dependencies);
|
|
1322
1272
|
const result = this.sendTpaasEvent(event);
|
|
@@ -1438,15 +1388,6 @@ export default class Tracker {
|
|
|
1438
1388
|
const event = buildLeaveLockedArticleEvent(input, dependencies);
|
|
1439
1389
|
return this.sendTpaasEvent(event);
|
|
1440
1390
|
}
|
|
1441
|
-
/**
|
|
1442
|
-
* @param input
|
|
1443
|
-
* @category TPaaS Tracking
|
|
1444
|
-
*/
|
|
1445
|
-
async trackLeaveLockedAudio(input) {
|
|
1446
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1447
|
-
const event = buildLeaveLockedAudioEvent(input, dependencies);
|
|
1448
|
-
return this.sendTpaasEvent(event);
|
|
1449
|
-
}
|
|
1450
1391
|
/**
|
|
1451
1392
|
* @param input
|
|
1452
1393
|
* @category TPaaS Tracking
|
|
@@ -1456,15 +1397,6 @@ export default class Tracker {
|
|
|
1456
1397
|
const event = buildLeaveLockedAudioPageEvent(input, dependencies);
|
|
1457
1398
|
return this.sendTpaasEvent(event);
|
|
1458
1399
|
}
|
|
1459
|
-
/**
|
|
1460
|
-
* @param input
|
|
1461
|
-
* @category TPaaS Tracking
|
|
1462
|
-
*/
|
|
1463
|
-
async trackLeaveLockedVideo(input) {
|
|
1464
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1465
|
-
const event = buildLeaveLockedVideoEvent(input, dependencies);
|
|
1466
|
-
return this.sendTpaasEvent(event);
|
|
1467
|
-
}
|
|
1468
1400
|
/**
|
|
1469
1401
|
* @param input
|
|
1470
1402
|
* @category TPaaS Tracking
|
|
@@ -12,11 +12,11 @@ export function generateActorSDRN(id, realm = '__REALM_NOT_SET__') {
|
|
|
12
12
|
return `sdrn:${realm}:user:${outputId}`;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* Type guard to check if the input
|
|
15
|
+
* Type guard to check if the input has an Actor Builder
|
|
16
16
|
* @param input
|
|
17
17
|
* @internal
|
|
18
18
|
*/
|
|
19
|
-
export function
|
|
19
|
+
export function hasActorBuilder(input) {
|
|
20
20
|
// biome-ignore lint/suspicious/noPrototypeBuiltins: Object.hasOwn is not available in ES2020
|
|
21
21
|
return isPlainObject(input) && Object.prototype.hasOwnProperty.call(input, 'actor');
|
|
22
22
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { evaluateAndFlatten } from '@schibsted/pulse-utils';
|
|
2
|
-
import {
|
|
2
|
+
import { hasActorBuilder } from '../builders/actor';
|
|
3
3
|
import warnOnce from '../warnOnce';
|
|
4
4
|
/**
|
|
5
5
|
* @internal exported for testing
|
|
6
6
|
*/
|
|
7
|
-
export const WARN_CIS_SYNC_LOGIN_UNDEFINED = '
|
|
8
|
-
' this using tracker.update({ actor: undefined }), otherwise do tracker.update({ actor: somePromise }) with a' +
|
|
9
|
-
' promise that resolves to the login state.';
|
|
7
|
+
export 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.';
|
|
10
8
|
/**
|
|
11
9
|
* Get the actor id (userId) from the current browser. A promise is returned
|
|
12
10
|
* because a call may be made to complete the login process.
|
|
@@ -25,6 +23,19 @@ const getUserId = async (builders) => {
|
|
|
25
23
|
const getActor = async (builders) => {
|
|
26
24
|
return await evaluateActor(builders);
|
|
27
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Pinpoints the Actor Builder from the Event payload or the available Builders
|
|
28
|
+
* @param eventInput - The event input which may contain an `actor` property
|
|
29
|
+
* @param builders - The builders managed by the SDK.
|
|
30
|
+
*/
|
|
31
|
+
function getActorSource(eventInput = {}, builders = {}) {
|
|
32
|
+
if (hasActorBuilder(eventInput)) {
|
|
33
|
+
return eventInput.actor;
|
|
34
|
+
}
|
|
35
|
+
if (hasActorBuilder(builders)) {
|
|
36
|
+
return builders.actor;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
28
39
|
const userIsLoggedIn = async (builders) => {
|
|
29
40
|
const actor = await getActor(builders);
|
|
30
41
|
return !!actor?.id;
|
|
@@ -36,8 +47,9 @@ const userIsLoggedIn = async (builders) => {
|
|
|
36
47
|
* @private
|
|
37
48
|
*/
|
|
38
49
|
const evaluateActor = async (eventInput = {}, builders = {}) => {
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
const actorSource = getActorSource(eventInput, builders);
|
|
51
|
+
if (actorSource) {
|
|
52
|
+
const evaluatedActor = await evaluateAndFlatten(actorSource);
|
|
41
53
|
if (evaluatedActor) {
|
|
42
54
|
return evaluatedActor;
|
|
43
55
|
}
|
|
@@ -45,7 +57,7 @@ const evaluateActor = async (eventInput = {}, builders = {}) => {
|
|
|
45
57
|
// We allow an empty actor object, because it is a sign that the application is not setting nor updating Actor correctly.
|
|
46
58
|
// Inferring "id: undefined" as a fallback would mask that bug.
|
|
47
59
|
// Hence, the warning below.
|
|
48
|
-
warnOnce('no-actor-builder
|
|
60
|
+
warnOnce('no-actor-builder', WARN_CIS_SYNC_LOGIN_UNDEFINED);
|
|
49
61
|
return {};
|
|
50
62
|
};
|
|
51
63
|
export { getUserId, getActor, userIsLoggedIn, evaluateActor };
|
|
@@ -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,12 @@ 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',
|
|
41
38
|
'trackLeaveVideoPage',
|
|
42
39
|
'trackLeaveWeather',
|
|
43
40
|
'trackViewArticle',
|
|
44
|
-
'trackViewAudio',
|
|
45
41
|
'trackViewAudioPage',
|
|
46
42
|
'trackViewError',
|
|
47
43
|
'trackViewFrontpage',
|
|
@@ -49,13 +45,10 @@ export const TPAAS_ALLOWED_METHODS = [
|
|
|
49
45
|
'trackViewLandingpage',
|
|
50
46
|
'trackViewListing',
|
|
51
47
|
'trackViewLockedArticle',
|
|
52
|
-
'trackViewLockedAudio',
|
|
53
48
|
'trackViewLockedAudioPage',
|
|
54
|
-
'trackViewLockedVideo',
|
|
55
49
|
'trackViewLockedVideoPage',
|
|
56
50
|
'trackViewPage',
|
|
57
51
|
'trackViewTitle',
|
|
58
|
-
'trackViewVideo',
|
|
59
52
|
'trackViewVideoPage',
|
|
60
53
|
'trackViewWeather',
|
|
61
54
|
// these are not TPaaS methods,
|
package/dist/ejs/version.js
CHANGED
|
@@ -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.
|
|
2
|
+
export const SDK_VERSION = '8.0.0-rc.5';
|