@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/ejs/Tracker.js
CHANGED
|
@@ -428,7 +428,6 @@ export default class Tracker {
|
|
|
428
428
|
};
|
|
429
429
|
}
|
|
430
430
|
/**
|
|
431
|
-
*
|
|
432
431
|
* @private
|
|
433
432
|
* @category TPaaS Tracking
|
|
434
433
|
*/
|
|
@@ -748,14 +747,13 @@ export default class Tracker {
|
|
|
748
747
|
const event = buildViewHealthPageEvent(input, dependencies);
|
|
749
748
|
const result = this.sendTpaasEvent(event);
|
|
750
749
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
751
|
-
const
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
this.trackLeavePage({
|
|
750
|
+
const leavePageCallback = async (leave) => {
|
|
751
|
+
// HealthView Page is a bit special, in the sense that in doesn't have a dedicated Leave event.
|
|
752
|
+
// Instead, we need to reuse the generic Leave Page event, but adapt the input accordingly.
|
|
753
|
+
// This means omitting some fields from HealthView Page that are not part of Leave Page schema.
|
|
754
|
+
const { experiments, metrics, object, origin, ...restInput } = input;
|
|
755
|
+
const { category, custom, intent, name, tags, ...restObject } = input.object;
|
|
756
|
+
await this.trackLeavePage({
|
|
759
757
|
leave,
|
|
760
758
|
...restInput,
|
|
761
759
|
object: {
|
|
@@ -765,10 +763,7 @@ export default class Tracker {
|
|
|
765
763
|
});
|
|
766
764
|
};
|
|
767
765
|
addTpaasLeaveTracking({
|
|
768
|
-
|
|
769
|
-
pageElement,
|
|
770
|
-
objectResizable,
|
|
771
|
-
heightBuilder,
|
|
766
|
+
...options.leaveTracking,
|
|
772
767
|
schema: LeavePage.object.objectType,
|
|
773
768
|
trackMethod: leavePageCallback,
|
|
774
769
|
});
|
|
@@ -792,18 +787,15 @@ export default class Tracker {
|
|
|
792
787
|
const event = buildViewPageEvent(input, dependencies);
|
|
793
788
|
const result = this.sendTpaasEvent(event);
|
|
794
789
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
795
|
-
const
|
|
796
|
-
|
|
797
|
-
this.trackLeavePage({
|
|
790
|
+
const leavePageCallback = async (leave) => {
|
|
791
|
+
const { metrics, ...rest } = input; // metrics are not part of LeavePage schema, so we need to omit them
|
|
792
|
+
await this.trackLeavePage({
|
|
798
793
|
leave,
|
|
799
|
-
...
|
|
794
|
+
...rest,
|
|
800
795
|
});
|
|
801
796
|
};
|
|
802
797
|
addTpaasLeaveTracking({
|
|
803
|
-
|
|
804
|
-
pageElement,
|
|
805
|
-
objectResizable,
|
|
806
|
-
heightBuilder,
|
|
798
|
+
...options.leaveTracking,
|
|
807
799
|
schema: LeavePage.object.objectType,
|
|
808
800
|
trackMethod: leavePageCallback,
|
|
809
801
|
});
|
|
@@ -822,18 +814,14 @@ export default class Tracker {
|
|
|
822
814
|
const event = buildViewSportsPageEvent(input, dependencies);
|
|
823
815
|
const result = this.sendTpaasEvent(event);
|
|
824
816
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
825
|
-
const
|
|
826
|
-
|
|
827
|
-
this.trackLeaveSportsPage({
|
|
817
|
+
const leaveSportsPageCallback = async (leave) => {
|
|
818
|
+
await this.trackLeaveSportsPage({
|
|
828
819
|
leave,
|
|
829
820
|
...input,
|
|
830
821
|
});
|
|
831
822
|
};
|
|
832
823
|
addTpaasLeaveTracking({
|
|
833
|
-
|
|
834
|
-
pageElement,
|
|
835
|
-
objectResizable,
|
|
836
|
-
heightBuilder,
|
|
824
|
+
...options.leaveTracking,
|
|
837
825
|
schema: LeaveSportsPage.object.objectType,
|
|
838
826
|
trackMethod: leaveSportsPageCallback,
|
|
839
827
|
});
|
|
@@ -873,18 +861,17 @@ export default class Tracker {
|
|
|
873
861
|
const event = buildViewArticleEvent(input, dependencies);
|
|
874
862
|
const result = this.sendTpaasEvent(event);
|
|
875
863
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
876
|
-
const
|
|
877
|
-
|
|
878
|
-
|
|
864
|
+
const leaveArticleCallback = async (leave) => {
|
|
865
|
+
// omit these properties from LeaveArticle because they're not part of the LeaveArticle schema
|
|
866
|
+
const { authors, hotness, lifetime, sponsor, wordCount, ...rest } = input.object;
|
|
867
|
+
await this.trackLeaveArticle({
|
|
879
868
|
leave,
|
|
880
869
|
...input,
|
|
870
|
+
object: rest,
|
|
881
871
|
});
|
|
882
872
|
};
|
|
883
873
|
addTpaasLeaveTracking({
|
|
884
|
-
|
|
885
|
-
pageElement,
|
|
886
|
-
heightBuilder,
|
|
887
|
-
objectResizable,
|
|
874
|
+
...options.leaveTracking,
|
|
888
875
|
schema: LeaveArticle.object.objectType,
|
|
889
876
|
trackMethod: leaveArticleCallback,
|
|
890
877
|
});
|
|
@@ -938,15 +925,15 @@ export default class Tracker {
|
|
|
938
925
|
const event = buildViewAudioPageEvent(input, dependencies);
|
|
939
926
|
const result = this.sendTpaasEvent(event);
|
|
940
927
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
941
|
-
const {
|
|
942
|
-
const leaveAudioPageCallback = (leave) => {
|
|
928
|
+
const { leaveAudioBuilder, ...restLeaveTrackingOptions } = options.leaveTracking;
|
|
929
|
+
const leaveAudioPageCallback = async (leave) => {
|
|
943
930
|
const leaveAudioInput = leaveAudioBuilder?.() ?? {
|
|
944
931
|
audioCompleted: 0,
|
|
945
932
|
audioStarted: 0,
|
|
946
933
|
maxPlaylistPosition: 0,
|
|
947
934
|
playlistPositionPercentage: 0,
|
|
948
935
|
};
|
|
949
|
-
this.trackLeaveAudioPage({
|
|
936
|
+
await this.trackLeaveAudioPage({
|
|
950
937
|
leave,
|
|
951
938
|
leaveAudio: {
|
|
952
939
|
...leaveAudioInput,
|
|
@@ -957,10 +944,7 @@ export default class Tracker {
|
|
|
957
944
|
});
|
|
958
945
|
};
|
|
959
946
|
addTpaasLeaveTracking({
|
|
960
|
-
|
|
961
|
-
pageElement,
|
|
962
|
-
heightBuilder,
|
|
963
|
-
objectResizable,
|
|
947
|
+
...restLeaveTrackingOptions,
|
|
964
948
|
schema: LeaveAudioPage.object.objectType,
|
|
965
949
|
trackMethod: leaveAudioPageCallback,
|
|
966
950
|
});
|
|
@@ -979,18 +963,14 @@ export default class Tracker {
|
|
|
979
963
|
const event = buildViewErrorEvent(input, dependencies);
|
|
980
964
|
const result = this.sendTpaasEvent(event);
|
|
981
965
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
982
|
-
const
|
|
983
|
-
|
|
984
|
-
this.trackLeaveError({
|
|
966
|
+
const leaveErrorCallback = async (leave) => {
|
|
967
|
+
await this.trackLeaveError({
|
|
985
968
|
leave,
|
|
986
969
|
...input,
|
|
987
970
|
});
|
|
988
971
|
};
|
|
989
972
|
addTpaasLeaveTracking({
|
|
990
|
-
|
|
991
|
-
pageElement,
|
|
992
|
-
heightBuilder,
|
|
993
|
-
objectResizable,
|
|
973
|
+
...options.leaveTracking,
|
|
994
974
|
schema: LeaveError.object.objectType,
|
|
995
975
|
trackMethod: leaveErrorCallback,
|
|
996
976
|
});
|
|
@@ -1054,18 +1034,15 @@ export default class Tracker {
|
|
|
1054
1034
|
const event = buildViewFrontpageEvent(input, dependencies);
|
|
1055
1035
|
const result = this.sendTpaasEvent(event);
|
|
1056
1036
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
1057
|
-
const
|
|
1058
|
-
|
|
1059
|
-
this.trackLeaveFrontpage({
|
|
1037
|
+
const leaveFrontpageCallback = async (leave) => {
|
|
1038
|
+
const { metrics, ...rest } = input; // metrics are not part of LeaveFrontpage schema, so we need to omit them
|
|
1039
|
+
await this.trackLeaveFrontpage({
|
|
1060
1040
|
leave,
|
|
1061
|
-
...
|
|
1041
|
+
...rest,
|
|
1062
1042
|
});
|
|
1063
1043
|
};
|
|
1064
1044
|
addTpaasLeaveTracking({
|
|
1065
|
-
|
|
1066
|
-
pageElement,
|
|
1067
|
-
objectResizable,
|
|
1068
|
-
heightBuilder,
|
|
1045
|
+
...options.leaveTracking,
|
|
1069
1046
|
schema: LeaveFrontpage.object.objectType,
|
|
1070
1047
|
trackMethod: leaveFrontpageCallback,
|
|
1071
1048
|
});
|
|
@@ -1084,18 +1061,14 @@ export default class Tracker {
|
|
|
1084
1061
|
const event = buildViewLandingpageEvent(input, dependencies);
|
|
1085
1062
|
const result = this.sendTpaasEvent(event);
|
|
1086
1063
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
1087
|
-
const
|
|
1088
|
-
|
|
1089
|
-
this.trackLeaveLandingpage({
|
|
1064
|
+
const leaveLandingpageCallback = async (leave) => {
|
|
1065
|
+
await this.trackLeaveLandingpage({
|
|
1090
1066
|
leave,
|
|
1091
1067
|
...input,
|
|
1092
1068
|
});
|
|
1093
1069
|
};
|
|
1094
1070
|
addTpaasLeaveTracking({
|
|
1095
|
-
|
|
1096
|
-
pageElement,
|
|
1097
|
-
heightBuilder,
|
|
1098
|
-
objectResizable,
|
|
1071
|
+
...options.leaveTracking,
|
|
1099
1072
|
schema: LeaveLandingpage.object.objectType,
|
|
1100
1073
|
trackMethod: leaveLandingpageCallback,
|
|
1101
1074
|
});
|
|
@@ -1114,18 +1087,14 @@ export default class Tracker {
|
|
|
1114
1087
|
const event = buildViewListingEvent(input, dependencies);
|
|
1115
1088
|
const result = this.sendTpaasEvent(event);
|
|
1116
1089
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
1117
|
-
const
|
|
1118
|
-
|
|
1119
|
-
this.trackLeaveListing({
|
|
1090
|
+
const leaveListingCallback = async (leave) => {
|
|
1091
|
+
await this.trackLeaveListing({
|
|
1120
1092
|
leave,
|
|
1121
1093
|
...input,
|
|
1122
1094
|
});
|
|
1123
1095
|
};
|
|
1124
1096
|
addTpaasLeaveTracking({
|
|
1125
|
-
|
|
1126
|
-
pageElement,
|
|
1127
|
-
heightBuilder,
|
|
1128
|
-
objectResizable,
|
|
1097
|
+
...options.leaveTracking,
|
|
1129
1098
|
schema: LeaveListing.object.objectType,
|
|
1130
1099
|
trackMethod: leaveListingCallback,
|
|
1131
1100
|
});
|
|
@@ -1144,18 +1113,17 @@ export default class Tracker {
|
|
|
1144
1113
|
const event = buildViewLockedArticleEvent(input, dependencies);
|
|
1145
1114
|
const result = this.sendTpaasEvent(event);
|
|
1146
1115
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
1147
|
-
const
|
|
1148
|
-
|
|
1149
|
-
|
|
1116
|
+
const leaveLockedArticleCallback = async (leave) => {
|
|
1117
|
+
// omit these properties because they're not part of the LeaveLockedArticle schema
|
|
1118
|
+
const { authors, hotness, lifetime, sponsor, wordCount, ...rest } = input.object;
|
|
1119
|
+
await this.trackLeaveLockedArticle({
|
|
1150
1120
|
leave,
|
|
1151
1121
|
...input,
|
|
1122
|
+
object: rest,
|
|
1152
1123
|
});
|
|
1153
1124
|
};
|
|
1154
1125
|
addTpaasLeaveTracking({
|
|
1155
|
-
|
|
1156
|
-
pageElement,
|
|
1157
|
-
objectResizable,
|
|
1158
|
-
heightBuilder,
|
|
1126
|
+
...options.leaveTracking,
|
|
1159
1127
|
schema: LeaveLockedArticle.object.objectType,
|
|
1160
1128
|
trackMethod: leaveLockedArticleCallback,
|
|
1161
1129
|
});
|
|
@@ -1174,18 +1142,14 @@ export default class Tracker {
|
|
|
1174
1142
|
const event = buildViewLockedAudioPageEvent(input, dependencies);
|
|
1175
1143
|
const result = this.sendTpaasEvent(event);
|
|
1176
1144
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
1177
|
-
const
|
|
1178
|
-
|
|
1179
|
-
this.trackLeaveLockedAudioPage({
|
|
1145
|
+
const leaveLockedAudioPageCallback = async (leave) => {
|
|
1146
|
+
await this.trackLeaveLockedAudioPage({
|
|
1180
1147
|
leave,
|
|
1181
1148
|
...input,
|
|
1182
1149
|
});
|
|
1183
1150
|
};
|
|
1184
1151
|
addTpaasLeaveTracking({
|
|
1185
|
-
|
|
1186
|
-
pageElement,
|
|
1187
|
-
heightBuilder,
|
|
1188
|
-
objectResizable,
|
|
1152
|
+
...options.leaveTracking,
|
|
1189
1153
|
schema: LeaveLockedAudioPage.object.objectType,
|
|
1190
1154
|
trackMethod: leaveLockedAudioPageCallback,
|
|
1191
1155
|
});
|
|
@@ -1204,18 +1168,14 @@ export default class Tracker {
|
|
|
1204
1168
|
const event = buildViewLockedVideoPageEvent(input, dependencies);
|
|
1205
1169
|
const result = this.sendTpaasEvent(event);
|
|
1206
1170
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
1207
|
-
const
|
|
1208
|
-
|
|
1209
|
-
this.trackLeaveLockedVideoPage({
|
|
1171
|
+
const leaveLockedVideoPageCallback = async (leave) => {
|
|
1172
|
+
await this.trackLeaveLockedVideoPage({
|
|
1210
1173
|
leave,
|
|
1211
1174
|
...input,
|
|
1212
1175
|
});
|
|
1213
1176
|
};
|
|
1214
1177
|
addTpaasLeaveTracking({
|
|
1215
|
-
|
|
1216
|
-
pageElement,
|
|
1217
|
-
heightBuilder,
|
|
1218
|
-
objectResizable,
|
|
1178
|
+
...options.leaveTracking,
|
|
1219
1179
|
schema: LeaveLockedVideoPage.object.objectType,
|
|
1220
1180
|
trackMethod: leaveLockedVideoPageCallback,
|
|
1221
1181
|
});
|
|
@@ -1271,10 +1231,10 @@ export default class Tracker {
|
|
|
1271
1231
|
const event = buildViewVideoPageEvent(input, dependencies);
|
|
1272
1232
|
const result = this.sendTpaasEvent(event);
|
|
1273
1233
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
1274
|
-
const {
|
|
1275
|
-
const leaveVideoCallback = (leave) => {
|
|
1234
|
+
const { leaveStoriesBuilder, ...restLeaveTrackingOptions } = options.leaveTracking;
|
|
1235
|
+
const leaveVideoCallback = async (leave) => {
|
|
1276
1236
|
const leaveStoriesInput = leaveStoriesBuilder?.();
|
|
1277
|
-
this.trackLeaveVideoPage({
|
|
1237
|
+
await this.trackLeaveVideoPage({
|
|
1278
1238
|
leave,
|
|
1279
1239
|
leaveStories: leaveStoriesInput && {
|
|
1280
1240
|
...leaveStoriesInput,
|
|
@@ -1285,10 +1245,7 @@ export default class Tracker {
|
|
|
1285
1245
|
});
|
|
1286
1246
|
};
|
|
1287
1247
|
addTpaasLeaveTracking({
|
|
1288
|
-
|
|
1289
|
-
pageElement,
|
|
1290
|
-
heightBuilder,
|
|
1291
|
-
objectResizable,
|
|
1248
|
+
...restLeaveTrackingOptions,
|
|
1292
1249
|
schema: LeaveVideoPage.object.objectType,
|
|
1293
1250
|
trackMethod: leaveVideoCallback,
|
|
1294
1251
|
});
|
|
@@ -1307,18 +1264,16 @@ export default class Tracker {
|
|
|
1307
1264
|
const event = buildViewWeatherEvent(input, dependencies);
|
|
1308
1265
|
const result = this.sendTpaasEvent(event);
|
|
1309
1266
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
1310
|
-
const
|
|
1311
|
-
|
|
1312
|
-
|
|
1267
|
+
const leaveWeatherCallback = async (leave) => {
|
|
1268
|
+
// omit object and page from input because they're not part of the LeaveWeather schema
|
|
1269
|
+
const { object, page, ...rest } = input;
|
|
1270
|
+
await this.trackLeaveWeather({
|
|
1313
1271
|
leave,
|
|
1314
|
-
...
|
|
1272
|
+
...rest,
|
|
1315
1273
|
});
|
|
1316
1274
|
};
|
|
1317
1275
|
addTpaasLeaveTracking({
|
|
1318
|
-
|
|
1319
|
-
pageElement,
|
|
1320
|
-
heightBuilder,
|
|
1321
|
-
objectResizable,
|
|
1276
|
+
...options.leaveTracking,
|
|
1322
1277
|
schema: LeaveWeather.object.objectType,
|
|
1323
1278
|
trackMethod: leaveWeatherCallback,
|
|
1324
1279
|
});
|
|
@@ -2157,8 +2112,8 @@ export default class Tracker {
|
|
|
2157
2112
|
* with the added guarantee that a second Leave event will not be triggered if one already has been sent.
|
|
2158
2113
|
* @category TPaaS Leave Tracking
|
|
2159
2114
|
*/
|
|
2160
|
-
trackTpaasActiveLeave() {
|
|
2161
|
-
trackTpaasActiveLeave();
|
|
2115
|
+
async trackTpaasActiveLeave() {
|
|
2116
|
+
await trackTpaasActiveLeave();
|
|
2162
2117
|
}
|
|
2163
2118
|
/**
|
|
2164
2119
|
* Check if leave tracking is enabled (if an event will be sent when the user leaves the page)
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
export const DEFAULT_ACTIVITY_DURATION = () => ({
|
|
2
|
-
value: 0,
|
|
3
|
-
interval: undefined,
|
|
4
|
-
timeSinceLastActivity: 0,
|
|
5
|
-
});
|
|
6
1
|
export const DEFAULT_PAGE_LEAVE_EVENT = () => ({
|
|
7
2
|
objectViewPercentage: 0,
|
|
8
3
|
maxObjectViewPercentage: 0,
|
|
@@ -11,3 +6,4 @@ export const DEFAULT_PAGE_LEAVE_EVENT = () => ({
|
|
|
11
6
|
pageScrollPosition: 0,
|
|
12
7
|
maxPageScrollPosition: 0,
|
|
13
8
|
});
|
|
9
|
+
export const ACTIVITY_DURATION_LIMIT_MS = 30000;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isBrowser, isFunction, throttle } from '@schibsted/pulse-utils';
|
|
2
2
|
import * as logger from 'loglevel';
|
|
3
|
-
import {
|
|
3
|
+
import { ACTIVITY_DURATION_LIMIT_MS, DEFAULT_PAGE_LEAVE_EVENT } from './constants';
|
|
4
4
|
import { BrowserEvents } from './types';
|
|
5
5
|
let currentLeaveSchema;
|
|
6
6
|
let currentTrackMethod;
|
|
@@ -9,19 +9,42 @@ let updateViewedContentListeners = [];
|
|
|
9
9
|
let activityListeners = [];
|
|
10
10
|
let resizeObserver = null;
|
|
11
11
|
let throttledUpdateFn = throttle(() => undefined, 0);
|
|
12
|
-
let
|
|
13
|
-
let
|
|
12
|
+
let durationStartTime = 0;
|
|
13
|
+
let activityStartTime = 0;
|
|
14
14
|
let currentLeaveEvent = DEFAULT_PAGE_LEAVE_EVENT();
|
|
15
15
|
let additionalHeightBuilder;
|
|
16
|
+
/**
|
|
17
|
+
* Resolves a DOM element from either a CSS selector string or an Element instance.
|
|
18
|
+
*/
|
|
19
|
+
function resolveDomElement(element) {
|
|
20
|
+
try {
|
|
21
|
+
return typeof element === 'string' ? document.querySelector(element) : element || null;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
logger.error('Error while resolving DOM element', e);
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
16
28
|
/*
|
|
17
29
|
Add leave tracking
|
|
18
30
|
*/
|
|
19
31
|
export function addTpaasLeaveTracking({ objectElement, pageElement, schema, objectResizable, heightBuilder, trackMethod, }) {
|
|
20
32
|
function _addLeaveTracking() {
|
|
33
|
+
const objectDomElement = resolveDomElement(objectElement);
|
|
34
|
+
if (objectDomElement == null) {
|
|
35
|
+
logger.error('Could not find object element for leave tracking');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
let pageDomElement = resolveDomElement(pageElement);
|
|
39
|
+
if (pageDomElement == null) {
|
|
40
|
+
logger.warn('Could not find page element for leave tracking, defaulting to document.body');
|
|
41
|
+
pageDomElement = document.body;
|
|
42
|
+
}
|
|
21
43
|
additionalHeightBuilder = heightBuilder;
|
|
22
44
|
addTpaasLeaveListeners();
|
|
23
|
-
addUpdateEventListeners(
|
|
24
|
-
|
|
45
|
+
addUpdateEventListeners(objectDomElement, pageDomElement, objectResizable);
|
|
46
|
+
activityStartTime = resetTime();
|
|
47
|
+
durationStartTime = resetTime();
|
|
25
48
|
currentLeaveSchema = schema;
|
|
26
49
|
currentTrackMethod = trackMethod;
|
|
27
50
|
logger.debug('addLeaveTracking:after:state', currentLeaveEvent);
|
|
@@ -113,12 +136,8 @@ function removeUpdateEventListeners() {
|
|
|
113
136
|
*/
|
|
114
137
|
const resetEventDefaults = () => {
|
|
115
138
|
currentLeaveEvent = DEFAULT_PAGE_LEAVE_EVENT();
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
};
|
|
119
|
-
const resetActivityDuration = () => {
|
|
120
|
-
clearInterval(activityDuration.interval);
|
|
121
|
-
return DEFAULT_ACTIVITY_DURATION();
|
|
139
|
+
durationStartTime = resetTime();
|
|
140
|
+
activityStartTime = resetTime();
|
|
122
141
|
};
|
|
123
142
|
export const resetTpaasViewedContent = () => {
|
|
124
143
|
currentLeaveEvent = DEFAULT_PAGE_LEAVE_EVENT();
|
|
@@ -126,34 +145,41 @@ export const resetTpaasViewedContent = () => {
|
|
|
126
145
|
const resetTime = () => Date.now();
|
|
127
146
|
/*
|
|
128
147
|
Send a Leave event only if Page Leave tracking is active in the SDK
|
|
129
|
-
The event that is ultimately sent is
|
|
130
|
-
|
|
131
|
-
to the brand event. After the event has been sent, leave page tracking is removed
|
|
148
|
+
The event that is ultimately sent is the View event saved in the currentTrackMethod callback.
|
|
149
|
+
After the event has been sent, leave page tracking is removed
|
|
132
150
|
and must be explicitly re-added if needed.
|
|
133
151
|
*/
|
|
134
|
-
export function trackTpaasActiveLeave() {
|
|
152
|
+
export async function trackTpaasActiveLeave() {
|
|
135
153
|
if (leaveTpaasTrackingIsActive()) {
|
|
136
|
-
trackTpaasLeave();
|
|
154
|
+
await trackTpaasLeave();
|
|
137
155
|
}
|
|
138
156
|
}
|
|
139
157
|
/*
|
|
140
158
|
Send a Leave event regardless of whether Page Leave tracking is active in the SDK
|
|
141
|
-
The event that is ultimately sent is
|
|
142
|
-
|
|
143
|
-
to the brand event. After the event has been sent, leave page tracking is removed
|
|
159
|
+
The event that is ultimately sent is the View event saved in the currentTrackMethod callback.
|
|
160
|
+
After the event has been sent, leave page tracking is removed
|
|
144
161
|
and must be explicitly re-added if needed.
|
|
145
162
|
*/
|
|
146
|
-
export function trackTpaasLeave() {
|
|
163
|
+
export async function trackTpaasLeave() {
|
|
147
164
|
const leave = getTpaasLeaveObject();
|
|
148
|
-
currentTrackMethod
|
|
165
|
+
// Capture currentTrackMethod and remove tracking synchronously before awaiting.
|
|
166
|
+
// If removal happened after the await, a new trackView* call arriving during the async
|
|
167
|
+
// gap would see tracking still active with the same schema and silently discard its
|
|
168
|
+
// new callback (e.g. a fresh leaveAudioBuilder), causing the next leave event to
|
|
169
|
+
// never fire or to use the wrong builder.
|
|
170
|
+
const trackMethod = currentTrackMethod;
|
|
149
171
|
removeTpaasLeaveTracking();
|
|
172
|
+
await trackMethod(leave);
|
|
150
173
|
}
|
|
151
174
|
export function getTpaasLeaveObject() {
|
|
152
175
|
const endTime = Date.now();
|
|
153
|
-
|
|
176
|
+
// TPaaS leave event requires duration/activity to be at least 1ms, otherwise the event is rejected
|
|
177
|
+
// also, in practice, it's almost impossible to have an activity or duration of 0ms
|
|
178
|
+
const durationMs = Math.max(endTime - durationStartTime, 1);
|
|
179
|
+
const activityDurationMs = Math.max(Math.min(endTime - activityStartTime, ACTIVITY_DURATION_LIMIT_MS), 1);
|
|
154
180
|
const leave = {
|
|
155
|
-
durationMs
|
|
156
|
-
activityDurationMs
|
|
181
|
+
durationMs,
|
|
182
|
+
activityDurationMs,
|
|
157
183
|
...currentLeaveEvent,
|
|
158
184
|
};
|
|
159
185
|
logger.debug('trackTpaasLeave: event', leave);
|
|
@@ -226,18 +252,10 @@ export const calculateScrollPosition = (element) => Math.abs(Math.min(element.ge
|
|
|
226
252
|
'mousedown', 'mousemove', 'keydown', 'scroll' and/or 'touchstart' browser events.
|
|
227
253
|
*/
|
|
228
254
|
function addUpdateActivityDurationListeners() {
|
|
229
|
-
if
|
|
230
|
-
|
|
255
|
+
// if there are already listeners for activity, do not add more
|
|
256
|
+
if (activityListeners.length > 0) {
|
|
231
257
|
return;
|
|
232
258
|
}
|
|
233
|
-
const interval = 1000;
|
|
234
|
-
const activityTimeout = 30 * 1000;
|
|
235
|
-
activityDuration.interval = window.setInterval(() => {
|
|
236
|
-
activityDuration.timeSinceLastActivity += interval;
|
|
237
|
-
if (activityDuration.timeSinceLastActivity < activityTimeout) {
|
|
238
|
-
activityDuration.value += interval;
|
|
239
|
-
}
|
|
240
|
-
}, interval);
|
|
241
259
|
const activityEvents = [
|
|
242
260
|
BrowserEvents.SCROLL,
|
|
243
261
|
BrowserEvents.MOUSEDOWN,
|
|
@@ -246,15 +264,9 @@ function addUpdateActivityDurationListeners() {
|
|
|
246
264
|
BrowserEvents.TOUCHSTART,
|
|
247
265
|
];
|
|
248
266
|
activityListeners = addEventListeners(activityEvents, () => {
|
|
249
|
-
|
|
267
|
+
activityStartTime = resetTime();
|
|
250
268
|
}, { passive: true });
|
|
251
269
|
}
|
|
252
|
-
function resetLastActivity(activityDuration) {
|
|
253
|
-
return {
|
|
254
|
-
...activityDuration,
|
|
255
|
-
timeSinceLastActivity: 0,
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
270
|
/*
|
|
259
271
|
Add listeners to a set of browser events.
|
|
260
272
|
*/
|
|
@@ -35,6 +35,7 @@ export const TPAAS_ALLOWED_METHODS = [
|
|
|
35
35
|
'trackLeaveLockedAudioPage',
|
|
36
36
|
'trackLeaveLockedVideoPage',
|
|
37
37
|
'trackLeavePage',
|
|
38
|
+
'trackLeaveSportsPage',
|
|
38
39
|
'trackLeaveVideoPage',
|
|
39
40
|
'trackLeaveWeather',
|
|
40
41
|
'trackViewArticle',
|
|
@@ -48,6 +49,7 @@ export const TPAAS_ALLOWED_METHODS = [
|
|
|
48
49
|
'trackViewLockedAudioPage',
|
|
49
50
|
'trackViewLockedVideoPage',
|
|
50
51
|
'trackViewPage',
|
|
52
|
+
'trackViewSportsPage',
|
|
51
53
|
'trackViewTitle',
|
|
52
54
|
'trackViewVideoPage',
|
|
53
55
|
'trackViewWeather',
|
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.6';
|