@schibsted/pulse-sdk 8.0.0-rc.3 → 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 +14 -79
- package/dist/cjs/Tracker.test-d.js +2 -0
- 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 +16 -81
- package/dist/ejs/Tracker.test-d.js +2 -0
- 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 +736 -1058
- package/node_modules/@schibsted/tpaas-event-builder/package.json +1 -1
- package/node_modules/@schibsted/tpaas-schemas/dist/cjs/constants.js +80 -107
- package/node_modules/@schibsted/tpaas-schemas/dist/ejs/constants.js +78 -105
- package/node_modules/@schibsted/tpaas-schemas/dist/index.d.ts +850 -1214
- package/node_modules/@schibsted/tpaas-schemas/package.json +1 -1
- 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
|
/**
|
|
@@ -438,6 +443,9 @@ class Tracker {
|
|
|
438
443
|
return {
|
|
439
444
|
name: exp.name || exp.id,
|
|
440
445
|
variant: exp.variant || '',
|
|
446
|
+
experimentSdrn: exp.id,
|
|
447
|
+
platform: exp.platform || '',
|
|
448
|
+
testId: exp.custom?.testId,
|
|
441
449
|
};
|
|
442
450
|
});
|
|
443
451
|
}
|
|
@@ -778,7 +786,7 @@ class Tracker {
|
|
|
778
786
|
}
|
|
779
787
|
async trackViewHealthPage(input, options) {
|
|
780
788
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
781
|
-
this.setCurrentPage(input.object.objectId,
|
|
789
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewHealthPage.object.objectType);
|
|
782
790
|
const dependencies = await this.prepareTpaasEvent();
|
|
783
791
|
const event = (0, tpaas_event_builder_1.buildViewHealthPageEvent)(input, dependencies);
|
|
784
792
|
const result = this.sendTpaasEvent(event);
|
|
@@ -852,7 +860,7 @@ class Tracker {
|
|
|
852
860
|
*/
|
|
853
861
|
async trackViewSportsPage(input, options) {
|
|
854
862
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
855
|
-
this.setCurrentPage(input.object.objectId,
|
|
863
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewSportsPage.object.objectType);
|
|
856
864
|
const dependencies = await this.prepareTpaasEvent();
|
|
857
865
|
const event = (0, tpaas_event_builder_1.buildViewSportsPageEvent)(input, dependencies);
|
|
858
866
|
const result = this.sendTpaasEvent(event);
|
|
@@ -896,15 +904,6 @@ class Tracker {
|
|
|
896
904
|
const event = (0, tpaas_event_builder_1.buildImpressionWidgetEvent)(input, dependencies);
|
|
897
905
|
return this.sendTpaasEvent(event);
|
|
898
906
|
}
|
|
899
|
-
/**
|
|
900
|
-
* @param input
|
|
901
|
-
* @category TPaaS Tracking
|
|
902
|
-
*/
|
|
903
|
-
async trackImpressionAdSlot(input) {
|
|
904
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
905
|
-
const event = (0, tpaas_event_builder_1.buildImpressionAdSlotEvent)(input, dependencies);
|
|
906
|
-
return this.sendTpaasEvent(event);
|
|
907
|
-
}
|
|
908
907
|
/**
|
|
909
908
|
* @param input
|
|
910
909
|
* @param options
|
|
@@ -935,18 +934,6 @@ class Tracker {
|
|
|
935
934
|
}
|
|
936
935
|
return result;
|
|
937
936
|
}
|
|
938
|
-
/**
|
|
939
|
-
* @param input
|
|
940
|
-
* @param options
|
|
941
|
-
* @category TPaaS Tracking
|
|
942
|
-
*/
|
|
943
|
-
async trackViewAudio(input) {
|
|
944
|
-
// despite the View event type, this is not a page view event, but rather a media object view event
|
|
945
|
-
// so we shouldn't reset the page view ID here or enable leave tracking
|
|
946
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
947
|
-
const event = (0, tpaas_event_builder_1.buildViewAudioEvent)(input, dependencies);
|
|
948
|
-
return this.sendTpaasEvent(event);
|
|
949
|
-
}
|
|
950
937
|
/**
|
|
951
938
|
* Tracks a View AudioPage event and automatically fires a Leave AudioPage event when the user
|
|
952
939
|
* navigates away.
|
|
@@ -989,7 +976,7 @@ class Tracker {
|
|
|
989
976
|
*/
|
|
990
977
|
async trackViewAudioPage(input, options) {
|
|
991
978
|
this.newPageView();
|
|
992
|
-
this.setCurrentPage(input.object.objectId,
|
|
979
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewAudioPage.object.objectType);
|
|
993
980
|
const dependencies = await this.prepareTpaasEvent();
|
|
994
981
|
const event = (0, tpaas_event_builder_1.buildViewAudioPageEvent)(input, dependencies);
|
|
995
982
|
const result = this.sendTpaasEvent(event);
|
|
@@ -1218,18 +1205,6 @@ class Tracker {
|
|
|
1218
1205
|
}
|
|
1219
1206
|
return result;
|
|
1220
1207
|
}
|
|
1221
|
-
/**
|
|
1222
|
-
* @param input
|
|
1223
|
-
* @param options
|
|
1224
|
-
* @category TPaaS Tracking
|
|
1225
|
-
*/
|
|
1226
|
-
async trackViewLockedAudio(input) {
|
|
1227
|
-
// despite the View event type, this is not a page view event, but rather a media object view event
|
|
1228
|
-
// so we shouldn't reset the page view ID here or enable leave tracking
|
|
1229
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1230
|
-
const event = (0, tpaas_event_builder_1.buildViewLockedAudioEvent)(input, dependencies);
|
|
1231
|
-
return this.sendTpaasEvent(event);
|
|
1232
|
-
}
|
|
1233
1208
|
/**
|
|
1234
1209
|
* @param input
|
|
1235
1210
|
* @param options
|
|
@@ -1237,7 +1212,7 @@ class Tracker {
|
|
|
1237
1212
|
*/
|
|
1238
1213
|
async trackViewLockedAudioPage(input, options) {
|
|
1239
1214
|
this.newPageView();
|
|
1240
|
-
this.setCurrentPage(input.object.objectId,
|
|
1215
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewLockedAudioPage.object.objectType);
|
|
1241
1216
|
const dependencies = await this.prepareTpaasEvent();
|
|
1242
1217
|
const event = (0, tpaas_event_builder_1.buildViewLockedAudioPageEvent)(input, dependencies);
|
|
1243
1218
|
const result = this.sendTpaasEvent(event);
|
|
@@ -1260,17 +1235,6 @@ class Tracker {
|
|
|
1260
1235
|
}
|
|
1261
1236
|
return result;
|
|
1262
1237
|
}
|
|
1263
|
-
/**
|
|
1264
|
-
* @param input
|
|
1265
|
-
* @category TPaaS Tracking
|
|
1266
|
-
*/
|
|
1267
|
-
async trackViewLockedVideo(input) {
|
|
1268
|
-
// despite the name, this is not a page-level event. trackViewLockedVideoPage is a page-level event
|
|
1269
|
-
// as such, we don't support (yet) automatic leave event enabling
|
|
1270
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1271
|
-
const event = (0, tpaas_event_builder_1.buildViewLockedVideoEvent)(input, dependencies);
|
|
1272
|
-
return this.sendTpaasEvent(event);
|
|
1273
|
-
}
|
|
1274
1238
|
/**
|
|
1275
1239
|
* @param input
|
|
1276
1240
|
* @param options
|
|
@@ -1278,7 +1242,7 @@ class Tracker {
|
|
|
1278
1242
|
*/
|
|
1279
1243
|
async trackViewLockedVideoPage(input, options) {
|
|
1280
1244
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
1281
|
-
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.
|
|
1245
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewLockedVideoPage.object.objectType);
|
|
1282
1246
|
const dependencies = await this.prepareTpaasEvent();
|
|
1283
1247
|
const event = (0, tpaas_event_builder_1.buildViewLockedVideoPageEvent)(input, dependencies);
|
|
1284
1248
|
const result = this.sendTpaasEvent(event);
|
|
@@ -1301,17 +1265,6 @@ class Tracker {
|
|
|
1301
1265
|
}
|
|
1302
1266
|
return result;
|
|
1303
1267
|
}
|
|
1304
|
-
/**
|
|
1305
|
-
* @param input
|
|
1306
|
-
* @category TPaaS Tracking
|
|
1307
|
-
*/
|
|
1308
|
-
async trackViewVideo(input) {
|
|
1309
|
-
// despite the View event type, this is not a page view event, but rather a media object view event
|
|
1310
|
-
// so we shouldn't reset the page view ID here or enable leave tracking
|
|
1311
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1312
|
-
const event = (0, tpaas_event_builder_1.buildViewVideoEvent)(input, dependencies);
|
|
1313
|
-
return this.sendTpaasEvent(event);
|
|
1314
|
-
}
|
|
1315
1268
|
/**
|
|
1316
1269
|
* Tracks a View VideoPage event and automatically fires a Leave VideoPage event when the user
|
|
1317
1270
|
* navigates away.
|
|
@@ -1356,7 +1309,7 @@ class Tracker {
|
|
|
1356
1309
|
*/
|
|
1357
1310
|
async trackViewVideoPage(input, options) {
|
|
1358
1311
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
1359
|
-
this.setCurrentPage(input.object.objectId,
|
|
1312
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewVideoPage.object.objectType);
|
|
1360
1313
|
const dependencies = await this.prepareTpaasEvent();
|
|
1361
1314
|
const event = (0, tpaas_event_builder_1.buildViewVideoPageEvent)(input, dependencies);
|
|
1362
1315
|
const result = this.sendTpaasEvent(event);
|
|
@@ -1478,15 +1431,6 @@ class Tracker {
|
|
|
1478
1431
|
const event = (0, tpaas_event_builder_1.buildLeaveLockedArticleEvent)(input, dependencies);
|
|
1479
1432
|
return this.sendTpaasEvent(event);
|
|
1480
1433
|
}
|
|
1481
|
-
/**
|
|
1482
|
-
* @param input
|
|
1483
|
-
* @category TPaaS Tracking
|
|
1484
|
-
*/
|
|
1485
|
-
async trackLeaveLockedAudio(input) {
|
|
1486
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1487
|
-
const event = (0, tpaas_event_builder_1.buildLeaveLockedAudioEvent)(input, dependencies);
|
|
1488
|
-
return this.sendTpaasEvent(event);
|
|
1489
|
-
}
|
|
1490
1434
|
/**
|
|
1491
1435
|
* @param input
|
|
1492
1436
|
* @category TPaaS Tracking
|
|
@@ -1496,15 +1440,6 @@ class Tracker {
|
|
|
1496
1440
|
const event = (0, tpaas_event_builder_1.buildLeaveLockedAudioPageEvent)(input, dependencies);
|
|
1497
1441
|
return this.sendTpaasEvent(event);
|
|
1498
1442
|
}
|
|
1499
|
-
/**
|
|
1500
|
-
* @param input
|
|
1501
|
-
* @category TPaaS Tracking
|
|
1502
|
-
*/
|
|
1503
|
-
async trackLeaveLockedVideo(input) {
|
|
1504
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1505
|
-
const event = (0, tpaas_event_builder_1.buildLeaveLockedVideoEvent)(input, dependencies);
|
|
1506
|
-
return this.sendTpaasEvent(event);
|
|
1507
|
-
}
|
|
1508
1443
|
/**
|
|
1509
1444
|
* @param input
|
|
1510
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
|
/**
|
|
@@ -395,6 +400,9 @@ export default class Tracker {
|
|
|
395
400
|
return {
|
|
396
401
|
name: exp.name || exp.id,
|
|
397
402
|
variant: exp.variant || '',
|
|
403
|
+
experimentSdrn: exp.id,
|
|
404
|
+
platform: exp.platform || '',
|
|
405
|
+
testId: exp.custom?.testId,
|
|
398
406
|
};
|
|
399
407
|
});
|
|
400
408
|
}
|
|
@@ -735,7 +743,7 @@ export default class Tracker {
|
|
|
735
743
|
}
|
|
736
744
|
async trackViewHealthPage(input, options) {
|
|
737
745
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
738
|
-
this.setCurrentPage(input.object.objectId,
|
|
746
|
+
this.setCurrentPage(input.object.objectId, ViewHealthPage.object.objectType);
|
|
739
747
|
const dependencies = await this.prepareTpaasEvent();
|
|
740
748
|
const event = buildViewHealthPageEvent(input, dependencies);
|
|
741
749
|
const result = this.sendTpaasEvent(event);
|
|
@@ -809,7 +817,7 @@ export default class Tracker {
|
|
|
809
817
|
*/
|
|
810
818
|
async trackViewSportsPage(input, options) {
|
|
811
819
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
812
|
-
this.setCurrentPage(input.object.objectId,
|
|
820
|
+
this.setCurrentPage(input.object.objectId, ViewSportsPage.object.objectType);
|
|
813
821
|
const dependencies = await this.prepareTpaasEvent();
|
|
814
822
|
const event = buildViewSportsPageEvent(input, dependencies);
|
|
815
823
|
const result = this.sendTpaasEvent(event);
|
|
@@ -853,15 +861,6 @@ export default class Tracker {
|
|
|
853
861
|
const event = buildImpressionWidgetEvent(input, dependencies);
|
|
854
862
|
return this.sendTpaasEvent(event);
|
|
855
863
|
}
|
|
856
|
-
/**
|
|
857
|
-
* @param input
|
|
858
|
-
* @category TPaaS Tracking
|
|
859
|
-
*/
|
|
860
|
-
async trackImpressionAdSlot(input) {
|
|
861
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
862
|
-
const event = buildImpressionAdSlotEvent(input, dependencies);
|
|
863
|
-
return this.sendTpaasEvent(event);
|
|
864
|
-
}
|
|
865
864
|
/**
|
|
866
865
|
* @param input
|
|
867
866
|
* @param options
|
|
@@ -892,18 +891,6 @@ export default class Tracker {
|
|
|
892
891
|
}
|
|
893
892
|
return result;
|
|
894
893
|
}
|
|
895
|
-
/**
|
|
896
|
-
* @param input
|
|
897
|
-
* @param options
|
|
898
|
-
* @category TPaaS Tracking
|
|
899
|
-
*/
|
|
900
|
-
async trackViewAudio(input) {
|
|
901
|
-
// despite the View event type, this is not a page view event, but rather a media object view event
|
|
902
|
-
// so we shouldn't reset the page view ID here or enable leave tracking
|
|
903
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
904
|
-
const event = buildViewAudioEvent(input, dependencies);
|
|
905
|
-
return this.sendTpaasEvent(event);
|
|
906
|
-
}
|
|
907
894
|
/**
|
|
908
895
|
* Tracks a View AudioPage event and automatically fires a Leave AudioPage event when the user
|
|
909
896
|
* navigates away.
|
|
@@ -946,7 +933,7 @@ export default class Tracker {
|
|
|
946
933
|
*/
|
|
947
934
|
async trackViewAudioPage(input, options) {
|
|
948
935
|
this.newPageView();
|
|
949
|
-
this.setCurrentPage(input.object.objectId,
|
|
936
|
+
this.setCurrentPage(input.object.objectId, ViewAudioPage.object.objectType);
|
|
950
937
|
const dependencies = await this.prepareTpaasEvent();
|
|
951
938
|
const event = buildViewAudioPageEvent(input, dependencies);
|
|
952
939
|
const result = this.sendTpaasEvent(event);
|
|
@@ -1175,18 +1162,6 @@ export default class Tracker {
|
|
|
1175
1162
|
}
|
|
1176
1163
|
return result;
|
|
1177
1164
|
}
|
|
1178
|
-
/**
|
|
1179
|
-
* @param input
|
|
1180
|
-
* @param options
|
|
1181
|
-
* @category TPaaS Tracking
|
|
1182
|
-
*/
|
|
1183
|
-
async trackViewLockedAudio(input) {
|
|
1184
|
-
// despite the View event type, this is not a page view event, but rather a media object view event
|
|
1185
|
-
// so we shouldn't reset the page view ID here or enable leave tracking
|
|
1186
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1187
|
-
const event = buildViewLockedAudioEvent(input, dependencies);
|
|
1188
|
-
return this.sendTpaasEvent(event);
|
|
1189
|
-
}
|
|
1190
1165
|
/**
|
|
1191
1166
|
* @param input
|
|
1192
1167
|
* @param options
|
|
@@ -1194,7 +1169,7 @@ export default class Tracker {
|
|
|
1194
1169
|
*/
|
|
1195
1170
|
async trackViewLockedAudioPage(input, options) {
|
|
1196
1171
|
this.newPageView();
|
|
1197
|
-
this.setCurrentPage(input.object.objectId,
|
|
1172
|
+
this.setCurrentPage(input.object.objectId, ViewLockedAudioPage.object.objectType);
|
|
1198
1173
|
const dependencies = await this.prepareTpaasEvent();
|
|
1199
1174
|
const event = buildViewLockedAudioPageEvent(input, dependencies);
|
|
1200
1175
|
const result = this.sendTpaasEvent(event);
|
|
@@ -1217,17 +1192,6 @@ export default class Tracker {
|
|
|
1217
1192
|
}
|
|
1218
1193
|
return result;
|
|
1219
1194
|
}
|
|
1220
|
-
/**
|
|
1221
|
-
* @param input
|
|
1222
|
-
* @category TPaaS Tracking
|
|
1223
|
-
*/
|
|
1224
|
-
async trackViewLockedVideo(input) {
|
|
1225
|
-
// despite the name, this is not a page-level event. trackViewLockedVideoPage is a page-level event
|
|
1226
|
-
// as such, we don't support (yet) automatic leave event enabling
|
|
1227
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1228
|
-
const event = buildViewLockedVideoEvent(input, dependencies);
|
|
1229
|
-
return this.sendTpaasEvent(event);
|
|
1230
|
-
}
|
|
1231
1195
|
/**
|
|
1232
1196
|
* @param input
|
|
1233
1197
|
* @param options
|
|
@@ -1235,7 +1199,7 @@ export default class Tracker {
|
|
|
1235
1199
|
*/
|
|
1236
1200
|
async trackViewLockedVideoPage(input, options) {
|
|
1237
1201
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
1238
|
-
this.setCurrentPage(input.object.objectId,
|
|
1202
|
+
this.setCurrentPage(input.object.objectId, ViewLockedVideoPage.object.objectType);
|
|
1239
1203
|
const dependencies = await this.prepareTpaasEvent();
|
|
1240
1204
|
const event = buildViewLockedVideoPageEvent(input, dependencies);
|
|
1241
1205
|
const result = this.sendTpaasEvent(event);
|
|
@@ -1258,17 +1222,6 @@ export default class Tracker {
|
|
|
1258
1222
|
}
|
|
1259
1223
|
return result;
|
|
1260
1224
|
}
|
|
1261
|
-
/**
|
|
1262
|
-
* @param input
|
|
1263
|
-
* @category TPaaS Tracking
|
|
1264
|
-
*/
|
|
1265
|
-
async trackViewVideo(input) {
|
|
1266
|
-
// despite the View event type, this is not a page view event, but rather a media object view event
|
|
1267
|
-
// so we shouldn't reset the page view ID here or enable leave tracking
|
|
1268
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1269
|
-
const event = buildViewVideoEvent(input, dependencies);
|
|
1270
|
-
return this.sendTpaasEvent(event);
|
|
1271
|
-
}
|
|
1272
1225
|
/**
|
|
1273
1226
|
* Tracks a View VideoPage event and automatically fires a Leave VideoPage event when the user
|
|
1274
1227
|
* navigates away.
|
|
@@ -1313,7 +1266,7 @@ export default class Tracker {
|
|
|
1313
1266
|
*/
|
|
1314
1267
|
async trackViewVideoPage(input, options) {
|
|
1315
1268
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
1316
|
-
this.setCurrentPage(input.object.objectId,
|
|
1269
|
+
this.setCurrentPage(input.object.objectId, ViewVideoPage.object.objectType);
|
|
1317
1270
|
const dependencies = await this.prepareTpaasEvent();
|
|
1318
1271
|
const event = buildViewVideoPageEvent(input, dependencies);
|
|
1319
1272
|
const result = this.sendTpaasEvent(event);
|
|
@@ -1435,15 +1388,6 @@ export default class Tracker {
|
|
|
1435
1388
|
const event = buildLeaveLockedArticleEvent(input, dependencies);
|
|
1436
1389
|
return this.sendTpaasEvent(event);
|
|
1437
1390
|
}
|
|
1438
|
-
/**
|
|
1439
|
-
* @param input
|
|
1440
|
-
* @category TPaaS Tracking
|
|
1441
|
-
*/
|
|
1442
|
-
async trackLeaveLockedAudio(input) {
|
|
1443
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1444
|
-
const event = buildLeaveLockedAudioEvent(input, dependencies);
|
|
1445
|
-
return this.sendTpaasEvent(event);
|
|
1446
|
-
}
|
|
1447
1391
|
/**
|
|
1448
1392
|
* @param input
|
|
1449
1393
|
* @category TPaaS Tracking
|
|
@@ -1453,15 +1397,6 @@ export default class Tracker {
|
|
|
1453
1397
|
const event = buildLeaveLockedAudioPageEvent(input, dependencies);
|
|
1454
1398
|
return this.sendTpaasEvent(event);
|
|
1455
1399
|
}
|
|
1456
|
-
/**
|
|
1457
|
-
* @param input
|
|
1458
|
-
* @category TPaaS Tracking
|
|
1459
|
-
*/
|
|
1460
|
-
async trackLeaveLockedVideo(input) {
|
|
1461
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1462
|
-
const event = buildLeaveLockedVideoEvent(input, dependencies);
|
|
1463
|
-
return this.sendTpaasEvent(event);
|
|
1464
|
-
}
|
|
1465
1400
|
/**
|
|
1466
1401
|
* @param input
|
|
1467
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';
|