@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/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
|
/**
|
|
@@ -423,7 +428,6 @@ export default class Tracker {
|
|
|
423
428
|
};
|
|
424
429
|
}
|
|
425
430
|
/**
|
|
426
|
-
*
|
|
427
431
|
* @private
|
|
428
432
|
* @category TPaaS Tracking
|
|
429
433
|
*/
|
|
@@ -738,19 +742,18 @@ export default class Tracker {
|
|
|
738
742
|
}
|
|
739
743
|
async trackViewHealthPage(input, options) {
|
|
740
744
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
741
|
-
this.setCurrentPage(input.object.objectId,
|
|
745
|
+
this.setCurrentPage(input.object.objectId, ViewHealthPage.object.objectType);
|
|
742
746
|
const dependencies = await this.prepareTpaasEvent();
|
|
743
747
|
const event = buildViewHealthPageEvent(input, dependencies);
|
|
744
748
|
const result = this.sendTpaasEvent(event);
|
|
745
749
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
746
|
-
const
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
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({
|
|
754
757
|
leave,
|
|
755
758
|
...restInput,
|
|
756
759
|
object: {
|
|
@@ -760,10 +763,7 @@ export default class Tracker {
|
|
|
760
763
|
});
|
|
761
764
|
};
|
|
762
765
|
addTpaasLeaveTracking({
|
|
763
|
-
|
|
764
|
-
pageElement,
|
|
765
|
-
objectResizable,
|
|
766
|
-
heightBuilder,
|
|
766
|
+
...options.leaveTracking,
|
|
767
767
|
schema: LeavePage.object.objectType,
|
|
768
768
|
trackMethod: leavePageCallback,
|
|
769
769
|
});
|
|
@@ -787,18 +787,15 @@ export default class Tracker {
|
|
|
787
787
|
const event = buildViewPageEvent(input, dependencies);
|
|
788
788
|
const result = this.sendTpaasEvent(event);
|
|
789
789
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
790
|
-
const
|
|
791
|
-
|
|
792
|
-
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({
|
|
793
793
|
leave,
|
|
794
|
-
...
|
|
794
|
+
...rest,
|
|
795
795
|
});
|
|
796
796
|
};
|
|
797
797
|
addTpaasLeaveTracking({
|
|
798
|
-
|
|
799
|
-
pageElement,
|
|
800
|
-
objectResizable,
|
|
801
|
-
heightBuilder,
|
|
798
|
+
...options.leaveTracking,
|
|
802
799
|
schema: LeavePage.object.objectType,
|
|
803
800
|
trackMethod: leavePageCallback,
|
|
804
801
|
});
|
|
@@ -812,23 +809,19 @@ export default class Tracker {
|
|
|
812
809
|
*/
|
|
813
810
|
async trackViewSportsPage(input, options) {
|
|
814
811
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
815
|
-
this.setCurrentPage(input.object.objectId,
|
|
812
|
+
this.setCurrentPage(input.object.objectId, ViewSportsPage.object.objectType);
|
|
816
813
|
const dependencies = await this.prepareTpaasEvent();
|
|
817
814
|
const event = buildViewSportsPageEvent(input, dependencies);
|
|
818
815
|
const result = this.sendTpaasEvent(event);
|
|
819
816
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
820
|
-
const
|
|
821
|
-
|
|
822
|
-
this.trackLeaveSportsPage({
|
|
817
|
+
const leaveSportsPageCallback = async (leave) => {
|
|
818
|
+
await this.trackLeaveSportsPage({
|
|
823
819
|
leave,
|
|
824
820
|
...input,
|
|
825
821
|
});
|
|
826
822
|
};
|
|
827
823
|
addTpaasLeaveTracking({
|
|
828
|
-
|
|
829
|
-
pageElement,
|
|
830
|
-
objectResizable,
|
|
831
|
-
heightBuilder,
|
|
824
|
+
...options.leaveTracking,
|
|
832
825
|
schema: LeaveSportsPage.object.objectType,
|
|
833
826
|
trackMethod: leaveSportsPageCallback,
|
|
834
827
|
});
|
|
@@ -856,15 +849,6 @@ export default class Tracker {
|
|
|
856
849
|
const event = buildImpressionWidgetEvent(input, dependencies);
|
|
857
850
|
return this.sendTpaasEvent(event);
|
|
858
851
|
}
|
|
859
|
-
/**
|
|
860
|
-
* @param input
|
|
861
|
-
* @category TPaaS Tracking
|
|
862
|
-
*/
|
|
863
|
-
async trackImpressionAdSlot(input) {
|
|
864
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
865
|
-
const event = buildImpressionAdSlotEvent(input, dependencies);
|
|
866
|
-
return this.sendTpaasEvent(event);
|
|
867
|
-
}
|
|
868
852
|
/**
|
|
869
853
|
* @param input
|
|
870
854
|
* @param options
|
|
@@ -877,36 +861,23 @@ export default class Tracker {
|
|
|
877
861
|
const event = buildViewArticleEvent(input, dependencies);
|
|
878
862
|
const result = this.sendTpaasEvent(event);
|
|
879
863
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
880
|
-
const
|
|
881
|
-
|
|
882
|
-
|
|
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({
|
|
883
868
|
leave,
|
|
884
869
|
...input,
|
|
870
|
+
object: rest,
|
|
885
871
|
});
|
|
886
872
|
};
|
|
887
873
|
addTpaasLeaveTracking({
|
|
888
|
-
|
|
889
|
-
pageElement,
|
|
890
|
-
heightBuilder,
|
|
891
|
-
objectResizable,
|
|
874
|
+
...options.leaveTracking,
|
|
892
875
|
schema: LeaveArticle.object.objectType,
|
|
893
876
|
trackMethod: leaveArticleCallback,
|
|
894
877
|
});
|
|
895
878
|
}
|
|
896
879
|
return result;
|
|
897
880
|
}
|
|
898
|
-
/**
|
|
899
|
-
* @param input
|
|
900
|
-
* @param options
|
|
901
|
-
* @category TPaaS Tracking
|
|
902
|
-
*/
|
|
903
|
-
async trackViewAudio(input) {
|
|
904
|
-
// despite the View event type, this is not a page view event, but rather a media object view event
|
|
905
|
-
// so we shouldn't reset the page view ID here or enable leave tracking
|
|
906
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
907
|
-
const event = buildViewAudioEvent(input, dependencies);
|
|
908
|
-
return this.sendTpaasEvent(event);
|
|
909
|
-
}
|
|
910
881
|
/**
|
|
911
882
|
* Tracks a View AudioPage event and automatically fires a Leave AudioPage event when the user
|
|
912
883
|
* navigates away.
|
|
@@ -949,20 +920,20 @@ export default class Tracker {
|
|
|
949
920
|
*/
|
|
950
921
|
async trackViewAudioPage(input, options) {
|
|
951
922
|
this.newPageView();
|
|
952
|
-
this.setCurrentPage(input.object.objectId,
|
|
923
|
+
this.setCurrentPage(input.object.objectId, ViewAudioPage.object.objectType);
|
|
953
924
|
const dependencies = await this.prepareTpaasEvent();
|
|
954
925
|
const event = buildViewAudioPageEvent(input, dependencies);
|
|
955
926
|
const result = this.sendTpaasEvent(event);
|
|
956
927
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
957
|
-
const {
|
|
958
|
-
const leaveAudioPageCallback = (leave) => {
|
|
928
|
+
const { leaveAudioBuilder, ...restLeaveTrackingOptions } = options.leaveTracking;
|
|
929
|
+
const leaveAudioPageCallback = async (leave) => {
|
|
959
930
|
const leaveAudioInput = leaveAudioBuilder?.() ?? {
|
|
960
931
|
audioCompleted: 0,
|
|
961
932
|
audioStarted: 0,
|
|
962
933
|
maxPlaylistPosition: 0,
|
|
963
934
|
playlistPositionPercentage: 0,
|
|
964
935
|
};
|
|
965
|
-
this.trackLeaveAudioPage({
|
|
936
|
+
await this.trackLeaveAudioPage({
|
|
966
937
|
leave,
|
|
967
938
|
leaveAudio: {
|
|
968
939
|
...leaveAudioInput,
|
|
@@ -973,10 +944,7 @@ export default class Tracker {
|
|
|
973
944
|
});
|
|
974
945
|
};
|
|
975
946
|
addTpaasLeaveTracking({
|
|
976
|
-
|
|
977
|
-
pageElement,
|
|
978
|
-
heightBuilder,
|
|
979
|
-
objectResizable,
|
|
947
|
+
...restLeaveTrackingOptions,
|
|
980
948
|
schema: LeaveAudioPage.object.objectType,
|
|
981
949
|
trackMethod: leaveAudioPageCallback,
|
|
982
950
|
});
|
|
@@ -995,18 +963,14 @@ export default class Tracker {
|
|
|
995
963
|
const event = buildViewErrorEvent(input, dependencies);
|
|
996
964
|
const result = this.sendTpaasEvent(event);
|
|
997
965
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
998
|
-
const
|
|
999
|
-
|
|
1000
|
-
this.trackLeaveError({
|
|
966
|
+
const leaveErrorCallback = async (leave) => {
|
|
967
|
+
await this.trackLeaveError({
|
|
1001
968
|
leave,
|
|
1002
969
|
...input,
|
|
1003
970
|
});
|
|
1004
971
|
};
|
|
1005
972
|
addTpaasLeaveTracking({
|
|
1006
|
-
|
|
1007
|
-
pageElement,
|
|
1008
|
-
heightBuilder,
|
|
1009
|
-
objectResizable,
|
|
973
|
+
...options.leaveTracking,
|
|
1010
974
|
schema: LeaveError.object.objectType,
|
|
1011
975
|
trackMethod: leaveErrorCallback,
|
|
1012
976
|
});
|
|
@@ -1070,18 +1034,15 @@ export default class Tracker {
|
|
|
1070
1034
|
const event = buildViewFrontpageEvent(input, dependencies);
|
|
1071
1035
|
const result = this.sendTpaasEvent(event);
|
|
1072
1036
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
1073
|
-
const
|
|
1074
|
-
|
|
1075
|
-
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({
|
|
1076
1040
|
leave,
|
|
1077
|
-
...
|
|
1041
|
+
...rest,
|
|
1078
1042
|
});
|
|
1079
1043
|
};
|
|
1080
1044
|
addTpaasLeaveTracking({
|
|
1081
|
-
|
|
1082
|
-
pageElement,
|
|
1083
|
-
objectResizable,
|
|
1084
|
-
heightBuilder,
|
|
1045
|
+
...options.leaveTracking,
|
|
1085
1046
|
schema: LeaveFrontpage.object.objectType,
|
|
1086
1047
|
trackMethod: leaveFrontpageCallback,
|
|
1087
1048
|
});
|
|
@@ -1100,18 +1061,14 @@ export default class Tracker {
|
|
|
1100
1061
|
const event = buildViewLandingpageEvent(input, dependencies);
|
|
1101
1062
|
const result = this.sendTpaasEvent(event);
|
|
1102
1063
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
1103
|
-
const
|
|
1104
|
-
|
|
1105
|
-
this.trackLeaveLandingpage({
|
|
1064
|
+
const leaveLandingpageCallback = async (leave) => {
|
|
1065
|
+
await this.trackLeaveLandingpage({
|
|
1106
1066
|
leave,
|
|
1107
1067
|
...input,
|
|
1108
1068
|
});
|
|
1109
1069
|
};
|
|
1110
1070
|
addTpaasLeaveTracking({
|
|
1111
|
-
|
|
1112
|
-
pageElement,
|
|
1113
|
-
heightBuilder,
|
|
1114
|
-
objectResizable,
|
|
1071
|
+
...options.leaveTracking,
|
|
1115
1072
|
schema: LeaveLandingpage.object.objectType,
|
|
1116
1073
|
trackMethod: leaveLandingpageCallback,
|
|
1117
1074
|
});
|
|
@@ -1130,18 +1087,14 @@ export default class Tracker {
|
|
|
1130
1087
|
const event = buildViewListingEvent(input, dependencies);
|
|
1131
1088
|
const result = this.sendTpaasEvent(event);
|
|
1132
1089
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
1133
|
-
const
|
|
1134
|
-
|
|
1135
|
-
this.trackLeaveListing({
|
|
1090
|
+
const leaveListingCallback = async (leave) => {
|
|
1091
|
+
await this.trackLeaveListing({
|
|
1136
1092
|
leave,
|
|
1137
1093
|
...input,
|
|
1138
1094
|
});
|
|
1139
1095
|
};
|
|
1140
1096
|
addTpaasLeaveTracking({
|
|
1141
|
-
|
|
1142
|
-
pageElement,
|
|
1143
|
-
heightBuilder,
|
|
1144
|
-
objectResizable,
|
|
1097
|
+
...options.leaveTracking,
|
|
1145
1098
|
schema: LeaveListing.object.objectType,
|
|
1146
1099
|
trackMethod: leaveListingCallback,
|
|
1147
1100
|
});
|
|
@@ -1160,36 +1113,23 @@ export default class Tracker {
|
|
|
1160
1113
|
const event = buildViewLockedArticleEvent(input, dependencies);
|
|
1161
1114
|
const result = this.sendTpaasEvent(event);
|
|
1162
1115
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
1163
|
-
const
|
|
1164
|
-
|
|
1165
|
-
|
|
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({
|
|
1166
1120
|
leave,
|
|
1167
1121
|
...input,
|
|
1122
|
+
object: rest,
|
|
1168
1123
|
});
|
|
1169
1124
|
};
|
|
1170
1125
|
addTpaasLeaveTracking({
|
|
1171
|
-
|
|
1172
|
-
pageElement,
|
|
1173
|
-
objectResizable,
|
|
1174
|
-
heightBuilder,
|
|
1126
|
+
...options.leaveTracking,
|
|
1175
1127
|
schema: LeaveLockedArticle.object.objectType,
|
|
1176
1128
|
trackMethod: leaveLockedArticleCallback,
|
|
1177
1129
|
});
|
|
1178
1130
|
}
|
|
1179
1131
|
return result;
|
|
1180
1132
|
}
|
|
1181
|
-
/**
|
|
1182
|
-
* @param input
|
|
1183
|
-
* @param options
|
|
1184
|
-
* @category TPaaS Tracking
|
|
1185
|
-
*/
|
|
1186
|
-
async trackViewLockedAudio(input) {
|
|
1187
|
-
// despite the View event type, this is not a page view event, but rather a media object view event
|
|
1188
|
-
// so we shouldn't reset the page view ID here or enable leave tracking
|
|
1189
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1190
|
-
const event = buildViewLockedAudioEvent(input, dependencies);
|
|
1191
|
-
return this.sendTpaasEvent(event);
|
|
1192
|
-
}
|
|
1193
1133
|
/**
|
|
1194
1134
|
* @param input
|
|
1195
1135
|
* @param options
|
|
@@ -1197,40 +1137,25 @@ export default class Tracker {
|
|
|
1197
1137
|
*/
|
|
1198
1138
|
async trackViewLockedAudioPage(input, options) {
|
|
1199
1139
|
this.newPageView();
|
|
1200
|
-
this.setCurrentPage(input.object.objectId,
|
|
1140
|
+
this.setCurrentPage(input.object.objectId, ViewLockedAudioPage.object.objectType);
|
|
1201
1141
|
const dependencies = await this.prepareTpaasEvent();
|
|
1202
1142
|
const event = buildViewLockedAudioPageEvent(input, dependencies);
|
|
1203
1143
|
const result = this.sendTpaasEvent(event);
|
|
1204
1144
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
1205
|
-
const
|
|
1206
|
-
|
|
1207
|
-
this.trackLeaveLockedAudioPage({
|
|
1145
|
+
const leaveLockedAudioPageCallback = async (leave) => {
|
|
1146
|
+
await this.trackLeaveLockedAudioPage({
|
|
1208
1147
|
leave,
|
|
1209
1148
|
...input,
|
|
1210
1149
|
});
|
|
1211
1150
|
};
|
|
1212
1151
|
addTpaasLeaveTracking({
|
|
1213
|
-
|
|
1214
|
-
pageElement,
|
|
1215
|
-
heightBuilder,
|
|
1216
|
-
objectResizable,
|
|
1152
|
+
...options.leaveTracking,
|
|
1217
1153
|
schema: LeaveLockedAudioPage.object.objectType,
|
|
1218
1154
|
trackMethod: leaveLockedAudioPageCallback,
|
|
1219
1155
|
});
|
|
1220
1156
|
}
|
|
1221
1157
|
return result;
|
|
1222
1158
|
}
|
|
1223
|
-
/**
|
|
1224
|
-
* @param input
|
|
1225
|
-
* @category TPaaS Tracking
|
|
1226
|
-
*/
|
|
1227
|
-
async trackViewLockedVideo(input) {
|
|
1228
|
-
// despite the name, this is not a page-level event. trackViewLockedVideoPage is a page-level event
|
|
1229
|
-
// as such, we don't support (yet) automatic leave event enabling
|
|
1230
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1231
|
-
const event = buildViewLockedVideoEvent(input, dependencies);
|
|
1232
|
-
return this.sendTpaasEvent(event);
|
|
1233
|
-
}
|
|
1234
1159
|
/**
|
|
1235
1160
|
* @param input
|
|
1236
1161
|
* @param options
|
|
@@ -1238,40 +1163,25 @@ export default class Tracker {
|
|
|
1238
1163
|
*/
|
|
1239
1164
|
async trackViewLockedVideoPage(input, options) {
|
|
1240
1165
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
1241
|
-
this.setCurrentPage(input.object.objectId,
|
|
1166
|
+
this.setCurrentPage(input.object.objectId, ViewLockedVideoPage.object.objectType);
|
|
1242
1167
|
const dependencies = await this.prepareTpaasEvent();
|
|
1243
1168
|
const event = buildViewLockedVideoPageEvent(input, dependencies);
|
|
1244
1169
|
const result = this.sendTpaasEvent(event);
|
|
1245
1170
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
1246
|
-
const
|
|
1247
|
-
|
|
1248
|
-
this.trackLeaveLockedVideoPage({
|
|
1171
|
+
const leaveLockedVideoPageCallback = async (leave) => {
|
|
1172
|
+
await this.trackLeaveLockedVideoPage({
|
|
1249
1173
|
leave,
|
|
1250
1174
|
...input,
|
|
1251
1175
|
});
|
|
1252
1176
|
};
|
|
1253
1177
|
addTpaasLeaveTracking({
|
|
1254
|
-
|
|
1255
|
-
pageElement,
|
|
1256
|
-
heightBuilder,
|
|
1257
|
-
objectResizable,
|
|
1178
|
+
...options.leaveTracking,
|
|
1258
1179
|
schema: LeaveLockedVideoPage.object.objectType,
|
|
1259
1180
|
trackMethod: leaveLockedVideoPageCallback,
|
|
1260
1181
|
});
|
|
1261
1182
|
}
|
|
1262
1183
|
return result;
|
|
1263
1184
|
}
|
|
1264
|
-
/**
|
|
1265
|
-
* @param input
|
|
1266
|
-
* @category TPaaS Tracking
|
|
1267
|
-
*/
|
|
1268
|
-
async trackViewVideo(input) {
|
|
1269
|
-
// despite the View event type, this is not a page view event, but rather a media object view event
|
|
1270
|
-
// so we shouldn't reset the page view ID here or enable leave tracking
|
|
1271
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1272
|
-
const event = buildViewVideoEvent(input, dependencies);
|
|
1273
|
-
return this.sendTpaasEvent(event);
|
|
1274
|
-
}
|
|
1275
1185
|
/**
|
|
1276
1186
|
* Tracks a View VideoPage event and automatically fires a Leave VideoPage event when the user
|
|
1277
1187
|
* navigates away.
|
|
@@ -1316,15 +1226,15 @@ export default class Tracker {
|
|
|
1316
1226
|
*/
|
|
1317
1227
|
async trackViewVideoPage(input, options) {
|
|
1318
1228
|
this.newPageView(); // Reset the page view ID if it is not set, to ensure a new page view is tracked
|
|
1319
|
-
this.setCurrentPage(input.object.objectId,
|
|
1229
|
+
this.setCurrentPage(input.object.objectId, ViewVideoPage.object.objectType);
|
|
1320
1230
|
const dependencies = await this.prepareTpaasEvent();
|
|
1321
1231
|
const event = buildViewVideoPageEvent(input, dependencies);
|
|
1322
1232
|
const result = this.sendTpaasEvent(event);
|
|
1323
1233
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
1324
|
-
const {
|
|
1325
|
-
const leaveVideoCallback = (leave) => {
|
|
1234
|
+
const { leaveStoriesBuilder, ...restLeaveTrackingOptions } = options.leaveTracking;
|
|
1235
|
+
const leaveVideoCallback = async (leave) => {
|
|
1326
1236
|
const leaveStoriesInput = leaveStoriesBuilder?.();
|
|
1327
|
-
this.trackLeaveVideoPage({
|
|
1237
|
+
await this.trackLeaveVideoPage({
|
|
1328
1238
|
leave,
|
|
1329
1239
|
leaveStories: leaveStoriesInput && {
|
|
1330
1240
|
...leaveStoriesInput,
|
|
@@ -1335,10 +1245,7 @@ export default class Tracker {
|
|
|
1335
1245
|
});
|
|
1336
1246
|
};
|
|
1337
1247
|
addTpaasLeaveTracking({
|
|
1338
|
-
|
|
1339
|
-
pageElement,
|
|
1340
|
-
heightBuilder,
|
|
1341
|
-
objectResizable,
|
|
1248
|
+
...restLeaveTrackingOptions,
|
|
1342
1249
|
schema: LeaveVideoPage.object.objectType,
|
|
1343
1250
|
trackMethod: leaveVideoCallback,
|
|
1344
1251
|
});
|
|
@@ -1357,18 +1264,16 @@ export default class Tracker {
|
|
|
1357
1264
|
const event = buildViewWeatherEvent(input, dependencies);
|
|
1358
1265
|
const result = this.sendTpaasEvent(event);
|
|
1359
1266
|
if (shouldEnableLeaveTracking(options.leaveTracking)) {
|
|
1360
|
-
const
|
|
1361
|
-
|
|
1362
|
-
|
|
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({
|
|
1363
1271
|
leave,
|
|
1364
|
-
...
|
|
1272
|
+
...rest,
|
|
1365
1273
|
});
|
|
1366
1274
|
};
|
|
1367
1275
|
addTpaasLeaveTracking({
|
|
1368
|
-
|
|
1369
|
-
pageElement,
|
|
1370
|
-
heightBuilder,
|
|
1371
|
-
objectResizable,
|
|
1276
|
+
...options.leaveTracking,
|
|
1372
1277
|
schema: LeaveWeather.object.objectType,
|
|
1373
1278
|
trackMethod: leaveWeatherCallback,
|
|
1374
1279
|
});
|
|
@@ -1438,15 +1343,6 @@ export default class Tracker {
|
|
|
1438
1343
|
const event = buildLeaveLockedArticleEvent(input, dependencies);
|
|
1439
1344
|
return this.sendTpaasEvent(event);
|
|
1440
1345
|
}
|
|
1441
|
-
/**
|
|
1442
|
-
* @param input
|
|
1443
|
-
* @category TPaaS Tracking
|
|
1444
|
-
*/
|
|
1445
|
-
async trackLeaveLockedAudio(input) {
|
|
1446
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1447
|
-
const event = buildLeaveLockedAudioEvent(input, dependencies);
|
|
1448
|
-
return this.sendTpaasEvent(event);
|
|
1449
|
-
}
|
|
1450
1346
|
/**
|
|
1451
1347
|
* @param input
|
|
1452
1348
|
* @category TPaaS Tracking
|
|
@@ -1456,15 +1352,6 @@ export default class Tracker {
|
|
|
1456
1352
|
const event = buildLeaveLockedAudioPageEvent(input, dependencies);
|
|
1457
1353
|
return this.sendTpaasEvent(event);
|
|
1458
1354
|
}
|
|
1459
|
-
/**
|
|
1460
|
-
* @param input
|
|
1461
|
-
* @category TPaaS Tracking
|
|
1462
|
-
*/
|
|
1463
|
-
async trackLeaveLockedVideo(input) {
|
|
1464
|
-
const dependencies = await this.prepareTpaasEvent();
|
|
1465
|
-
const event = buildLeaveLockedVideoEvent(input, dependencies);
|
|
1466
|
-
return this.sendTpaasEvent(event);
|
|
1467
|
-
}
|
|
1468
1355
|
/**
|
|
1469
1356
|
* @param input
|
|
1470
1357
|
* @category TPaaS Tracking
|
|
@@ -2225,8 +2112,8 @@ export default class Tracker {
|
|
|
2225
2112
|
* with the added guarantee that a second Leave event will not be triggered if one already has been sent.
|
|
2226
2113
|
* @category TPaaS Leave Tracking
|
|
2227
2114
|
*/
|
|
2228
|
-
trackTpaasActiveLeave() {
|
|
2229
|
-
trackTpaasActiveLeave();
|
|
2115
|
+
async trackTpaasActiveLeave() {
|
|
2116
|
+
await trackTpaasActiveLeave();
|
|
2230
2117
|
}
|
|
2231
2118
|
/**
|
|
2232
2119
|
* Check if leave tracking is enabled (if an event will be sent when the user leaves the page)
|
|
@@ -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 };
|
|
@@ -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;
|