@amplifyup/sdk 0.1.20 → 0.1.22

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/index.d.mts CHANGED
@@ -11,6 +11,11 @@ export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUv
11
11
  * All runtime data (events, profiles, decisions) lives in AWS.
12
12
  */
13
13
 
14
+ /**
15
+ * Idle gap that starts a new logical visit when a tab is reactivated.
16
+ * Must stay aligned with SESSION_GAP_MS in apps/orchestrator/lib/aws-profiles.ts.
17
+ */
18
+ declare const SESSION_IDLE_GAP_MS: number;
14
19
  interface EventTrackingConfig {
15
20
  eventName: string;
16
21
  eventType: string;
@@ -99,7 +104,10 @@ declare class AmplifyUpSDK {
99
104
  * State lives on the instance so SPA route changes can reset milestones.
100
105
  */
101
106
  private setupPageEngagement;
107
+ /** Flush dwell then reset — used on SPA route changes. */
102
108
  private resetEngagementForNewPage;
109
+ /** Reset dwell/scroll state without emitting (idle resume already flushed on hide). */
110
+ private resetEngagementQuiet;
103
111
  /**
104
112
  * SPA / soft navigation: fire a page view and reset engagement.
105
113
  * No-op when the path has not changed. Safe for React Strict Mode remounts.
@@ -386,4 +394,4 @@ declare const verifyAWSConnection: () => {
386
394
 
387
395
  declare const _default: AmplifyUpSDK;
388
396
 
389
- export { AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, IdentifyTraits, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, _default as default, fetchPageConfig, getDiagnostics, getInstanceId, getOrchestratorUrl, getSDK, getStatus, getTarget, getTrackingId, getUserId, identify, init, page, refreshEventTracking, reset, routeChange, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
397
+ export { AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, IdentifyTraits, SESSION_IDLE_GAP_MS, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, _default as default, fetchPageConfig, getDiagnostics, getInstanceId, getOrchestratorUrl, getSDK, getStatus, getTarget, getTrackingId, getUserId, identify, init, page, refreshEventTracking, reset, routeChange, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
package/dist/index.d.ts CHANGED
@@ -11,6 +11,11 @@ export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUv
11
11
  * All runtime data (events, profiles, decisions) lives in AWS.
12
12
  */
13
13
 
14
+ /**
15
+ * Idle gap that starts a new logical visit when a tab is reactivated.
16
+ * Must stay aligned with SESSION_GAP_MS in apps/orchestrator/lib/aws-profiles.ts.
17
+ */
18
+ declare const SESSION_IDLE_GAP_MS: number;
14
19
  interface EventTrackingConfig {
15
20
  eventName: string;
16
21
  eventType: string;
@@ -99,7 +104,10 @@ declare class AmplifyUpSDK {
99
104
  * State lives on the instance so SPA route changes can reset milestones.
100
105
  */
101
106
  private setupPageEngagement;
107
+ /** Flush dwell then reset — used on SPA route changes. */
102
108
  private resetEngagementForNewPage;
109
+ /** Reset dwell/scroll state without emitting (idle resume already flushed on hide). */
110
+ private resetEngagementQuiet;
103
111
  /**
104
112
  * SPA / soft navigation: fire a page view and reset engagement.
105
113
  * No-op when the path has not changed. Safe for React Strict Mode remounts.
@@ -386,4 +394,4 @@ declare const verifyAWSConnection: () => {
386
394
 
387
395
  declare const _default: AmplifyUpSDK;
388
396
 
389
- export { AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, IdentifyTraits, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, _default as default, fetchPageConfig, getDiagnostics, getInstanceId, getOrchestratorUrl, getSDK, getStatus, getTarget, getTrackingId, getUserId, identify, init, page, refreshEventTracking, reset, routeChange, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
397
+ export { AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, IdentifyTraits, SESSION_IDLE_GAP_MS, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, _default as default, fetchPageConfig, getDiagnostics, getInstanceId, getOrchestratorUrl, getSDK, getStatus, getTarget, getTrackingId, getUserId, identify, init, page, refreshEventTracking, reset, routeChange, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
package/dist/index.js CHANGED
@@ -304,6 +304,7 @@ function isComposerPreview() {
304
304
  }
305
305
 
306
306
  // src/index.ts
307
+ var SESSION_IDLE_GAP_MS = 30 * 60 * 1e3;
307
308
  function readPreviewQueryOverrides() {
308
309
  if (typeof window === "undefined") return {};
309
310
  const params = new URLSearchParams(window.location.search);
@@ -370,7 +371,9 @@ var AmplifyUpSDK = class {
370
371
  reached: /* @__PURE__ */ new Set(),
371
372
  visibleMs: 0,
372
373
  visibleSince: null,
373
- lastDwellSecondsSent: 0
374
+ lastDwellSecondsSent: 0,
375
+ /** When the tab last became hidden — used for idle-resume re-page. */
376
+ hiddenAt: null
374
377
  };
375
378
  this.adapter = adapter || new AWSAdapter();
376
379
  if (typeof window !== "undefined") {
@@ -601,6 +604,7 @@ var AmplifyUpSDK = class {
601
604
  state.visibleMs = 0;
602
605
  state.visibleSince = document.visibilityState === "visible" ? Date.now() : null;
603
606
  state.lastDwellSecondsSent = 0;
607
+ state.hiddenAt = document.visibilityState === "hidden" ? Date.now() : null;
604
608
  let scrollRaf = null;
605
609
  const path = () => this.currentPath();
606
610
  const measureScrollPercent = () => {
@@ -643,12 +647,12 @@ var AmplifyUpSDK = class {
643
647
  state.visibleMs += Date.now() - state.visibleSince;
644
648
  state.visibleSince = Date.now();
645
649
  };
646
- const emitDwell = (force = false) => {
650
+ const emitDwell = (_force = false) => {
647
651
  if (this.isPreviewMode()) return;
648
652
  accumulateVisible();
649
653
  const seconds = Math.floor(state.visibleMs / 1e3);
650
654
  if (seconds <= 0) return;
651
- if (!force && seconds <= state.lastDwellSecondsSent) return;
655
+ if (seconds <= state.lastDwellSecondsSent) return;
652
656
  state.lastDwellSecondsSent = seconds;
653
657
  this.track("Time on Page", {
654
658
  seconds,
@@ -658,14 +662,34 @@ var AmplifyUpSDK = class {
658
662
  this._emitPageDwell = emitDwell;
659
663
  const onVisibility = () => {
660
664
  if (document.visibilityState === "visible") {
665
+ const idleMs = state.hiddenAt != null ? Date.now() - state.hiddenAt : 0;
666
+ state.hiddenAt = null;
667
+ if (idleMs >= SESSION_IDLE_GAP_MS) {
668
+ this.resetEngagementQuiet();
669
+ const resumePath = path();
670
+ this.page(resumePath, { resumed: true });
671
+ this.lastTrackedPath = resumePath;
672
+ if (this.config?.debug) {
673
+ console.log(
674
+ "[AmplifyUp SDK] Idle resume page view",
675
+ resumePath,
676
+ `(hidden ${Math.round(idleMs / 6e4)}m)`
677
+ );
678
+ }
679
+ }
661
680
  state.visibleSince = Date.now();
662
681
  } else {
663
682
  emitDwell(true);
683
+ state.hiddenAt = Date.now();
664
684
  state.visibleSince = null;
665
685
  }
666
686
  };
667
687
  const onPageHide = () => {
668
688
  emitDwell(true);
689
+ if (state.hiddenAt == null) {
690
+ state.hiddenAt = Date.now();
691
+ }
692
+ state.visibleSince = null;
669
693
  };
670
694
  window.addEventListener("scroll", onScroll, { passive: true });
671
695
  document.addEventListener("visibilitychange", onVisibility);
@@ -694,13 +718,19 @@ var AmplifyUpSDK = class {
694
718
  console.log("[AmplifyUp SDK] Page engagement tracking enabled");
695
719
  }
696
720
  }
721
+ /** Flush dwell then reset — used on SPA route changes. */
697
722
  resetEngagementForNewPage() {
698
723
  const emit = this._emitPageDwell;
699
724
  emit?.(true);
725
+ this.resetEngagementQuiet();
726
+ }
727
+ /** Reset dwell/scroll state without emitting (idle resume already flushed on hide). */
728
+ resetEngagementQuiet() {
700
729
  const state = this.pageEngagementState;
701
730
  state.reached = /* @__PURE__ */ new Set();
702
731
  state.visibleMs = 0;
703
732
  state.lastDwellSecondsSent = 0;
733
+ state.hiddenAt = null;
704
734
  state.visibleSince = typeof document !== "undefined" && document.visibilityState === "visible" ? Date.now() : null;
705
735
  this.componentViewSeen.clear();
706
736
  }
@@ -2398,6 +2428,7 @@ var verifyAWSConnection = () => {
2398
2428
  var index_default = getSDK();
2399
2429
 
2400
2430
  exports.AmplifyUpSDK = AmplifyUpSDK;
2431
+ exports.SESSION_IDLE_GAP_MS = SESSION_IDLE_GAP_MS;
2401
2432
  exports.buildLayoutProviderUrl = buildLayoutProviderUrl;
2402
2433
  exports.buildPageRenderUrl = buildPageRenderUrl;
2403
2434
  exports.cleanupEventTracking = cleanupEventTracking;