@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/AmplifyRenderer.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) {
|
|
@@ -346,8 +349,6 @@ function isComposerPreview() {
|
|
|
346
349
|
|
|
347
350
|
// src/index.ts
|
|
348
351
|
var SESSION_IDLE_GAP_MS = 30 * 60 * 1e3;
|
|
349
|
-
var DWELL_MILESTONES_SEC = [15, 30, 60, 120, 300];
|
|
350
|
-
var DWELL_CHECKPOINT_SEC = 15 * 60;
|
|
351
352
|
var DWELL_ACTIVITY_IDLE_MS = 2 * 60 * 1e3;
|
|
352
353
|
var DWELL_POLL_MS = 5e3;
|
|
353
354
|
function readPreviewQueryOverrides() {
|
|
@@ -418,7 +419,8 @@ var AmplifyUpSDK = class {
|
|
|
418
419
|
reached: /* @__PURE__ */ new Set(),
|
|
419
420
|
visibleMs: 0,
|
|
420
421
|
visibleSince: null,
|
|
421
|
-
|
|
422
|
+
/** True after Time on Page has been sent for the current visit. */
|
|
423
|
+
dwellEmitted: false,
|
|
422
424
|
/** When the tab last became hidden — used for idle-resume re-page. */
|
|
423
425
|
hiddenAt: null,
|
|
424
426
|
/** Last user interaction — freezes dwell when stale while visible. */
|
|
@@ -647,9 +649,9 @@ var AmplifyUpSDK = class {
|
|
|
647
649
|
}
|
|
648
650
|
/**
|
|
649
651
|
* Automatic page-level Scroll Depth + Time on Page.
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
*
|
|
652
|
+
* Time on Page fires once per visit when the visit ends (route change,
|
|
653
|
+
* tab close, or 30-minute idle resume). Hidden tabs pause the clock;
|
|
654
|
+
* visible-but-idle tabs freeze after DWELL_ACTIVITY_IDLE_MS.
|
|
653
655
|
*/
|
|
654
656
|
setupPageEngagement() {
|
|
655
657
|
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
@@ -660,7 +662,7 @@ var AmplifyUpSDK = class {
|
|
|
660
662
|
state.reached = /* @__PURE__ */ new Set();
|
|
661
663
|
state.visibleMs = 0;
|
|
662
664
|
state.visibleSince = document.visibilityState === "visible" ? Date.now() : null;
|
|
663
|
-
state.
|
|
665
|
+
state.dwellEmitted = false;
|
|
664
666
|
state.hiddenAt = document.visibilityState === "hidden" ? Date.now() : null;
|
|
665
667
|
state.lastActivityAt = Date.now();
|
|
666
668
|
state.activityIdle = false;
|
|
@@ -722,48 +724,34 @@ var AmplifyUpSDK = class {
|
|
|
722
724
|
}
|
|
723
725
|
}
|
|
724
726
|
};
|
|
725
|
-
const
|
|
726
|
-
for (const m of DWELL_MILESTONES_SEC) {
|
|
727
|
-
if (m > lastSent) return { seconds: m, reason: "milestone" };
|
|
728
|
-
}
|
|
729
|
-
const nextCheckpoint = Math.floor(lastSent / DWELL_CHECKPOINT_SEC) * DWELL_CHECKPOINT_SEC + DWELL_CHECKPOINT_SEC;
|
|
730
|
-
const target = nextCheckpoint > lastSent ? nextCheckpoint : lastSent + DWELL_CHECKPOINT_SEC;
|
|
731
|
-
return { seconds: target, reason: "checkpoint" };
|
|
732
|
-
};
|
|
733
|
-
const emitDwell = (reason, force = false) => {
|
|
727
|
+
const emitDwell = (reason) => {
|
|
734
728
|
if (this.isPreviewMode()) return;
|
|
729
|
+
if (state.dwellEmitted) return;
|
|
735
730
|
if (!state.activityIdle) {
|
|
736
731
|
accumulateVisible();
|
|
737
732
|
}
|
|
738
733
|
const seconds = Math.floor(state.visibleMs / 1e3);
|
|
739
734
|
if (seconds <= 0) return;
|
|
740
|
-
|
|
741
|
-
if (!force) {
|
|
742
|
-
const target = nextEmitTarget(state.lastDwellSecondsSent);
|
|
743
|
-
if (!target || seconds < target.seconds) return;
|
|
744
|
-
reason = target.reason;
|
|
745
|
-
}
|
|
746
|
-
state.lastDwellSecondsSent = seconds;
|
|
735
|
+
state.dwellEmitted = true;
|
|
747
736
|
this.track("Time on Page", {
|
|
748
737
|
seconds,
|
|
749
738
|
path: this.lastTrackedPath || path(),
|
|
750
739
|
reason
|
|
751
740
|
});
|
|
752
741
|
};
|
|
753
|
-
const
|
|
742
|
+
const evaluateIdle = () => {
|
|
754
743
|
if (document.visibilityState !== "visible") return;
|
|
755
744
|
if (Date.now() - state.lastActivityAt >= DWELL_ACTIVITY_IDLE_MS) {
|
|
756
745
|
freezeActivityIdle();
|
|
757
|
-
return;
|
|
758
746
|
}
|
|
759
|
-
emitDwell("milestone", false);
|
|
760
747
|
};
|
|
761
|
-
this._emitPageDwell = (
|
|
748
|
+
this._emitPageDwell = () => emitDwell("route");
|
|
762
749
|
const onVisibility = () => {
|
|
763
750
|
if (document.visibilityState === "visible") {
|
|
764
751
|
const idleMs = state.hiddenAt != null ? Date.now() - state.hiddenAt : 0;
|
|
765
752
|
state.hiddenAt = null;
|
|
766
753
|
if (idleMs >= SESSION_IDLE_GAP_MS) {
|
|
754
|
+
emitDwell("idle-resume");
|
|
767
755
|
this.resetEngagementQuiet();
|
|
768
756
|
const resumePath = path();
|
|
769
757
|
this.page(resumePath, { resumed: true });
|
|
@@ -780,14 +768,14 @@ var AmplifyUpSDK = class {
|
|
|
780
768
|
state.visibleSince = Date.now();
|
|
781
769
|
state.activityIdle = false;
|
|
782
770
|
} else {
|
|
783
|
-
|
|
771
|
+
accumulateVisible();
|
|
784
772
|
state.hiddenAt = Date.now();
|
|
785
773
|
state.visibleSince = null;
|
|
786
774
|
state.activityIdle = false;
|
|
787
775
|
}
|
|
788
776
|
};
|
|
789
777
|
const onPageHide = () => {
|
|
790
|
-
emitDwell("unload"
|
|
778
|
+
emitDwell("unload");
|
|
791
779
|
if (state.hiddenAt == null) {
|
|
792
780
|
state.hiddenAt = Date.now();
|
|
793
781
|
}
|
|
@@ -808,10 +796,10 @@ var AmplifyUpSDK = class {
|
|
|
808
796
|
window.addEventListener(evt, onActivity, { passive: true });
|
|
809
797
|
}
|
|
810
798
|
checkScroll();
|
|
811
|
-
const
|
|
812
|
-
|
|
799
|
+
const idlePoll = setInterval(() => {
|
|
800
|
+
evaluateIdle();
|
|
813
801
|
}, DWELL_POLL_MS);
|
|
814
|
-
this.trackingIntervals.push(
|
|
802
|
+
this.trackingIntervals.push(idlePoll);
|
|
815
803
|
const previousCleanup = this.trackingCleanup;
|
|
816
804
|
this.trackingCleanup = () => {
|
|
817
805
|
window.removeEventListener("scroll", onScroll);
|
|
@@ -839,12 +827,12 @@ var AmplifyUpSDK = class {
|
|
|
839
827
|
emit?.(true);
|
|
840
828
|
this.resetEngagementQuiet();
|
|
841
829
|
}
|
|
842
|
-
/** Reset dwell/scroll state without emitting (idle resume already flushed
|
|
830
|
+
/** Reset dwell/scroll state without emitting (idle resume already flushed). */
|
|
843
831
|
resetEngagementQuiet() {
|
|
844
832
|
const state = this.pageEngagementState;
|
|
845
833
|
state.reached = /* @__PURE__ */ new Set();
|
|
846
834
|
state.visibleMs = 0;
|
|
847
|
-
state.
|
|
835
|
+
state.dwellEmitted = false;
|
|
848
836
|
state.hiddenAt = null;
|
|
849
837
|
state.lastActivityAt = Date.now();
|
|
850
838
|
state.activityIdle = false;
|