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