@amplifyup/sdk 0.1.25 → 0.1.26
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/AmplifyRenderer.js +23 -35
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +23 -35
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +8 -12
- package/dist/index.d.ts +8 -12
- package/dist/index.js +23 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -36
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +23 -35
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +23 -35
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.js
CHANGED
|
@@ -60,7 +60,10 @@ var AWSAdapter = class {
|
|
|
60
60
|
headers: {
|
|
61
61
|
"Content-Type": "application/json"
|
|
62
62
|
},
|
|
63
|
-
body: JSON.stringify(eventData)
|
|
63
|
+
body: JSON.stringify(eventData),
|
|
64
|
+
// Keep the request alive through tab close so the single Time on Page
|
|
65
|
+
// flush on pagehide is not cancelled with the document.
|
|
66
|
+
keepalive: true
|
|
64
67
|
});
|
|
65
68
|
if (!response.ok) {
|
|
66
69
|
if (this.config.debug) {
|
|
@@ -519,8 +522,6 @@ async function fetchContent(options) {
|
|
|
519
522
|
|
|
520
523
|
// src/index.ts
|
|
521
524
|
var SESSION_IDLE_GAP_MS = 30 * 60 * 1e3;
|
|
522
|
-
var DWELL_MILESTONES_SEC = [15, 30, 60, 120, 300];
|
|
523
|
-
var DWELL_CHECKPOINT_SEC = 15 * 60;
|
|
524
525
|
var DWELL_ACTIVITY_IDLE_MS = 2 * 60 * 1e3;
|
|
525
526
|
var DWELL_POLL_MS = 5e3;
|
|
526
527
|
function readPreviewQueryOverrides() {
|
|
@@ -591,7 +592,8 @@ var AmplifyUpSDK = class {
|
|
|
591
592
|
reached: /* @__PURE__ */ new Set(),
|
|
592
593
|
visibleMs: 0,
|
|
593
594
|
visibleSince: null,
|
|
594
|
-
|
|
595
|
+
/** True after Time on Page has been sent for the current visit. */
|
|
596
|
+
dwellEmitted: false,
|
|
595
597
|
/** When the tab last became hidden — used for idle-resume re-page. */
|
|
596
598
|
hiddenAt: null,
|
|
597
599
|
/** Last user interaction — freezes dwell when stale while visible. */
|
|
@@ -820,9 +822,9 @@ var AmplifyUpSDK = class {
|
|
|
820
822
|
}
|
|
821
823
|
/**
|
|
822
824
|
* Automatic page-level Scroll Depth + Time on Page.
|
|
823
|
-
*
|
|
824
|
-
*
|
|
825
|
-
*
|
|
825
|
+
* Time on Page fires once per visit when the visit ends (route change,
|
|
826
|
+
* tab close, or 30-minute idle resume). Hidden tabs pause the clock;
|
|
827
|
+
* visible-but-idle tabs freeze after DWELL_ACTIVITY_IDLE_MS.
|
|
826
828
|
*/
|
|
827
829
|
setupPageEngagement() {
|
|
828
830
|
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
@@ -833,7 +835,7 @@ var AmplifyUpSDK = class {
|
|
|
833
835
|
state.reached = /* @__PURE__ */ new Set();
|
|
834
836
|
state.visibleMs = 0;
|
|
835
837
|
state.visibleSince = document.visibilityState === "visible" ? Date.now() : null;
|
|
836
|
-
state.
|
|
838
|
+
state.dwellEmitted = false;
|
|
837
839
|
state.hiddenAt = document.visibilityState === "hidden" ? Date.now() : null;
|
|
838
840
|
state.lastActivityAt = Date.now();
|
|
839
841
|
state.activityIdle = false;
|
|
@@ -895,48 +897,34 @@ var AmplifyUpSDK = class {
|
|
|
895
897
|
}
|
|
896
898
|
}
|
|
897
899
|
};
|
|
898
|
-
const
|
|
899
|
-
for (const m of DWELL_MILESTONES_SEC) {
|
|
900
|
-
if (m > lastSent) return { seconds: m, reason: "milestone" };
|
|
901
|
-
}
|
|
902
|
-
const nextCheckpoint = Math.floor(lastSent / DWELL_CHECKPOINT_SEC) * DWELL_CHECKPOINT_SEC + DWELL_CHECKPOINT_SEC;
|
|
903
|
-
const target = nextCheckpoint > lastSent ? nextCheckpoint : lastSent + DWELL_CHECKPOINT_SEC;
|
|
904
|
-
return { seconds: target, reason: "checkpoint" };
|
|
905
|
-
};
|
|
906
|
-
const emitDwell = (reason, force = false) => {
|
|
900
|
+
const emitDwell = (reason) => {
|
|
907
901
|
if (this.isPreviewMode()) return;
|
|
902
|
+
if (state.dwellEmitted) return;
|
|
908
903
|
if (!state.activityIdle) {
|
|
909
904
|
accumulateVisible();
|
|
910
905
|
}
|
|
911
906
|
const seconds = Math.floor(state.visibleMs / 1e3);
|
|
912
907
|
if (seconds <= 0) return;
|
|
913
|
-
|
|
914
|
-
if (!force) {
|
|
915
|
-
const target = nextEmitTarget(state.lastDwellSecondsSent);
|
|
916
|
-
if (!target || seconds < target.seconds) return;
|
|
917
|
-
reason = target.reason;
|
|
918
|
-
}
|
|
919
|
-
state.lastDwellSecondsSent = seconds;
|
|
908
|
+
state.dwellEmitted = true;
|
|
920
909
|
this.track("Time on Page", {
|
|
921
910
|
seconds,
|
|
922
911
|
path: this.lastTrackedPath || path(),
|
|
923
912
|
reason
|
|
924
913
|
});
|
|
925
914
|
};
|
|
926
|
-
const
|
|
915
|
+
const evaluateIdle = () => {
|
|
927
916
|
if (document.visibilityState !== "visible") return;
|
|
928
917
|
if (Date.now() - state.lastActivityAt >= DWELL_ACTIVITY_IDLE_MS) {
|
|
929
918
|
freezeActivityIdle();
|
|
930
|
-
return;
|
|
931
919
|
}
|
|
932
|
-
emitDwell("milestone", false);
|
|
933
920
|
};
|
|
934
|
-
this._emitPageDwell = (
|
|
921
|
+
this._emitPageDwell = () => emitDwell("route");
|
|
935
922
|
const onVisibility = () => {
|
|
936
923
|
if (document.visibilityState === "visible") {
|
|
937
924
|
const idleMs = state.hiddenAt != null ? Date.now() - state.hiddenAt : 0;
|
|
938
925
|
state.hiddenAt = null;
|
|
939
926
|
if (idleMs >= SESSION_IDLE_GAP_MS) {
|
|
927
|
+
emitDwell("idle-resume");
|
|
940
928
|
this.resetEngagementQuiet();
|
|
941
929
|
const resumePath = path();
|
|
942
930
|
this.page(resumePath, { resumed: true });
|
|
@@ -953,14 +941,14 @@ var AmplifyUpSDK = class {
|
|
|
953
941
|
state.visibleSince = Date.now();
|
|
954
942
|
state.activityIdle = false;
|
|
955
943
|
} else {
|
|
956
|
-
|
|
944
|
+
accumulateVisible();
|
|
957
945
|
state.hiddenAt = Date.now();
|
|
958
946
|
state.visibleSince = null;
|
|
959
947
|
state.activityIdle = false;
|
|
960
948
|
}
|
|
961
949
|
};
|
|
962
950
|
const onPageHide = () => {
|
|
963
|
-
emitDwell("unload"
|
|
951
|
+
emitDwell("unload");
|
|
964
952
|
if (state.hiddenAt == null) {
|
|
965
953
|
state.hiddenAt = Date.now();
|
|
966
954
|
}
|
|
@@ -981,10 +969,10 @@ var AmplifyUpSDK = class {
|
|
|
981
969
|
window.addEventListener(evt, onActivity, { passive: true });
|
|
982
970
|
}
|
|
983
971
|
checkScroll();
|
|
984
|
-
const
|
|
985
|
-
|
|
972
|
+
const idlePoll = setInterval(() => {
|
|
973
|
+
evaluateIdle();
|
|
986
974
|
}, DWELL_POLL_MS);
|
|
987
|
-
this.trackingIntervals.push(
|
|
975
|
+
this.trackingIntervals.push(idlePoll);
|
|
988
976
|
const previousCleanup = this.trackingCleanup;
|
|
989
977
|
this.trackingCleanup = () => {
|
|
990
978
|
window.removeEventListener("scroll", onScroll);
|
|
@@ -1012,12 +1000,12 @@ var AmplifyUpSDK = class {
|
|
|
1012
1000
|
emit?.(true);
|
|
1013
1001
|
this.resetEngagementQuiet();
|
|
1014
1002
|
}
|
|
1015
|
-
/** Reset dwell/scroll state without emitting (idle resume already flushed
|
|
1003
|
+
/** Reset dwell/scroll state without emitting (idle resume already flushed). */
|
|
1016
1004
|
resetEngagementQuiet() {
|
|
1017
1005
|
const state = this.pageEngagementState;
|
|
1018
1006
|
state.reached = /* @__PURE__ */ new Set();
|
|
1019
1007
|
state.visibleMs = 0;
|
|
1020
|
-
state.
|
|
1008
|
+
state.dwellEmitted = false;
|
|
1021
1009
|
state.hiddenAt = null;
|
|
1022
1010
|
state.lastActivityAt = Date.now();
|
|
1023
1011
|
state.activityIdle = false;
|