@amplifyup/sdk 0.1.19 → 0.1.21
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 +83 -15
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +83 -15
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +18 -1
- package/dist/index.d.ts +18 -1
- package/dist/index.js +85 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -16
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +84 -15
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +84 -15
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -59,6 +59,10 @@ declare class AmplifyUpSDK {
|
|
|
59
59
|
private componentViewObservers;
|
|
60
60
|
private componentViewSeen;
|
|
61
61
|
private pageEngagementActive;
|
|
62
|
+
/** Path of the last page() / routeChange — avoids duplicate SPA fires. */
|
|
63
|
+
private lastTrackedPath;
|
|
64
|
+
private historyHooksInstalled;
|
|
65
|
+
private pageEngagementState;
|
|
62
66
|
constructor(adapter?: CDPAdapter);
|
|
63
67
|
/**
|
|
64
68
|
* Detect if we're running in visual editor mode
|
|
@@ -92,8 +96,20 @@ declare class AmplifyUpSDK {
|
|
|
92
96
|
private currentPath;
|
|
93
97
|
/**
|
|
94
98
|
* Automatic page-level Scroll Depth + Time on Page (dwell heartbeat).
|
|
99
|
+
* State lives on the instance so SPA route changes can reset milestones.
|
|
95
100
|
*/
|
|
96
101
|
private setupPageEngagement;
|
|
102
|
+
private resetEngagementForNewPage;
|
|
103
|
+
/**
|
|
104
|
+
* SPA / soft navigation: fire a page view and reset engagement.
|
|
105
|
+
* No-op when the path has not changed. Safe for React Strict Mode remounts.
|
|
106
|
+
*/
|
|
107
|
+
routeChange(url?: string, properties?: EventProperties): void;
|
|
108
|
+
/**
|
|
109
|
+
* Patch history.pushState / replaceState + popstate for non-React SPAs.
|
|
110
|
+
* React/Next apps should also call routeChange from the provider.
|
|
111
|
+
*/
|
|
112
|
+
private installHistoryHooks;
|
|
97
113
|
/**
|
|
98
114
|
* Automatic Component View when component hosts enter the viewport.
|
|
99
115
|
*/
|
|
@@ -314,6 +330,7 @@ declare function getSDK(adapter?: CDPAdapter): AmplifyUpSDK;
|
|
|
314
330
|
*/
|
|
315
331
|
declare function init(config: AmplifyUpConfig): Promise<void>;
|
|
316
332
|
declare const page: (url: string, properties?: EventProperties) => void;
|
|
333
|
+
declare const routeChange: (url?: string, properties?: EventProperties) => void;
|
|
317
334
|
declare const track: (eventName: string, properties?: EventProperties) => void;
|
|
318
335
|
declare const trackClick: (elementId: string, elementText: string, properties?: EventProperties) => void;
|
|
319
336
|
declare const trackFormSubmit: (formId: string, formData?: EventProperties) => void;
|
|
@@ -369,4 +386,4 @@ declare const verifyAWSConnection: () => {
|
|
|
369
386
|
|
|
370
387
|
declare const _default: AmplifyUpSDK;
|
|
371
388
|
|
|
372
|
-
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, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -59,6 +59,10 @@ declare class AmplifyUpSDK {
|
|
|
59
59
|
private componentViewObservers;
|
|
60
60
|
private componentViewSeen;
|
|
61
61
|
private pageEngagementActive;
|
|
62
|
+
/** Path of the last page() / routeChange — avoids duplicate SPA fires. */
|
|
63
|
+
private lastTrackedPath;
|
|
64
|
+
private historyHooksInstalled;
|
|
65
|
+
private pageEngagementState;
|
|
62
66
|
constructor(adapter?: CDPAdapter);
|
|
63
67
|
/**
|
|
64
68
|
* Detect if we're running in visual editor mode
|
|
@@ -92,8 +96,20 @@ declare class AmplifyUpSDK {
|
|
|
92
96
|
private currentPath;
|
|
93
97
|
/**
|
|
94
98
|
* Automatic page-level Scroll Depth + Time on Page (dwell heartbeat).
|
|
99
|
+
* State lives on the instance so SPA route changes can reset milestones.
|
|
95
100
|
*/
|
|
96
101
|
private setupPageEngagement;
|
|
102
|
+
private resetEngagementForNewPage;
|
|
103
|
+
/**
|
|
104
|
+
* SPA / soft navigation: fire a page view and reset engagement.
|
|
105
|
+
* No-op when the path has not changed. Safe for React Strict Mode remounts.
|
|
106
|
+
*/
|
|
107
|
+
routeChange(url?: string, properties?: EventProperties): void;
|
|
108
|
+
/**
|
|
109
|
+
* Patch history.pushState / replaceState + popstate for non-React SPAs.
|
|
110
|
+
* React/Next apps should also call routeChange from the provider.
|
|
111
|
+
*/
|
|
112
|
+
private installHistoryHooks;
|
|
97
113
|
/**
|
|
98
114
|
* Automatic Component View when component hosts enter the viewport.
|
|
99
115
|
*/
|
|
@@ -314,6 +330,7 @@ declare function getSDK(adapter?: CDPAdapter): AmplifyUpSDK;
|
|
|
314
330
|
*/
|
|
315
331
|
declare function init(config: AmplifyUpConfig): Promise<void>;
|
|
316
332
|
declare const page: (url: string, properties?: EventProperties) => void;
|
|
333
|
+
declare const routeChange: (url?: string, properties?: EventProperties) => void;
|
|
317
334
|
declare const track: (eventName: string, properties?: EventProperties) => void;
|
|
318
335
|
declare const trackClick: (elementId: string, elementText: string, properties?: EventProperties) => void;
|
|
319
336
|
declare const trackFormSubmit: (formId: string, formData?: EventProperties) => void;
|
|
@@ -369,4 +386,4 @@ declare const verifyAWSConnection: () => {
|
|
|
369
386
|
|
|
370
387
|
declare const _default: AmplifyUpSDK;
|
|
371
388
|
|
|
372
|
-
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, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -363,6 +363,15 @@ var AmplifyUpSDK = class {
|
|
|
363
363
|
this.componentViewObservers = [];
|
|
364
364
|
this.componentViewSeen = /* @__PURE__ */ new Set();
|
|
365
365
|
this.pageEngagementActive = false;
|
|
366
|
+
/** Path of the last page() / routeChange — avoids duplicate SPA fires. */
|
|
367
|
+
this.lastTrackedPath = null;
|
|
368
|
+
this.historyHooksInstalled = false;
|
|
369
|
+
this.pageEngagementState = {
|
|
370
|
+
reached: /* @__PURE__ */ new Set(),
|
|
371
|
+
visibleMs: 0,
|
|
372
|
+
visibleSince: null,
|
|
373
|
+
lastDwellSecondsSent: 0
|
|
374
|
+
};
|
|
366
375
|
this.adapter = adapter || new AWSAdapter();
|
|
367
376
|
if (typeof window !== "undefined") {
|
|
368
377
|
this.isVisualEditorMode = this.detectVisualEditorMode();
|
|
@@ -535,7 +544,9 @@ var AmplifyUpSDK = class {
|
|
|
535
544
|
this.initialPageSent = true;
|
|
536
545
|
const url = window.location.pathname;
|
|
537
546
|
this.page(url);
|
|
547
|
+
this.lastTrackedPath = url;
|
|
538
548
|
this.setupPageEngagement();
|
|
549
|
+
this.installHistoryHooks();
|
|
539
550
|
}
|
|
540
551
|
}
|
|
541
552
|
if (this.config?.debug && this.initialized) {
|
|
@@ -578,16 +589,18 @@ var AmplifyUpSDK = class {
|
|
|
578
589
|
}
|
|
579
590
|
/**
|
|
580
591
|
* Automatic page-level Scroll Depth + Time on Page (dwell heartbeat).
|
|
592
|
+
* State lives on the instance so SPA route changes can reset milestones.
|
|
581
593
|
*/
|
|
582
594
|
setupPageEngagement() {
|
|
583
595
|
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
584
596
|
if (this.isPreviewMode() || this.pageEngagementActive) return;
|
|
585
597
|
this.pageEngagementActive = true;
|
|
586
598
|
const milestones = [25, 50, 75, 100];
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
599
|
+
const state = this.pageEngagementState;
|
|
600
|
+
state.reached = /* @__PURE__ */ new Set();
|
|
601
|
+
state.visibleMs = 0;
|
|
602
|
+
state.visibleSince = document.visibilityState === "visible" ? Date.now() : null;
|
|
603
|
+
state.lastDwellSecondsSent = 0;
|
|
591
604
|
let scrollRaf = null;
|
|
592
605
|
const path = () => this.currentPath();
|
|
593
606
|
const measureScrollPercent = () => {
|
|
@@ -609,8 +622,8 @@ var AmplifyUpSDK = class {
|
|
|
609
622
|
if (this.isPreviewMode()) return;
|
|
610
623
|
const pct = measureScrollPercent();
|
|
611
624
|
for (const milestone of milestones) {
|
|
612
|
-
if (pct >= milestone && !reached.has(milestone)) {
|
|
613
|
-
reached.add(milestone);
|
|
625
|
+
if (pct >= milestone && !state.reached.has(milestone)) {
|
|
626
|
+
state.reached.add(milestone);
|
|
614
627
|
this.track("Scroll Depth", {
|
|
615
628
|
percentage: milestone,
|
|
616
629
|
path: path()
|
|
@@ -626,28 +639,29 @@ var AmplifyUpSDK = class {
|
|
|
626
639
|
});
|
|
627
640
|
};
|
|
628
641
|
const accumulateVisible = () => {
|
|
629
|
-
if (visibleSince == null) return;
|
|
630
|
-
visibleMs += Date.now() - visibleSince;
|
|
631
|
-
visibleSince = Date.now();
|
|
642
|
+
if (state.visibleSince == null) return;
|
|
643
|
+
state.visibleMs += Date.now() - state.visibleSince;
|
|
644
|
+
state.visibleSince = Date.now();
|
|
632
645
|
};
|
|
633
646
|
const emitDwell = (force = false) => {
|
|
634
647
|
if (this.isPreviewMode()) return;
|
|
635
648
|
accumulateVisible();
|
|
636
|
-
const seconds = Math.floor(visibleMs / 1e3);
|
|
649
|
+
const seconds = Math.floor(state.visibleMs / 1e3);
|
|
637
650
|
if (seconds <= 0) return;
|
|
638
|
-
if (!force && seconds <= lastDwellSecondsSent) return;
|
|
639
|
-
lastDwellSecondsSent = seconds;
|
|
651
|
+
if (!force && seconds <= state.lastDwellSecondsSent) return;
|
|
652
|
+
state.lastDwellSecondsSent = seconds;
|
|
640
653
|
this.track("Time on Page", {
|
|
641
654
|
seconds,
|
|
642
|
-
path: path()
|
|
655
|
+
path: this.lastTrackedPath || path()
|
|
643
656
|
});
|
|
644
657
|
};
|
|
658
|
+
this._emitPageDwell = emitDwell;
|
|
645
659
|
const onVisibility = () => {
|
|
646
660
|
if (document.visibilityState === "visible") {
|
|
647
|
-
visibleSince = Date.now();
|
|
661
|
+
state.visibleSince = Date.now();
|
|
648
662
|
} else {
|
|
649
663
|
emitDwell(true);
|
|
650
|
-
visibleSince = null;
|
|
664
|
+
state.visibleSince = null;
|
|
651
665
|
}
|
|
652
666
|
};
|
|
653
667
|
const onPageHide = () => {
|
|
@@ -674,11 +688,64 @@ var AmplifyUpSDK = class {
|
|
|
674
688
|
}
|
|
675
689
|
previousCleanup?.();
|
|
676
690
|
this.pageEngagementActive = false;
|
|
691
|
+
delete this._emitPageDwell;
|
|
677
692
|
};
|
|
678
693
|
if (this.config?.debug) {
|
|
679
694
|
console.log("[AmplifyUp SDK] Page engagement tracking enabled");
|
|
680
695
|
}
|
|
681
696
|
}
|
|
697
|
+
resetEngagementForNewPage() {
|
|
698
|
+
const emit = this._emitPageDwell;
|
|
699
|
+
emit?.(true);
|
|
700
|
+
const state = this.pageEngagementState;
|
|
701
|
+
state.reached = /* @__PURE__ */ new Set();
|
|
702
|
+
state.visibleMs = 0;
|
|
703
|
+
state.lastDwellSecondsSent = 0;
|
|
704
|
+
state.visibleSince = typeof document !== "undefined" && document.visibilityState === "visible" ? Date.now() : null;
|
|
705
|
+
this.componentViewSeen.clear();
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* SPA / soft navigation: fire a page view and reset engagement.
|
|
709
|
+
* No-op when the path has not changed. Safe for React Strict Mode remounts.
|
|
710
|
+
*/
|
|
711
|
+
routeChange(url, properties) {
|
|
712
|
+
if (this.isPreviewMode()) return;
|
|
713
|
+
if (!this.isInitialized()) return;
|
|
714
|
+
if (typeof window === "undefined") return;
|
|
715
|
+
const path = url || window.location.pathname || "/";
|
|
716
|
+
if (path === this.lastTrackedPath) return;
|
|
717
|
+
this.resetEngagementForNewPage();
|
|
718
|
+
this.page(path, properties);
|
|
719
|
+
this.lastTrackedPath = path;
|
|
720
|
+
if (!this.pageEngagementActive) {
|
|
721
|
+
this.setupPageEngagement();
|
|
722
|
+
}
|
|
723
|
+
if (this.config?.debug) {
|
|
724
|
+
console.log("[AmplifyUp SDK] Route change page view", path);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Patch history.pushState / replaceState + popstate for non-React SPAs.
|
|
729
|
+
* React/Next apps should also call routeChange from the provider.
|
|
730
|
+
*/
|
|
731
|
+
installHistoryHooks() {
|
|
732
|
+
if (typeof window === "undefined" || this.historyHooksInstalled) return;
|
|
733
|
+
this.historyHooksInstalled = true;
|
|
734
|
+
const notify = () => {
|
|
735
|
+
queueMicrotask(() => this.routeChange(window.location.pathname));
|
|
736
|
+
};
|
|
737
|
+
const wrap = (method) => {
|
|
738
|
+
const original = history[method].bind(history);
|
|
739
|
+
history[method] = (...args) => {
|
|
740
|
+
const result = original(...args);
|
|
741
|
+
notify();
|
|
742
|
+
return result;
|
|
743
|
+
};
|
|
744
|
+
};
|
|
745
|
+
wrap("pushState");
|
|
746
|
+
wrap("replaceState");
|
|
747
|
+
window.addEventListener("popstate", notify);
|
|
748
|
+
}
|
|
682
749
|
/**
|
|
683
750
|
* Automatic Component View when component hosts enter the viewport.
|
|
684
751
|
*/
|
|
@@ -753,6 +820,7 @@ var AmplifyUpSDK = class {
|
|
|
753
820
|
...properties
|
|
754
821
|
};
|
|
755
822
|
this.adapter.page(pageProperties);
|
|
823
|
+
this.lastTrackedPath = url;
|
|
756
824
|
}
|
|
757
825
|
/**
|
|
758
826
|
* Track an event
|
|
@@ -2293,6 +2361,7 @@ async function init(config) {
|
|
|
2293
2361
|
await sdk.init(config);
|
|
2294
2362
|
}
|
|
2295
2363
|
var page = (url, properties) => getSDK().page(url, properties);
|
|
2364
|
+
var routeChange = (url, properties) => getSDK().routeChange(url, properties);
|
|
2296
2365
|
var track = (eventName, properties) => getSDK().track(eventName, properties);
|
|
2297
2366
|
var trackClick = (elementId, elementText, properties) => getSDK().trackClick(elementId, elementText, properties);
|
|
2298
2367
|
var trackFormSubmit = (formId, formData) => getSDK().trackFormSubmit(formId, formData);
|
|
@@ -2353,6 +2422,7 @@ exports.refreshEventTracking = refreshEventTracking;
|
|
|
2353
2422
|
exports.reset = reset;
|
|
2354
2423
|
exports.resolveAmplifyUpTarget = resolveAmplifyUpTarget;
|
|
2355
2424
|
exports.resolveAmplifyUpUrls = resolveAmplifyUpUrls;
|
|
2425
|
+
exports.routeChange = routeChange;
|
|
2356
2426
|
exports.setupComponentViewTracking = setupComponentViewTracking;
|
|
2357
2427
|
exports.setupEventTracking = setupEventTracking;
|
|
2358
2428
|
exports.testTracking = testTracking;
|