@schibsted/pulse-sdk 8.0.0-rc.5 → 8.0.0-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Tracker.js +64 -109
- package/dist/cjs/leaveTrackingTpaas/constants.js +2 -7
- package/dist/cjs/leaveTrackingTpaas/index.js +52 -40
- package/dist/cjs/tracker-proxy/consts.js +2 -0
- package/dist/cjs/version.js +1 -1
- package/dist/ejs/Tracker.js +64 -109
- package/dist/ejs/leaveTrackingTpaas/constants.js +1 -5
- package/dist/ejs/leaveTrackingTpaas/index.js +53 -41
- package/dist/ejs/tracker-proxy/consts.js +2 -0
- package/dist/ejs/version.js +1 -1
- package/dist/types/Tracker.d.ts +16 -17
- 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/index.d.ts +10 -2
- package/package.json +3 -3
package/dist/cjs/Tracker.js
CHANGED
|
@@ -471,7 +471,6 @@ class Tracker {
|
|
|
471
471
|
};
|
|
472
472
|
}
|
|
473
473
|
/**
|
|
474
|
-
*
|
|
475
474
|
* @private
|
|
476
475
|
* @category TPaaS Tracking
|
|
477
476
|
*/
|
|
@@ -791,14 +790,13 @@ class Tracker {
|
|
|
791
790
|
const event = (0, tpaas_event_builder_1.buildViewHealthPageEvent)(input, dependencies);
|
|
792
791
|
const result = this.sendTpaasEvent(event);
|
|
793
792
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
794
|
-
const
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
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({
|
|
802
800
|
leave,
|
|
803
801
|
...restInput,
|
|
804
802
|
object: {
|
|
@@ -808,10 +806,7 @@ class Tracker {
|
|
|
808
806
|
});
|
|
809
807
|
};
|
|
810
808
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
811
|
-
|
|
812
|
-
pageElement,
|
|
813
|
-
objectResizable,
|
|
814
|
-
heightBuilder,
|
|
809
|
+
...options.leaveTracking,
|
|
815
810
|
schema: tpaas_schemas_1.LeavePage.object.objectType,
|
|
816
811
|
trackMethod: leavePageCallback,
|
|
817
812
|
});
|
|
@@ -835,18 +830,15 @@ class Tracker {
|
|
|
835
830
|
const event = (0, tpaas_event_builder_1.buildViewPageEvent)(input, dependencies);
|
|
836
831
|
const result = this.sendTpaasEvent(event);
|
|
837
832
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
838
|
-
const
|
|
839
|
-
|
|
840
|
-
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({
|
|
841
836
|
leave,
|
|
842
|
-
...
|
|
837
|
+
...rest,
|
|
843
838
|
});
|
|
844
839
|
};
|
|
845
840
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
846
|
-
|
|
847
|
-
pageElement,
|
|
848
|
-
objectResizable,
|
|
849
|
-
heightBuilder,
|
|
841
|
+
...options.leaveTracking,
|
|
850
842
|
schema: tpaas_schemas_1.LeavePage.object.objectType,
|
|
851
843
|
trackMethod: leavePageCallback,
|
|
852
844
|
});
|
|
@@ -865,18 +857,14 @@ class Tracker {
|
|
|
865
857
|
const event = (0, tpaas_event_builder_1.buildViewSportsPageEvent)(input, dependencies);
|
|
866
858
|
const result = this.sendTpaasEvent(event);
|
|
867
859
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
868
|
-
const
|
|
869
|
-
|
|
870
|
-
this.trackLeaveSportsPage({
|
|
860
|
+
const leaveSportsPageCallback = async (leave) => {
|
|
861
|
+
await this.trackLeaveSportsPage({
|
|
871
862
|
leave,
|
|
872
863
|
...input,
|
|
873
864
|
});
|
|
874
865
|
};
|
|
875
866
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
876
|
-
|
|
877
|
-
pageElement,
|
|
878
|
-
objectResizable,
|
|
879
|
-
heightBuilder,
|
|
867
|
+
...options.leaveTracking,
|
|
880
868
|
schema: tpaas_schemas_1.LeaveSportsPage.object.objectType,
|
|
881
869
|
trackMethod: leaveSportsPageCallback,
|
|
882
870
|
});
|
|
@@ -916,18 +904,17 @@ class Tracker {
|
|
|
916
904
|
const event = (0, tpaas_event_builder_1.buildViewArticleEvent)(input, dependencies);
|
|
917
905
|
const result = this.sendTpaasEvent(event);
|
|
918
906
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
919
|
-
const
|
|
920
|
-
|
|
921
|
-
|
|
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({
|
|
922
911
|
leave,
|
|
923
912
|
...input,
|
|
913
|
+
object: rest,
|
|
924
914
|
});
|
|
925
915
|
};
|
|
926
916
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
927
|
-
|
|
928
|
-
pageElement,
|
|
929
|
-
heightBuilder,
|
|
930
|
-
objectResizable,
|
|
917
|
+
...options.leaveTracking,
|
|
931
918
|
schema: tpaas_schemas_1.LeaveArticle.object.objectType,
|
|
932
919
|
trackMethod: leaveArticleCallback,
|
|
933
920
|
});
|
|
@@ -981,15 +968,15 @@ class Tracker {
|
|
|
981
968
|
const event = (0, tpaas_event_builder_1.buildViewAudioPageEvent)(input, dependencies);
|
|
982
969
|
const result = this.sendTpaasEvent(event);
|
|
983
970
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
984
|
-
const {
|
|
985
|
-
const leaveAudioPageCallback = (leave) => {
|
|
971
|
+
const { leaveAudioBuilder, ...restLeaveTrackingOptions } = options.leaveTracking;
|
|
972
|
+
const leaveAudioPageCallback = async (leave) => {
|
|
986
973
|
const leaveAudioInput = leaveAudioBuilder?.() ?? {
|
|
987
974
|
audioCompleted: 0,
|
|
988
975
|
audioStarted: 0,
|
|
989
976
|
maxPlaylistPosition: 0,
|
|
990
977
|
playlistPositionPercentage: 0,
|
|
991
978
|
};
|
|
992
|
-
this.trackLeaveAudioPage({
|
|
979
|
+
await this.trackLeaveAudioPage({
|
|
993
980
|
leave,
|
|
994
981
|
leaveAudio: {
|
|
995
982
|
...leaveAudioInput,
|
|
@@ -1000,10 +987,7 @@ class Tracker {
|
|
|
1000
987
|
});
|
|
1001
988
|
};
|
|
1002
989
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1003
|
-
|
|
1004
|
-
pageElement,
|
|
1005
|
-
heightBuilder,
|
|
1006
|
-
objectResizable,
|
|
990
|
+
...restLeaveTrackingOptions,
|
|
1007
991
|
schema: tpaas_schemas_1.LeaveAudioPage.object.objectType,
|
|
1008
992
|
trackMethod: leaveAudioPageCallback,
|
|
1009
993
|
});
|
|
@@ -1022,18 +1006,14 @@ class Tracker {
|
|
|
1022
1006
|
const event = (0, tpaas_event_builder_1.buildViewErrorEvent)(input, dependencies);
|
|
1023
1007
|
const result = this.sendTpaasEvent(event);
|
|
1024
1008
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1025
|
-
const
|
|
1026
|
-
|
|
1027
|
-
this.trackLeaveError({
|
|
1009
|
+
const leaveErrorCallback = async (leave) => {
|
|
1010
|
+
await this.trackLeaveError({
|
|
1028
1011
|
leave,
|
|
1029
1012
|
...input,
|
|
1030
1013
|
});
|
|
1031
1014
|
};
|
|
1032
1015
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1033
|
-
|
|
1034
|
-
pageElement,
|
|
1035
|
-
heightBuilder,
|
|
1036
|
-
objectResizable,
|
|
1016
|
+
...options.leaveTracking,
|
|
1037
1017
|
schema: tpaas_schemas_1.LeaveError.object.objectType,
|
|
1038
1018
|
trackMethod: leaveErrorCallback,
|
|
1039
1019
|
});
|
|
@@ -1097,18 +1077,15 @@ class Tracker {
|
|
|
1097
1077
|
const event = (0, tpaas_event_builder_1.buildViewFrontpageEvent)(input, dependencies);
|
|
1098
1078
|
const result = this.sendTpaasEvent(event);
|
|
1099
1079
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1100
|
-
const
|
|
1101
|
-
|
|
1102
|
-
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({
|
|
1103
1083
|
leave,
|
|
1104
|
-
...
|
|
1084
|
+
...rest,
|
|
1105
1085
|
});
|
|
1106
1086
|
};
|
|
1107
1087
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1108
|
-
|
|
1109
|
-
pageElement,
|
|
1110
|
-
objectResizable,
|
|
1111
|
-
heightBuilder,
|
|
1088
|
+
...options.leaveTracking,
|
|
1112
1089
|
schema: tpaas_schemas_1.LeaveFrontpage.object.objectType,
|
|
1113
1090
|
trackMethod: leaveFrontpageCallback,
|
|
1114
1091
|
});
|
|
@@ -1127,18 +1104,14 @@ class Tracker {
|
|
|
1127
1104
|
const event = (0, tpaas_event_builder_1.buildViewLandingpageEvent)(input, dependencies);
|
|
1128
1105
|
const result = this.sendTpaasEvent(event);
|
|
1129
1106
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1130
|
-
const
|
|
1131
|
-
|
|
1132
|
-
this.trackLeaveLandingpage({
|
|
1107
|
+
const leaveLandingpageCallback = async (leave) => {
|
|
1108
|
+
await this.trackLeaveLandingpage({
|
|
1133
1109
|
leave,
|
|
1134
1110
|
...input,
|
|
1135
1111
|
});
|
|
1136
1112
|
};
|
|
1137
1113
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1138
|
-
|
|
1139
|
-
pageElement,
|
|
1140
|
-
heightBuilder,
|
|
1141
|
-
objectResizable,
|
|
1114
|
+
...options.leaveTracking,
|
|
1142
1115
|
schema: tpaas_schemas_1.LeaveLandingpage.object.objectType,
|
|
1143
1116
|
trackMethod: leaveLandingpageCallback,
|
|
1144
1117
|
});
|
|
@@ -1157,18 +1130,14 @@ class Tracker {
|
|
|
1157
1130
|
const event = (0, tpaas_event_builder_1.buildViewListingEvent)(input, dependencies);
|
|
1158
1131
|
const result = this.sendTpaasEvent(event);
|
|
1159
1132
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1160
|
-
const
|
|
1161
|
-
|
|
1162
|
-
this.trackLeaveListing({
|
|
1133
|
+
const leaveListingCallback = async (leave) => {
|
|
1134
|
+
await this.trackLeaveListing({
|
|
1163
1135
|
leave,
|
|
1164
1136
|
...input,
|
|
1165
1137
|
});
|
|
1166
1138
|
};
|
|
1167
1139
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1168
|
-
|
|
1169
|
-
pageElement,
|
|
1170
|
-
heightBuilder,
|
|
1171
|
-
objectResizable,
|
|
1140
|
+
...options.leaveTracking,
|
|
1172
1141
|
schema: tpaas_schemas_1.LeaveListing.object.objectType,
|
|
1173
1142
|
trackMethod: leaveListingCallback,
|
|
1174
1143
|
});
|
|
@@ -1187,18 +1156,17 @@ class Tracker {
|
|
|
1187
1156
|
const event = (0, tpaas_event_builder_1.buildViewLockedArticleEvent)(input, dependencies);
|
|
1188
1157
|
const result = this.sendTpaasEvent(event);
|
|
1189
1158
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1190
|
-
const
|
|
1191
|
-
|
|
1192
|
-
|
|
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({
|
|
1193
1163
|
leave,
|
|
1194
1164
|
...input,
|
|
1165
|
+
object: rest,
|
|
1195
1166
|
});
|
|
1196
1167
|
};
|
|
1197
1168
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1198
|
-
|
|
1199
|
-
pageElement,
|
|
1200
|
-
objectResizable,
|
|
1201
|
-
heightBuilder,
|
|
1169
|
+
...options.leaveTracking,
|
|
1202
1170
|
schema: tpaas_schemas_1.LeaveLockedArticle.object.objectType,
|
|
1203
1171
|
trackMethod: leaveLockedArticleCallback,
|
|
1204
1172
|
});
|
|
@@ -1217,18 +1185,14 @@ class Tracker {
|
|
|
1217
1185
|
const event = (0, tpaas_event_builder_1.buildViewLockedAudioPageEvent)(input, dependencies);
|
|
1218
1186
|
const result = this.sendTpaasEvent(event);
|
|
1219
1187
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1220
|
-
const
|
|
1221
|
-
|
|
1222
|
-
this.trackLeaveLockedAudioPage({
|
|
1188
|
+
const leaveLockedAudioPageCallback = async (leave) => {
|
|
1189
|
+
await this.trackLeaveLockedAudioPage({
|
|
1223
1190
|
leave,
|
|
1224
1191
|
...input,
|
|
1225
1192
|
});
|
|
1226
1193
|
};
|
|
1227
1194
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1228
|
-
|
|
1229
|
-
pageElement,
|
|
1230
|
-
heightBuilder,
|
|
1231
|
-
objectResizable,
|
|
1195
|
+
...options.leaveTracking,
|
|
1232
1196
|
schema: tpaas_schemas_1.LeaveLockedAudioPage.object.objectType,
|
|
1233
1197
|
trackMethod: leaveLockedAudioPageCallback,
|
|
1234
1198
|
});
|
|
@@ -1247,18 +1211,14 @@ class Tracker {
|
|
|
1247
1211
|
const event = (0, tpaas_event_builder_1.buildViewLockedVideoPageEvent)(input, dependencies);
|
|
1248
1212
|
const result = this.sendTpaasEvent(event);
|
|
1249
1213
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1250
|
-
const
|
|
1251
|
-
|
|
1252
|
-
this.trackLeaveLockedVideoPage({
|
|
1214
|
+
const leaveLockedVideoPageCallback = async (leave) => {
|
|
1215
|
+
await this.trackLeaveLockedVideoPage({
|
|
1253
1216
|
leave,
|
|
1254
1217
|
...input,
|
|
1255
1218
|
});
|
|
1256
1219
|
};
|
|
1257
1220
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1258
|
-
|
|
1259
|
-
pageElement,
|
|
1260
|
-
heightBuilder,
|
|
1261
|
-
objectResizable,
|
|
1221
|
+
...options.leaveTracking,
|
|
1262
1222
|
schema: tpaas_schemas_1.LeaveLockedVideoPage.object.objectType,
|
|
1263
1223
|
trackMethod: leaveLockedVideoPageCallback,
|
|
1264
1224
|
});
|
|
@@ -1314,10 +1274,10 @@ class Tracker {
|
|
|
1314
1274
|
const event = (0, tpaas_event_builder_1.buildViewVideoPageEvent)(input, dependencies);
|
|
1315
1275
|
const result = this.sendTpaasEvent(event);
|
|
1316
1276
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1317
|
-
const {
|
|
1318
|
-
const leaveVideoCallback = (leave) => {
|
|
1277
|
+
const { leaveStoriesBuilder, ...restLeaveTrackingOptions } = options.leaveTracking;
|
|
1278
|
+
const leaveVideoCallback = async (leave) => {
|
|
1319
1279
|
const leaveStoriesInput = leaveStoriesBuilder?.();
|
|
1320
|
-
this.trackLeaveVideoPage({
|
|
1280
|
+
await this.trackLeaveVideoPage({
|
|
1321
1281
|
leave,
|
|
1322
1282
|
leaveStories: leaveStoriesInput && {
|
|
1323
1283
|
...leaveStoriesInput,
|
|
@@ -1328,10 +1288,7 @@ class Tracker {
|
|
|
1328
1288
|
});
|
|
1329
1289
|
};
|
|
1330
1290
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1331
|
-
|
|
1332
|
-
pageElement,
|
|
1333
|
-
heightBuilder,
|
|
1334
|
-
objectResizable,
|
|
1291
|
+
...restLeaveTrackingOptions,
|
|
1335
1292
|
schema: tpaas_schemas_1.LeaveVideoPage.object.objectType,
|
|
1336
1293
|
trackMethod: leaveVideoCallback,
|
|
1337
1294
|
});
|
|
@@ -1350,18 +1307,16 @@ class Tracker {
|
|
|
1350
1307
|
const event = (0, tpaas_event_builder_1.buildViewWeatherEvent)(input, dependencies);
|
|
1351
1308
|
const result = this.sendTpaasEvent(event);
|
|
1352
1309
|
if ((0, leaveTrackingTpaas_1.shouldEnableLeaveTracking)(options.leaveTracking)) {
|
|
1353
|
-
const
|
|
1354
|
-
|
|
1355
|
-
|
|
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({
|
|
1356
1314
|
leave,
|
|
1357
|
-
...
|
|
1315
|
+
...rest,
|
|
1358
1316
|
});
|
|
1359
1317
|
};
|
|
1360
1318
|
(0, leaveTrackingTpaas_1.addTpaasLeaveTracking)({
|
|
1361
|
-
|
|
1362
|
-
pageElement,
|
|
1363
|
-
heightBuilder,
|
|
1364
|
-
objectResizable,
|
|
1319
|
+
...options.leaveTracking,
|
|
1365
1320
|
schema: tpaas_schemas_1.LeaveWeather.object.objectType,
|
|
1366
1321
|
trackMethod: leaveWeatherCallback,
|
|
1367
1322
|
});
|
|
@@ -2200,8 +2155,8 @@ class Tracker {
|
|
|
2200
2155
|
* with the added guarantee that a second Leave event will not be triggered if one already has been sent.
|
|
2201
2156
|
* @category TPaaS Leave Tracking
|
|
2202
2157
|
*/
|
|
2203
|
-
trackTpaasActiveLeave() {
|
|
2204
|
-
(0, leaveTrackingTpaas_1.trackTpaasActiveLeave)();
|
|
2158
|
+
async trackTpaasActiveLeave() {
|
|
2159
|
+
await (0, leaveTrackingTpaas_1.trackTpaasActiveLeave)();
|
|
2205
2160
|
}
|
|
2206
2161
|
/**
|
|
2207
2162
|
* Check if leave tracking is enabled (if an event will be sent when the user leaves the page)
|
|
@@ -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;
|
|
@@ -56,19 +56,42 @@ let updateViewedContentListeners = [];
|
|
|
56
56
|
let activityListeners = [];
|
|
57
57
|
let resizeObserver = null;
|
|
58
58
|
let throttledUpdateFn = (0, pulse_utils_1.throttle)(() => undefined, 0);
|
|
59
|
-
let
|
|
60
|
-
let
|
|
59
|
+
let durationStartTime = 0;
|
|
60
|
+
let activityStartTime = 0;
|
|
61
61
|
let currentLeaveEvent = (0, constants_1.DEFAULT_PAGE_LEAVE_EVENT)();
|
|
62
62
|
let additionalHeightBuilder;
|
|
63
|
+
/**
|
|
64
|
+
* Resolves a DOM element from either a CSS selector string or an Element instance.
|
|
65
|
+
*/
|
|
66
|
+
function resolveDomElement(element) {
|
|
67
|
+
try {
|
|
68
|
+
return typeof element === 'string' ? document.querySelector(element) : element || null;
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
logger.error('Error while resolving DOM element', e);
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
63
75
|
/*
|
|
64
76
|
Add leave tracking
|
|
65
77
|
*/
|
|
66
78
|
function addTpaasLeaveTracking({ objectElement, pageElement, schema, objectResizable, heightBuilder, trackMethod, }) {
|
|
67
79
|
function _addLeaveTracking() {
|
|
80
|
+
const objectDomElement = resolveDomElement(objectElement);
|
|
81
|
+
if (objectDomElement == null) {
|
|
82
|
+
logger.error('Could not find object element for leave tracking');
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
let pageDomElement = resolveDomElement(pageElement);
|
|
86
|
+
if (pageDomElement == null) {
|
|
87
|
+
logger.warn('Could not find page element for leave tracking, defaulting to document.body');
|
|
88
|
+
pageDomElement = document.body;
|
|
89
|
+
}
|
|
68
90
|
additionalHeightBuilder = heightBuilder;
|
|
69
91
|
addTpaasLeaveListeners();
|
|
70
|
-
addUpdateEventListeners(
|
|
71
|
-
|
|
92
|
+
addUpdateEventListeners(objectDomElement, pageDomElement, objectResizable);
|
|
93
|
+
activityStartTime = resetTime();
|
|
94
|
+
durationStartTime = resetTime();
|
|
72
95
|
currentLeaveSchema = schema;
|
|
73
96
|
currentTrackMethod = trackMethod;
|
|
74
97
|
logger.debug('addLeaveTracking:after:state', currentLeaveEvent);
|
|
@@ -160,12 +183,8 @@ function removeUpdateEventListeners() {
|
|
|
160
183
|
*/
|
|
161
184
|
const resetEventDefaults = () => {
|
|
162
185
|
currentLeaveEvent = (0, constants_1.DEFAULT_PAGE_LEAVE_EVENT)();
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
};
|
|
166
|
-
const resetActivityDuration = () => {
|
|
167
|
-
clearInterval(activityDuration.interval);
|
|
168
|
-
return (0, constants_1.DEFAULT_ACTIVITY_DURATION)();
|
|
186
|
+
durationStartTime = resetTime();
|
|
187
|
+
activityStartTime = resetTime();
|
|
169
188
|
};
|
|
170
189
|
const resetTpaasViewedContent = () => {
|
|
171
190
|
currentLeaveEvent = (0, constants_1.DEFAULT_PAGE_LEAVE_EVENT)();
|
|
@@ -174,34 +193,41 @@ exports.resetTpaasViewedContent = resetTpaasViewedContent;
|
|
|
174
193
|
const resetTime = () => Date.now();
|
|
175
194
|
/*
|
|
176
195
|
Send a Leave event only if Page Leave tracking is active in the SDK
|
|
177
|
-
The event that is ultimately sent is
|
|
178
|
-
|
|
179
|
-
to the brand event. After the event has been sent, leave page tracking is removed
|
|
196
|
+
The event that is ultimately sent is the View event saved in the currentTrackMethod callback.
|
|
197
|
+
After the event has been sent, leave page tracking is removed
|
|
180
198
|
and must be explicitly re-added if needed.
|
|
181
199
|
*/
|
|
182
|
-
function trackTpaasActiveLeave() {
|
|
200
|
+
async function trackTpaasActiveLeave() {
|
|
183
201
|
if (leaveTpaasTrackingIsActive()) {
|
|
184
|
-
trackTpaasLeave();
|
|
202
|
+
await trackTpaasLeave();
|
|
185
203
|
}
|
|
186
204
|
}
|
|
187
205
|
/*
|
|
188
206
|
Send a Leave event regardless of whether Page Leave tracking is active in the SDK
|
|
189
|
-
The event that is ultimately sent is
|
|
190
|
-
|
|
191
|
-
to the brand event. After the event has been sent, leave page tracking is removed
|
|
207
|
+
The event that is ultimately sent is the View event saved in the currentTrackMethod callback.
|
|
208
|
+
After the event has been sent, leave page tracking is removed
|
|
192
209
|
and must be explicitly re-added if needed.
|
|
193
210
|
*/
|
|
194
|
-
function trackTpaasLeave() {
|
|
211
|
+
async function trackTpaasLeave() {
|
|
195
212
|
const leave = getTpaasLeaveObject();
|
|
196
|
-
currentTrackMethod
|
|
213
|
+
// Capture currentTrackMethod and remove tracking synchronously before awaiting.
|
|
214
|
+
// If removal happened after the await, a new trackView* call arriving during the async
|
|
215
|
+
// gap would see tracking still active with the same schema and silently discard its
|
|
216
|
+
// new callback (e.g. a fresh leaveAudioBuilder), causing the next leave event to
|
|
217
|
+
// never fire or to use the wrong builder.
|
|
218
|
+
const trackMethod = currentTrackMethod;
|
|
197
219
|
removeTpaasLeaveTracking();
|
|
220
|
+
await trackMethod(leave);
|
|
198
221
|
}
|
|
199
222
|
function getTpaasLeaveObject() {
|
|
200
223
|
const endTime = Date.now();
|
|
201
|
-
|
|
224
|
+
// TPaaS leave event requires duration/activity to be at least 1ms, otherwise the event is rejected
|
|
225
|
+
// also, in practice, it's almost impossible to have an activity or duration of 0ms
|
|
226
|
+
const durationMs = Math.max(endTime - durationStartTime, 1);
|
|
227
|
+
const activityDurationMs = Math.max(Math.min(endTime - activityStartTime, constants_1.ACTIVITY_DURATION_LIMIT_MS), 1);
|
|
202
228
|
const leave = {
|
|
203
|
-
durationMs
|
|
204
|
-
activityDurationMs
|
|
229
|
+
durationMs,
|
|
230
|
+
activityDurationMs,
|
|
205
231
|
...currentLeaveEvent,
|
|
206
232
|
};
|
|
207
233
|
logger.debug('trackTpaasLeave: event', leave);
|
|
@@ -276,18 +302,10 @@ exports.calculateScrollPosition = calculateScrollPosition;
|
|
|
276
302
|
'mousedown', 'mousemove', 'keydown', 'scroll' and/or 'touchstart' browser events.
|
|
277
303
|
*/
|
|
278
304
|
function addUpdateActivityDurationListeners() {
|
|
279
|
-
if
|
|
280
|
-
|
|
305
|
+
// if there are already listeners for activity, do not add more
|
|
306
|
+
if (activityListeners.length > 0) {
|
|
281
307
|
return;
|
|
282
308
|
}
|
|
283
|
-
const interval = 1000;
|
|
284
|
-
const activityTimeout = 30 * 1000;
|
|
285
|
-
activityDuration.interval = window.setInterval(() => {
|
|
286
|
-
activityDuration.timeSinceLastActivity += interval;
|
|
287
|
-
if (activityDuration.timeSinceLastActivity < activityTimeout) {
|
|
288
|
-
activityDuration.value += interval;
|
|
289
|
-
}
|
|
290
|
-
}, interval);
|
|
291
309
|
const activityEvents = [
|
|
292
310
|
types_1.BrowserEvents.SCROLL,
|
|
293
311
|
types_1.BrowserEvents.MOUSEDOWN,
|
|
@@ -296,15 +314,9 @@ function addUpdateActivityDurationListeners() {
|
|
|
296
314
|
types_1.BrowserEvents.TOUCHSTART,
|
|
297
315
|
];
|
|
298
316
|
activityListeners = addEventListeners(activityEvents, () => {
|
|
299
|
-
|
|
317
|
+
activityStartTime = resetTime();
|
|
300
318
|
}, { passive: true });
|
|
301
319
|
}
|
|
302
|
-
function resetLastActivity(activityDuration) {
|
|
303
|
-
return {
|
|
304
|
-
...activityDuration,
|
|
305
|
-
timeSinceLastActivity: 0,
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
320
|
/*
|
|
309
321
|
Add listeners to a set of browser events.
|
|
310
322
|
*/
|
|
@@ -39,6 +39,7 @@ exports.TPAAS_ALLOWED_METHODS = [
|
|
|
39
39
|
'trackLeaveLockedAudioPage',
|
|
40
40
|
'trackLeaveLockedVideoPage',
|
|
41
41
|
'trackLeavePage',
|
|
42
|
+
'trackLeaveSportsPage',
|
|
42
43
|
'trackLeaveVideoPage',
|
|
43
44
|
'trackLeaveWeather',
|
|
44
45
|
'trackViewArticle',
|
|
@@ -52,6 +53,7 @@ exports.TPAAS_ALLOWED_METHODS = [
|
|
|
52
53
|
'trackViewLockedAudioPage',
|
|
53
54
|
'trackViewLockedVideoPage',
|
|
54
55
|
'trackViewPage',
|
|
56
|
+
'trackViewSportsPage',
|
|
55
57
|
'trackViewTitle',
|
|
56
58
|
'trackViewVideoPage',
|
|
57
59
|
'trackViewWeather',
|
package/dist/cjs/version.js
CHANGED