@schibsted/pulse-sdk 8.0.0-rc.4 → 8.0.0-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Tracker.js +75 -188
- package/dist/cjs/builders/actor.js +3 -3
- package/dist/cjs/identity/actor.js +18 -6
- package/dist/cjs/leaveTrackingTpaas/constants.js +2 -7
- package/dist/cjs/leaveTrackingTpaas/index.js +52 -40
- package/dist/cjs/tracker-proxy/consts.js +2 -7
- package/dist/cjs/version.js +1 -1
- package/dist/ejs/Tracker.js +77 -190
- package/dist/ejs/builders/actor.js +2 -2
- package/dist/ejs/identity/actor.js +19 -7
- package/dist/ejs/leaveTrackingTpaas/constants.js +1 -5
- package/dist/ejs/leaveTrackingTpaas/index.js +53 -41
- package/dist/ejs/tracker-proxy/consts.js +2 -7
- package/dist/ejs/version.js +1 -1
- package/dist/types/Tracker.d.ts +18 -56
- 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/index.d.ts +1 -1
- package/dist/types/leaveTrackingTpaas/constants.d.ts +1 -5
- package/dist/types/leaveTrackingTpaas/index.d.ts +6 -6
- package/dist/types/leaveTrackingTpaas/types.d.ts +1 -9
- package/dist/types/tracker-proxy/consts.d.ts +1 -1
- package/dist/types/types.d.ts +19 -13
- package/dist/types/version.d.ts +1 -1
- package/node_modules/@schibsted/pulse-utils/package.json +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 +607 -1018
- 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 +2 -2
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
|
/**
|
|
@@ -466,7 +471,6 @@ class Tracker {
|
|
|
466
471
|
};
|
|
467
472
|
}
|
|
468
473
|
/**
|
|
469
|
-
*
|
|
470
474
|
* @private
|
|
471
475
|
* @category TPaaS Tracking
|
|
472
476
|
*/
|
|
@@ -781,19 +785,18 @@ class Tracker {
|
|
|
781
785
|
}
|
|
782
786
|
async trackViewHealthPage(input, options) {
|
|
783
787
|
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,
|
|
788
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewHealthPage.object.objectType);
|
|
785
789
|
const dependencies = await this.prepareTpaasEvent();
|
|
786
790
|
const event = (0, tpaas_event_builder_1.buildViewHealthPageEvent)(input, dependencies);
|
|
787
791
|
const result = this.sendTpaasEvent(event);
|
|
788
792
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
789
|
-
const
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
this.trackLeavePage({
|
|
793
|
+
const leavePageCallback = async (leave) => {
|
|
794
|
+
// HealthView Page is a bit special, in the sense that in doesn't have a dedicated Leave event.
|
|
795
|
+
// Instead, we need to reuse the generic Leave Page event, but adapt the input accordingly.
|
|
796
|
+
// This means omitting some fields from HealthView Page that are not part of Leave Page schema.
|
|
797
|
+
const { experiments, metrics, object, origin, ...restInput } = input;
|
|
798
|
+
const { category, custom, intent, name, tags, ...restObject } = input.object;
|
|
799
|
+
await this.trackLeavePage({
|
|
797
800
|
leave,
|
|
798
801
|
...restInput,
|
|
799
802
|
object: {
|
|
@@ -803,10 +806,7 @@ class Tracker {
|
|
|
803
806
|
});
|
|
804
807
|
};
|
|
805
808
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
806
|
-
|
|
807
|
-
pageElement,
|
|
808
|
-
objectResizable,
|
|
809
|
-
heightBuilder,
|
|
809
|
+
...options.leaveTracking,
|
|
810
810
|
schema: tpaas_schemas_1.LeavePage.object.objectType,
|
|
811
811
|
trackMethod: leavePageCallback,
|
|
812
812
|
});
|
|
@@ -830,18 +830,15 @@ class Tracker {
|
|
|
830
830
|
const event = (0, tpaas_event_builder_1.buildViewPageEvent)(input, dependencies);
|
|
831
831
|
const result = this.sendTpaasEvent(event);
|
|
832
832
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
833
|
-
const
|
|
834
|
-
|
|
835
|
-
this.trackLeavePage({
|
|
833
|
+
const leavePageCallback = async (leave) => {
|
|
834
|
+
const { metrics, ...rest } = input; // metrics are not part of LeavePage schema, so we need to omit them
|
|
835
|
+
await this.trackLeavePage({
|
|
836
836
|
leave,
|
|
837
|
-
...
|
|
837
|
+
...rest,
|
|
838
838
|
});
|
|
839
839
|
};
|
|
840
840
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
841
|
-
|
|
842
|
-
pageElement,
|
|
843
|
-
objectResizable,
|
|
844
|
-
heightBuilder,
|
|
841
|
+
...options.leaveTracking,
|
|
845
842
|
schema: tpaas_schemas_1.LeavePage.object.objectType,
|
|
846
843
|
trackMethod: leavePageCallback,
|
|
847
844
|
});
|
|
@@ -855,23 +852,19 @@ class Tracker {
|
|
|
855
852
|
*/
|
|
856
853
|
async trackViewSportsPage(input, options) {
|
|
857
854
|
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,
|
|
855
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewSportsPage.object.objectType);
|
|
859
856
|
const dependencies = await this.prepareTpaasEvent();
|
|
860
857
|
const event = (0, tpaas_event_builder_1.buildViewSportsPageEvent)(input, dependencies);
|
|
861
858
|
const result = this.sendTpaasEvent(event);
|
|
862
859
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
863
|
-
const
|
|
864
|
-
|
|
865
|
-
this.trackLeaveSportsPage({
|
|
860
|
+
const leaveSportsPageCallback = async (leave) => {
|
|
861
|
+
await this.trackLeaveSportsPage({
|
|
866
862
|
leave,
|
|
867
863
|
...input,
|
|
868
864
|
});
|
|
869
865
|
};
|
|
870
866
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
871
|
-
|
|
872
|
-
pageElement,
|
|
873
|
-
objectResizable,
|
|
874
|
-
heightBuilder,
|
|
867
|
+
...options.leaveTracking,
|
|
875
868
|
schema: tpaas_schemas_1.LeaveSportsPage.object.objectType,
|
|
876
869
|
trackMethod: leaveSportsPageCallback,
|
|
877
870
|
});
|
|
@@ -899,15 +892,6 @@ class Tracker {
|
|
|
899
892
|
const event = (0, tpaas_event_builder_1.buildImpressionWidgetEvent)(input, dependencies);
|
|
900
893
|
return this.sendTpaasEvent(event);
|
|
901
894
|
}
|
|
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
895
|
/**
|
|
912
896
|
* @param input
|
|
913
897
|
* @param options
|
|
@@ -920,36 +904,23 @@ class Tracker {
|
|
|
920
904
|
const event = (0, tpaas_event_builder_1.buildViewArticleEvent)(input, dependencies);
|
|
921
905
|
const result = this.sendTpaasEvent(event);
|
|
922
906
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
923
|
-
const
|
|
924
|
-
|
|
925
|
-
|
|
907
|
+
const leaveArticleCallback = async (leave) => {
|
|
908
|
+
// omit these properties from LeaveArticle because they're not part of the LeaveArticle schema
|
|
909
|
+
const { authors, hotness, lifetime, sponsor, wordCount, ...rest } = input.object;
|
|
910
|
+
await this.trackLeaveArticle({
|
|
926
911
|
leave,
|
|
927
912
|
...input,
|
|
913
|
+
object: rest,
|
|
928
914
|
});
|
|
929
915
|
};
|
|
930
916
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
931
|
-
|
|
932
|
-
pageElement,
|
|
933
|
-
heightBuilder,
|
|
934
|
-
objectResizable,
|
|
917
|
+
...options.leaveTracking,
|
|
935
918
|
schema: tpaas_schemas_1.LeaveArticle.object.objectType,
|
|
936
919
|
trackMethod: leaveArticleCallback,
|
|
937
920
|
});
|
|
938
921
|
}
|
|
939
922
|
return result;
|
|
940
923
|
}
|
|
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
924
|
/**
|
|
954
925
|
* Tracks a View AudioPage event and automatically fires a Leave AudioPage event when the user
|
|
955
926
|
* navigates away.
|
|
@@ -992,20 +963,20 @@ class Tracker {
|
|
|
992
963
|
*/
|
|
993
964
|
async trackViewAudioPage(input, options) {
|
|
994
965
|
this.newPageView();
|
|
995
|
-
this.setCurrentPage(input.object.objectId,
|
|
966
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewAudioPage.object.objectType);
|
|
996
967
|
const dependencies = await this.prepareTpaasEvent();
|
|
997
968
|
const event = (0, tpaas_event_builder_1.buildViewAudioPageEvent)(input, dependencies);
|
|
998
969
|
const result = this.sendTpaasEvent(event);
|
|
999
970
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1000
|
-
const {
|
|
1001
|
-
const leaveAudioPageCallback = (leave) => {
|
|
971
|
+
const { leaveAudioBuilder, ...restLeaveTrackingOptions } = options.leaveTracking;
|
|
972
|
+
const leaveAudioPageCallback = async (leave) => {
|
|
1002
973
|
const leaveAudioInput = leaveAudioBuilder?.() ?? {
|
|
1003
974
|
audioCompleted: 0,
|
|
1004
975
|
audioStarted: 0,
|
|
1005
976
|
maxPlaylistPosition: 0,
|
|
1006
977
|
playlistPositionPercentage: 0,
|
|
1007
978
|
};
|
|
1008
|
-
this.trackLeaveAudioPage({
|
|
979
|
+
await this.trackLeaveAudioPage({
|
|
1009
980
|
leave,
|
|
1010
981
|
leaveAudio: {
|
|
1011
982
|
...leaveAudioInput,
|
|
@@ -1016,10 +987,7 @@ class Tracker {
|
|
|
1016
987
|
});
|
|
1017
988
|
};
|
|
1018
989
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1019
|
-
|
|
1020
|
-
pageElement,
|
|
1021
|
-
heightBuilder,
|
|
1022
|
-
objectResizable,
|
|
990
|
+
...restLeaveTrackingOptions,
|
|
1023
991
|
schema: tpaas_schemas_1.LeaveAudioPage.object.objectType,
|
|
1024
992
|
trackMethod: leaveAudioPageCallback,
|
|
1025
993
|
});
|
|
@@ -1038,18 +1006,14 @@ class Tracker {
|
|
|
1038
1006
|
const event = (0, tpaas_event_builder_1.buildViewErrorEvent)(input, dependencies);
|
|
1039
1007
|
const result = this.sendTpaasEvent(event);
|
|
1040
1008
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1041
|
-
const
|
|
1042
|
-
|
|
1043
|
-
this.trackLeaveError({
|
|
1009
|
+
const leaveErrorCallback = async (leave) => {
|
|
1010
|
+
await this.trackLeaveError({
|
|
1044
1011
|
leave,
|
|
1045
1012
|
...input,
|
|
1046
1013
|
});
|
|
1047
1014
|
};
|
|
1048
1015
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1049
|
-
|
|
1050
|
-
pageElement,
|
|
1051
|
-
heightBuilder,
|
|
1052
|
-
objectResizable,
|
|
1016
|
+
...options.leaveTracking,
|
|
1053
1017
|
schema: tpaas_schemas_1.LeaveError.object.objectType,
|
|
1054
1018
|
trackMethod: leaveErrorCallback,
|
|
1055
1019
|
});
|
|
@@ -1113,18 +1077,15 @@ class Tracker {
|
|
|
1113
1077
|
const event = (0, tpaas_event_builder_1.buildViewFrontpageEvent)(input, dependencies);
|
|
1114
1078
|
const result = this.sendTpaasEvent(event);
|
|
1115
1079
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1116
|
-
const
|
|
1117
|
-
|
|
1118
|
-
this.trackLeaveFrontpage({
|
|
1080
|
+
const leaveFrontpageCallback = async (leave) => {
|
|
1081
|
+
const { metrics, ...rest } = input; // metrics are not part of LeaveFrontpage schema, so we need to omit them
|
|
1082
|
+
await this.trackLeaveFrontpage({
|
|
1119
1083
|
leave,
|
|
1120
|
-
...
|
|
1084
|
+
...rest,
|
|
1121
1085
|
});
|
|
1122
1086
|
};
|
|
1123
1087
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1124
|
-
|
|
1125
|
-
pageElement,
|
|
1126
|
-
objectResizable,
|
|
1127
|
-
heightBuilder,
|
|
1088
|
+
...options.leaveTracking,
|
|
1128
1089
|
schema: tpaas_schemas_1.LeaveFrontpage.object.objectType,
|
|
1129
1090
|
trackMethod: leaveFrontpageCallback,
|
|
1130
1091
|
});
|
|
@@ -1143,18 +1104,14 @@ class Tracker {
|
|
|
1143
1104
|
const event = (0, tpaas_event_builder_1.buildViewLandingpageEvent)(input, dependencies);
|
|
1144
1105
|
const result = this.sendTpaasEvent(event);
|
|
1145
1106
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1146
|
-
const
|
|
1147
|
-
|
|
1148
|
-
this.trackLeaveLandingpage({
|
|
1107
|
+
const leaveLandingpageCallback = async (leave) => {
|
|
1108
|
+
await this.trackLeaveLandingpage({
|
|
1149
1109
|
leave,
|
|
1150
1110
|
...input,
|
|
1151
1111
|
});
|
|
1152
1112
|
};
|
|
1153
1113
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1154
|
-
|
|
1155
|
-
pageElement,
|
|
1156
|
-
heightBuilder,
|
|
1157
|
-
objectResizable,
|
|
1114
|
+
...options.leaveTracking,
|
|
1158
1115
|
schema: tpaas_schemas_1.LeaveLandingpage.object.objectType,
|
|
1159
1116
|
trackMethod: leaveLandingpageCallback,
|
|
1160
1117
|
});
|
|
@@ -1173,18 +1130,14 @@ class Tracker {
|
|
|
1173
1130
|
const event = (0, tpaas_event_builder_1.buildViewListingEvent)(input, dependencies);
|
|
1174
1131
|
const result = this.sendTpaasEvent(event);
|
|
1175
1132
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1176
|
-
const
|
|
1177
|
-
|
|
1178
|
-
this.trackLeaveListing({
|
|
1133
|
+
const leaveListingCallback = async (leave) => {
|
|
1134
|
+
await this.trackLeaveListing({
|
|
1179
1135
|
leave,
|
|
1180
1136
|
...input,
|
|
1181
1137
|
});
|
|
1182
1138
|
};
|
|
1183
1139
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1184
|
-
|
|
1185
|
-
pageElement,
|
|
1186
|
-
heightBuilder,
|
|
1187
|
-
objectResizable,
|
|
1140
|
+
...options.leaveTracking,
|
|
1188
1141
|
schema: tpaas_schemas_1.LeaveListing.object.objectType,
|
|
1189
1142
|
trackMethod: leaveListingCallback,
|
|
1190
1143
|
});
|
|
@@ -1203,36 +1156,23 @@ class Tracker {
|
|
|
1203
1156
|
const event = (0, tpaas_event_builder_1.buildViewLockedArticleEvent)(input, dependencies);
|
|
1204
1157
|
const result = this.sendTpaasEvent(event);
|
|
1205
1158
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1206
|
-
const
|
|
1207
|
-
|
|
1208
|
-
|
|
1159
|
+
const leaveLockedArticleCallback = async (leave) => {
|
|
1160
|
+
// omit these properties because they're not part of the LeaveLockedArticle schema
|
|
1161
|
+
const { authors, hotness, lifetime, sponsor, wordCount, ...rest } = input.object;
|
|
1162
|
+
await this.trackLeaveLockedArticle({
|
|
1209
1163
|
leave,
|
|
1210
1164
|
...input,
|
|
1165
|
+
object: rest,
|
|
1211
1166
|
});
|
|
1212
1167
|
};
|
|
1213
1168
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1214
|
-
|
|
1215
|
-
pageElement,
|
|
1216
|
-
objectResizable,
|
|
1217
|
-
heightBuilder,
|
|
1169
|
+
...options.leaveTracking,
|
|
1218
1170
|
schema: tpaas_schemas_1.LeaveLockedArticle.object.objectType,
|
|
1219
1171
|
trackMethod: leaveLockedArticleCallback,
|
|
1220
1172
|
});
|
|
1221
1173
|
}
|
|
1222
1174
|
return result;
|
|
1223
1175
|
}
|
|
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
1176
|
/**
|
|
1237
1177
|
* @param input
|
|
1238
1178
|
* @param options
|
|
@@ -1240,40 +1180,25 @@ class Tracker {
|
|
|
1240
1180
|
*/
|
|
1241
1181
|
async trackViewLockedAudioPage(input, options) {
|
|
1242
1182
|
this.newPageView();
|
|
1243
|
-
this.setCurrentPage(input.object.objectId,
|
|
1183
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewLockedAudioPage.object.objectType);
|
|
1244
1184
|
const dependencies = await this.prepareTpaasEvent();
|
|
1245
1185
|
const event = (0, tpaas_event_builder_1.buildViewLockedAudioPageEvent)(input, dependencies);
|
|
1246
1186
|
const result = this.sendTpaasEvent(event);
|
|
1247
1187
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1248
|
-
const
|
|
1249
|
-
|
|
1250
|
-
this.trackLeaveLockedAudioPage({
|
|
1188
|
+
const leaveLockedAudioPageCallback = async (leave) => {
|
|
1189
|
+
await this.trackLeaveLockedAudioPage({
|
|
1251
1190
|
leave,
|
|
1252
1191
|
...input,
|
|
1253
1192
|
});
|
|
1254
1193
|
};
|
|
1255
1194
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1256
|
-
|
|
1257
|
-
pageElement,
|
|
1258
|
-
heightBuilder,
|
|
1259
|
-
objectResizable,
|
|
1195
|
+
...options.leaveTracking,
|
|
1260
1196
|
schema: tpaas_schemas_1.LeaveLockedAudioPage.object.objectType,
|
|
1261
1197
|
trackMethod: leaveLockedAudioPageCallback,
|
|
1262
1198
|
});
|
|
1263
1199
|
}
|
|
1264
1200
|
return result;
|
|
1265
1201
|
}
|
|
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
1202
|
/**
|
|
1278
1203
|
* @param input
|
|
1279
1204
|
* @param options
|
|
@@ -1281,40 +1206,25 @@ class Tracker {
|
|
|
1281
1206
|
*/
|
|
1282
1207
|
async trackViewLockedVideoPage(input, options) {
|
|
1283
1208
|
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.
|
|
1209
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewLockedVideoPage.object.objectType);
|
|
1285
1210
|
const dependencies = await this.prepareTpaasEvent();
|
|
1286
1211
|
const event = (0, tpaas_event_builder_1.buildViewLockedVideoPageEvent)(input, dependencies);
|
|
1287
1212
|
const result = this.sendTpaasEvent(event);
|
|
1288
1213
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1289
|
-
const
|
|
1290
|
-
|
|
1291
|
-
this.trackLeaveLockedVideoPage({
|
|
1214
|
+
const leaveLockedVideoPageCallback = async (leave) => {
|
|
1215
|
+
await this.trackLeaveLockedVideoPage({
|
|
1292
1216
|
leave,
|
|
1293
1217
|
...input,
|
|
1294
1218
|
});
|
|
1295
1219
|
};
|
|
1296
1220
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1297
|
-
|
|
1298
|
-
pageElement,
|
|
1299
|
-
heightBuilder,
|
|
1300
|
-
objectResizable,
|
|
1221
|
+
...options.leaveTracking,
|
|
1301
1222
|
schema: tpaas_schemas_1.LeaveLockedVideoPage.object.objectType,
|
|
1302
1223
|
trackMethod: leaveLockedVideoPageCallback,
|
|
1303
1224
|
});
|
|
1304
1225
|
}
|
|
1305
1226
|
return result;
|
|
1306
1227
|
}
|
|
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
1228
|
/**
|
|
1319
1229
|
* Tracks a View VideoPage event and automatically fires a Leave VideoPage event when the user
|
|
1320
1230
|
* navigates away.
|
|
@@ -1359,15 +1269,15 @@ class Tracker {
|
|
|
1359
1269
|
*/
|
|
1360
1270
|
async trackViewVideoPage(input, options) {
|
|
1361
1271
|
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,
|
|
1272
|
+
this.setCurrentPage(input.object.objectId, tpaas_schemas_1.ViewVideoPage.object.objectType);
|
|
1363
1273
|
const dependencies = await this.prepareTpaasEvent();
|
|
1364
1274
|
const event = (0, tpaas_event_builder_1.buildViewVideoPageEvent)(input, dependencies);
|
|
1365
1275
|
const result = this.sendTpaasEvent(event);
|
|
1366
1276
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1367
|
-
const {
|
|
1368
|
-
const leaveVideoCallback = (leave) => {
|
|
1277
|
+
const { leaveStoriesBuilder, ...restLeaveTrackingOptions } = options.leaveTracking;
|
|
1278
|
+
const leaveVideoCallback = async (leave) => {
|
|
1369
1279
|
const leaveStoriesInput = leaveStoriesBuilder?.();
|
|
1370
|
-
this.trackLeaveVideoPage({
|
|
1280
|
+
await this.trackLeaveVideoPage({
|
|
1371
1281
|
leave,
|
|
1372
1282
|
leaveStories: leaveStoriesInput && {
|
|
1373
1283
|
...leaveStoriesInput,
|
|
@@ -1378,10 +1288,7 @@ class Tracker {
|
|
|
1378
1288
|
});
|
|
1379
1289
|
};
|
|
1380
1290
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1381
|
-
|
|
1382
|
-
pageElement,
|
|
1383
|
-
heightBuilder,
|
|
1384
|
-
objectResizable,
|
|
1291
|
+
...restLeaveTrackingOptions,
|
|
1385
1292
|
schema: tpaas_schemas_1.LeaveVideoPage.object.objectType,
|
|
1386
1293
|
trackMethod: leaveVideoCallback,
|
|
1387
1294
|
});
|
|
@@ -1400,18 +1307,16 @@ class Tracker {
|
|
|
1400
1307
|
const event = (0, tpaas_event_builder_1.buildViewWeatherEvent)(input, dependencies);
|
|
1401
1308
|
const result = this.sendTpaasEvent(event);
|
|
1402
1309
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1403
|
-
const
|
|
1404
|
-
|
|
1405
|
-
|
|
1310
|
+
const leaveWeatherCallback = async (leave) => {
|
|
1311
|
+
// omit object and page from input because they're not part of the LeaveWeather schema
|
|
1312
|
+
const { object, page, ...rest } = input;
|
|
1313
|
+
await this.trackLeaveWeather({
|
|
1406
1314
|
leave,
|
|
1407
|
-
...
|
|
1315
|
+
...rest,
|
|
1408
1316
|
});
|
|
1409
1317
|
};
|
|
1410
1318
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1411
|
-
|
|
1412
|
-
pageElement,
|
|
1413
|
-
heightBuilder,
|
|
1414
|
-
objectResizable,
|
|
1319
|
+
...options.leaveTracking,
|
|
1415
1320
|
schema: tpaas_schemas_1.LeaveWeather.object.objectType,
|
|
1416
1321
|
trackMethod: leaveWeatherCallback,
|
|
1417
1322
|
});
|
|
@@ -1481,15 +1386,6 @@ class Tracker {
|
|
|
1481
1386
|
const event = (0, tpaas_event_builder_1.buildLeaveLockedArticleEvent)(input, dependencies);
|
|
1482
1387
|
return this.sendTpaasEvent(event);
|
|
1483
1388
|
}
|
|
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
1389
|
/**
|
|
1494
1390
|
* @param input
|
|
1495
1391
|
* @category TPaaS Tracking
|
|
@@ -1499,15 +1395,6 @@ class Tracker {
|
|
|
1499
1395
|
const event = (0, tpaas_event_builder_1.buildLeaveLockedAudioPageEvent)(input, dependencies);
|
|
1500
1396
|
return this.sendTpaasEvent(event);
|
|
1501
1397
|
}
|
|
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
1398
|
/**
|
|
1512
1399
|
* @param input
|
|
1513
1400
|
* @category TPaaS Tracking
|
|
@@ -2268,8 +2155,8 @@ class Tracker {
|
|
|
2268
2155
|
* with the added guarantee that a second Leave event will not be triggered if one already has been sent.
|
|
2269
2156
|
* @category TPaaS Leave Tracking
|
|
2270
2157
|
*/
|
|
2271
|
-
trackTpaasActiveLeave() {
|
|
2272
|
-
(0, leaveTrackingTpaas_1.trackTpaasActiveLeave)();
|
|
2158
|
+
async trackTpaasActiveLeave() {
|
|
2159
|
+
await (0, leaveTrackingTpaas_1.trackTpaasActiveLeave)();
|
|
2273
2160
|
}
|
|
2274
2161
|
/**
|
|
2275
2162
|
* Check if leave tracking is enabled (if an event will be sent when the user leaves the page)
|
|
@@ -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;
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const DEFAULT_ACTIVITY_DURATION = () => ({
|
|
5
|
-
value: 0,
|
|
6
|
-
interval: undefined,
|
|
7
|
-
timeSinceLastActivity: 0,
|
|
8
|
-
});
|
|
9
|
-
exports.DEFAULT_ACTIVITY_DURATION = DEFAULT_ACTIVITY_DURATION;
|
|
3
|
+
exports.ACTIVITY_DURATION_LIMIT_MS = exports.DEFAULT_PAGE_LEAVE_EVENT = void 0;
|
|
10
4
|
const DEFAULT_PAGE_LEAVE_EVENT = () => ({
|
|
11
5
|
objectViewPercentage: 0,
|
|
12
6
|
maxObjectViewPercentage: 0,
|
|
@@ -16,3 +10,4 @@ const DEFAULT_PAGE_LEAVE_EVENT = () => ({
|
|
|
16
10
|
maxPageScrollPosition: 0,
|
|
17
11
|
});
|
|
18
12
|
exports.DEFAULT_PAGE_LEAVE_EVENT = DEFAULT_PAGE_LEAVE_EVENT;
|
|
13
|
+
exports.ACTIVITY_DURATION_LIMIT_MS = 30000;
|