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