@amplifyup/sdk 0.1.17 → 0.1.19
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.d.mts +1 -1
- package/dist/AmplifyRenderer.d.ts +1 -1
- package/dist/AmplifyRenderer.js +278 -18
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +278 -18
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +25 -4
- package/dist/index.d.ts +25 -4
- package/dist/index.js +228 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +228 -19
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +278 -18
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +278 -18
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/{types-B2Swk8BW.d.mts → types-Cy5aWQ5c.d.mts} +4 -0
- package/dist/{types-B2Swk8BW.d.ts → types-Cy5aWQ5c.d.ts} +4 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CDPAdapter, A as AmplifyUpConfig, E as EventProperties, I as IdentifyTraits, a as AmplifyUpTarget, b as EventTrackingConfig$1 } from './types-
|
|
2
|
-
export { P as PageConfig, Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, c as resolveAmplifyUpUrls } from './types-
|
|
1
|
+
import { C as CDPAdapter, A as AmplifyUpConfig, E as EventProperties, I as IdentifyTraits, a as AmplifyUpTarget, b as EventTrackingConfig$1 } from './types-Cy5aWQ5c.mjs';
|
|
2
|
+
export { P as PageConfig, Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, c as resolveAmplifyUpUrls } from './types-Cy5aWQ5c.mjs';
|
|
3
3
|
export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUvp.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -18,6 +18,8 @@ interface EventTrackingConfig {
|
|
|
18
18
|
description?: string;
|
|
19
19
|
properties?: string[];
|
|
20
20
|
enabled?: boolean;
|
|
21
|
+
componentId?: string | null;
|
|
22
|
+
componentName?: string | null;
|
|
21
23
|
}
|
|
22
24
|
declare class AmplifyUpSDK {
|
|
23
25
|
private adapter;
|
|
@@ -54,6 +56,9 @@ declare class AmplifyUpSDK {
|
|
|
54
56
|
private attachedEventListeners;
|
|
55
57
|
private trackingIntervals;
|
|
56
58
|
private trackingCleanup;
|
|
59
|
+
private componentViewObservers;
|
|
60
|
+
private componentViewSeen;
|
|
61
|
+
private pageEngagementActive;
|
|
57
62
|
constructor(adapter?: CDPAdapter);
|
|
58
63
|
/**
|
|
59
64
|
* Detect if we're running in visual editor mode
|
|
@@ -83,6 +88,17 @@ declare class AmplifyUpSDK {
|
|
|
83
88
|
* Clear all tracking intervals and event listeners
|
|
84
89
|
*/
|
|
85
90
|
private clearTrackingIntervals;
|
|
91
|
+
/** Current page path for engagement attribution. */
|
|
92
|
+
private currentPath;
|
|
93
|
+
/**
|
|
94
|
+
* Automatic page-level Scroll Depth + Time on Page (dwell heartbeat).
|
|
95
|
+
*/
|
|
96
|
+
private setupPageEngagement;
|
|
97
|
+
/**
|
|
98
|
+
* Automatic Component View when component hosts enter the viewport.
|
|
99
|
+
*/
|
|
100
|
+
setupComponentViewTracking(): void;
|
|
101
|
+
private cleanupComponentViewTracking;
|
|
86
102
|
/**
|
|
87
103
|
* Track a page view
|
|
88
104
|
*/
|
|
@@ -203,7 +219,11 @@ declare class AmplifyUpSDK {
|
|
|
203
219
|
*/
|
|
204
220
|
private setupViewTracking;
|
|
205
221
|
/**
|
|
206
|
-
*
|
|
222
|
+
* Detach listeners/observers without clearing the saved event config.
|
|
223
|
+
*/
|
|
224
|
+
private detachEventListeners;
|
|
225
|
+
/**
|
|
226
|
+
* Clean up all attached event listeners and clear config
|
|
207
227
|
*/
|
|
208
228
|
cleanupEventTracking(): void;
|
|
209
229
|
/**
|
|
@@ -313,6 +333,7 @@ declare const fetchPageConfig: (route: string, preview?: boolean) => Promise<any
|
|
|
313
333
|
declare const setupEventTracking: (config: EventTrackingConfig$1[]) => void;
|
|
314
334
|
declare const cleanupEventTracking: () => void;
|
|
315
335
|
declare const refreshEventTracking: () => void;
|
|
336
|
+
declare const setupComponentViewTracking: () => void;
|
|
316
337
|
declare const getDiagnostics: () => {
|
|
317
338
|
initialized: boolean;
|
|
318
339
|
instanceId: string;
|
|
@@ -348,4 +369,4 @@ declare const verifyAWSConnection: () => {
|
|
|
348
369
|
|
|
349
370
|
declare const _default: AmplifyUpSDK;
|
|
350
371
|
|
|
351
|
-
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, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CDPAdapter, A as AmplifyUpConfig, E as EventProperties, I as IdentifyTraits, a as AmplifyUpTarget, b as EventTrackingConfig$1 } from './types-
|
|
2
|
-
export { P as PageConfig, Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, c as resolveAmplifyUpUrls } from './types-
|
|
1
|
+
import { C as CDPAdapter, A as AmplifyUpConfig, E as EventProperties, I as IdentifyTraits, a as AmplifyUpTarget, b as EventTrackingConfig$1 } from './types-Cy5aWQ5c.js';
|
|
2
|
+
export { P as PageConfig, Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, c as resolveAmplifyUpUrls } from './types-Cy5aWQ5c.js';
|
|
3
3
|
export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUvp.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -18,6 +18,8 @@ interface EventTrackingConfig {
|
|
|
18
18
|
description?: string;
|
|
19
19
|
properties?: string[];
|
|
20
20
|
enabled?: boolean;
|
|
21
|
+
componentId?: string | null;
|
|
22
|
+
componentName?: string | null;
|
|
21
23
|
}
|
|
22
24
|
declare class AmplifyUpSDK {
|
|
23
25
|
private adapter;
|
|
@@ -54,6 +56,9 @@ declare class AmplifyUpSDK {
|
|
|
54
56
|
private attachedEventListeners;
|
|
55
57
|
private trackingIntervals;
|
|
56
58
|
private trackingCleanup;
|
|
59
|
+
private componentViewObservers;
|
|
60
|
+
private componentViewSeen;
|
|
61
|
+
private pageEngagementActive;
|
|
57
62
|
constructor(adapter?: CDPAdapter);
|
|
58
63
|
/**
|
|
59
64
|
* Detect if we're running in visual editor mode
|
|
@@ -83,6 +88,17 @@ declare class AmplifyUpSDK {
|
|
|
83
88
|
* Clear all tracking intervals and event listeners
|
|
84
89
|
*/
|
|
85
90
|
private clearTrackingIntervals;
|
|
91
|
+
/** Current page path for engagement attribution. */
|
|
92
|
+
private currentPath;
|
|
93
|
+
/**
|
|
94
|
+
* Automatic page-level Scroll Depth + Time on Page (dwell heartbeat).
|
|
95
|
+
*/
|
|
96
|
+
private setupPageEngagement;
|
|
97
|
+
/**
|
|
98
|
+
* Automatic Component View when component hosts enter the viewport.
|
|
99
|
+
*/
|
|
100
|
+
setupComponentViewTracking(): void;
|
|
101
|
+
private cleanupComponentViewTracking;
|
|
86
102
|
/**
|
|
87
103
|
* Track a page view
|
|
88
104
|
*/
|
|
@@ -203,7 +219,11 @@ declare class AmplifyUpSDK {
|
|
|
203
219
|
*/
|
|
204
220
|
private setupViewTracking;
|
|
205
221
|
/**
|
|
206
|
-
*
|
|
222
|
+
* Detach listeners/observers without clearing the saved event config.
|
|
223
|
+
*/
|
|
224
|
+
private detachEventListeners;
|
|
225
|
+
/**
|
|
226
|
+
* Clean up all attached event listeners and clear config
|
|
207
227
|
*/
|
|
208
228
|
cleanupEventTracking(): void;
|
|
209
229
|
/**
|
|
@@ -313,6 +333,7 @@ declare const fetchPageConfig: (route: string, preview?: boolean) => Promise<any
|
|
|
313
333
|
declare const setupEventTracking: (config: EventTrackingConfig$1[]) => void;
|
|
314
334
|
declare const cleanupEventTracking: () => void;
|
|
315
335
|
declare const refreshEventTracking: () => void;
|
|
336
|
+
declare const setupComponentViewTracking: () => void;
|
|
316
337
|
declare const getDiagnostics: () => {
|
|
317
338
|
initialized: boolean;
|
|
318
339
|
instanceId: string;
|
|
@@ -348,4 +369,4 @@ declare const verifyAWSConnection: () => {
|
|
|
348
369
|
|
|
349
370
|
declare const _default: AmplifyUpSDK;
|
|
350
371
|
|
|
351
|
-
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, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -360,6 +360,9 @@ var AmplifyUpSDK = class {
|
|
|
360
360
|
this.attachedEventListeners = [];
|
|
361
361
|
this.trackingIntervals = [];
|
|
362
362
|
this.trackingCleanup = null;
|
|
363
|
+
this.componentViewObservers = [];
|
|
364
|
+
this.componentViewSeen = /* @__PURE__ */ new Set();
|
|
365
|
+
this.pageEngagementActive = false;
|
|
363
366
|
this.adapter = adapter || new AWSAdapter();
|
|
364
367
|
if (typeof window !== "undefined") {
|
|
365
368
|
this.isVisualEditorMode = this.detectVisualEditorMode();
|
|
@@ -532,6 +535,7 @@ var AmplifyUpSDK = class {
|
|
|
532
535
|
this.initialPageSent = true;
|
|
533
536
|
const url = window.location.pathname;
|
|
534
537
|
this.page(url);
|
|
538
|
+
this.setupPageEngagement();
|
|
535
539
|
}
|
|
536
540
|
}
|
|
537
541
|
if (this.config?.debug && this.initialized) {
|
|
@@ -564,6 +568,168 @@ var AmplifyUpSDK = class {
|
|
|
564
568
|
}
|
|
565
569
|
this.trackingIntervals.forEach((id) => clearInterval(id));
|
|
566
570
|
this.trackingIntervals = [];
|
|
571
|
+
this.cleanupComponentViewTracking();
|
|
572
|
+
this.pageEngagementActive = false;
|
|
573
|
+
}
|
|
574
|
+
/** Current page path for engagement attribution. */
|
|
575
|
+
currentPath() {
|
|
576
|
+
if (typeof window === "undefined") return "/";
|
|
577
|
+
return window.location.pathname || "/";
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Automatic page-level Scroll Depth + Time on Page (dwell heartbeat).
|
|
581
|
+
*/
|
|
582
|
+
setupPageEngagement() {
|
|
583
|
+
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
584
|
+
if (this.isPreviewMode() || this.pageEngagementActive) return;
|
|
585
|
+
this.pageEngagementActive = true;
|
|
586
|
+
const milestones = [25, 50, 75, 100];
|
|
587
|
+
const reached = /* @__PURE__ */ new Set();
|
|
588
|
+
let visibleMs = 0;
|
|
589
|
+
let visibleSince = document.visibilityState === "visible" ? Date.now() : null;
|
|
590
|
+
let lastDwellSecondsSent = 0;
|
|
591
|
+
let scrollRaf = null;
|
|
592
|
+
const path = () => this.currentPath();
|
|
593
|
+
const measureScrollPercent = () => {
|
|
594
|
+
const doc = document.documentElement;
|
|
595
|
+
const body = document.body;
|
|
596
|
+
const scrollTop = window.scrollY || doc.scrollTop || body?.scrollTop || 0;
|
|
597
|
+
const scrollHeight = Math.max(
|
|
598
|
+
doc.scrollHeight,
|
|
599
|
+
body?.scrollHeight || 0,
|
|
600
|
+
doc.offsetHeight,
|
|
601
|
+
body?.offsetHeight || 0
|
|
602
|
+
);
|
|
603
|
+
const clientHeight = window.innerHeight || doc.clientHeight || 0;
|
|
604
|
+
const traversable = Math.max(scrollHeight - clientHeight, 0);
|
|
605
|
+
if (traversable <= 0) return 100;
|
|
606
|
+
return Math.min(100, Math.round(scrollTop / traversable * 100));
|
|
607
|
+
};
|
|
608
|
+
const checkScroll = () => {
|
|
609
|
+
if (this.isPreviewMode()) return;
|
|
610
|
+
const pct = measureScrollPercent();
|
|
611
|
+
for (const milestone of milestones) {
|
|
612
|
+
if (pct >= milestone && !reached.has(milestone)) {
|
|
613
|
+
reached.add(milestone);
|
|
614
|
+
this.track("Scroll Depth", {
|
|
615
|
+
percentage: milestone,
|
|
616
|
+
path: path()
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
const onScroll = () => {
|
|
622
|
+
if (scrollRaf != null) return;
|
|
623
|
+
scrollRaf = window.requestAnimationFrame(() => {
|
|
624
|
+
scrollRaf = null;
|
|
625
|
+
checkScroll();
|
|
626
|
+
});
|
|
627
|
+
};
|
|
628
|
+
const accumulateVisible = () => {
|
|
629
|
+
if (visibleSince == null) return;
|
|
630
|
+
visibleMs += Date.now() - visibleSince;
|
|
631
|
+
visibleSince = Date.now();
|
|
632
|
+
};
|
|
633
|
+
const emitDwell = (force = false) => {
|
|
634
|
+
if (this.isPreviewMode()) return;
|
|
635
|
+
accumulateVisible();
|
|
636
|
+
const seconds = Math.floor(visibleMs / 1e3);
|
|
637
|
+
if (seconds <= 0) return;
|
|
638
|
+
if (!force && seconds <= lastDwellSecondsSent) return;
|
|
639
|
+
lastDwellSecondsSent = seconds;
|
|
640
|
+
this.track("Time on Page", {
|
|
641
|
+
seconds,
|
|
642
|
+
path: path()
|
|
643
|
+
});
|
|
644
|
+
};
|
|
645
|
+
const onVisibility = () => {
|
|
646
|
+
if (document.visibilityState === "visible") {
|
|
647
|
+
visibleSince = Date.now();
|
|
648
|
+
} else {
|
|
649
|
+
emitDwell(true);
|
|
650
|
+
visibleSince = null;
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
const onPageHide = () => {
|
|
654
|
+
emitDwell(true);
|
|
655
|
+
};
|
|
656
|
+
window.addEventListener("scroll", onScroll, { passive: true });
|
|
657
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
658
|
+
window.addEventListener("pagehide", onPageHide);
|
|
659
|
+
checkScroll();
|
|
660
|
+
const heartbeat = setInterval(() => {
|
|
661
|
+
if (document.visibilityState === "visible") {
|
|
662
|
+
emitDwell(false);
|
|
663
|
+
}
|
|
664
|
+
}, 15e3);
|
|
665
|
+
this.trackingIntervals.push(heartbeat);
|
|
666
|
+
const previousCleanup = this.trackingCleanup;
|
|
667
|
+
this.trackingCleanup = () => {
|
|
668
|
+
window.removeEventListener("scroll", onScroll);
|
|
669
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
670
|
+
window.removeEventListener("pagehide", onPageHide);
|
|
671
|
+
if (scrollRaf != null) {
|
|
672
|
+
window.cancelAnimationFrame(scrollRaf);
|
|
673
|
+
scrollRaf = null;
|
|
674
|
+
}
|
|
675
|
+
previousCleanup?.();
|
|
676
|
+
this.pageEngagementActive = false;
|
|
677
|
+
};
|
|
678
|
+
if (this.config?.debug) {
|
|
679
|
+
console.log("[AmplifyUp SDK] Page engagement tracking enabled");
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Automatic Component View when component hosts enter the viewport.
|
|
684
|
+
*/
|
|
685
|
+
setupComponentViewTracking() {
|
|
686
|
+
if (typeof document === "undefined" || typeof IntersectionObserver === "undefined") {
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
if (this.isPreviewMode()) return;
|
|
690
|
+
this.cleanupComponentViewTracking();
|
|
691
|
+
const hosts = document.querySelectorAll("[data-amplifyup-component]");
|
|
692
|
+
if (hosts.length === 0) {
|
|
693
|
+
if (this.config?.debug) {
|
|
694
|
+
console.log("[AmplifyUp SDK] No component hosts found for Component View");
|
|
695
|
+
}
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
const observer = new IntersectionObserver(
|
|
699
|
+
(entries) => {
|
|
700
|
+
entries.forEach((entry) => {
|
|
701
|
+
if (!entry.isIntersecting) return;
|
|
702
|
+
const el = entry.target;
|
|
703
|
+
const componentId = el.getAttribute("data-amplifyup-component") || el.getAttribute("data-component-id");
|
|
704
|
+
if (!componentId || this.componentViewSeen.has(componentId)) {
|
|
705
|
+
observer.unobserve(el);
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
this.componentViewSeen.add(componentId);
|
|
709
|
+
const componentName = el.getAttribute("data-component-name") || void 0;
|
|
710
|
+
this.track("Component View", {
|
|
711
|
+
componentId,
|
|
712
|
+
componentName,
|
|
713
|
+
path: this.currentPath()
|
|
714
|
+
});
|
|
715
|
+
observer.unobserve(el);
|
|
716
|
+
});
|
|
717
|
+
},
|
|
718
|
+
{ threshold: 0.5 }
|
|
719
|
+
);
|
|
720
|
+
hosts.forEach((host) => observer.observe(host));
|
|
721
|
+
this.componentViewObservers.push(observer);
|
|
722
|
+
if (this.config?.debug) {
|
|
723
|
+
console.log(
|
|
724
|
+
"[AmplifyUp SDK] Component View tracking enabled for",
|
|
725
|
+
hosts.length,
|
|
726
|
+
"hosts"
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
cleanupComponentViewTracking() {
|
|
731
|
+
this.componentViewObservers.forEach((obs) => obs.disconnect());
|
|
732
|
+
this.componentViewObservers = [];
|
|
567
733
|
}
|
|
568
734
|
/**
|
|
569
735
|
* Track a page view
|
|
@@ -603,9 +769,13 @@ var AmplifyUpSDK = class {
|
|
|
603
769
|
instanceId,
|
|
604
770
|
trackingId: this.config?.trackingId,
|
|
605
771
|
url: typeof window !== "undefined" ? window.location.href : void 0,
|
|
772
|
+
path: properties?.path || (typeof window !== "undefined" ? window.location.pathname : void 0),
|
|
606
773
|
// Timestamp is included in event payload
|
|
607
774
|
...properties
|
|
608
775
|
};
|
|
776
|
+
if (!trackProperties.path && typeof window !== "undefined") {
|
|
777
|
+
trackProperties.path = window.location.pathname;
|
|
778
|
+
}
|
|
609
779
|
this.adapter.track(eventName, trackProperties);
|
|
610
780
|
}
|
|
611
781
|
/**
|
|
@@ -894,6 +1064,13 @@ Available Console Commands:
|
|
|
894
1064
|
if (pageConfig?.eventTracking) {
|
|
895
1065
|
this.setupEventTracking(pageConfig.eventTracking);
|
|
896
1066
|
}
|
|
1067
|
+
if (typeof window !== "undefined") {
|
|
1068
|
+
window.setTimeout(() => this.setupComponentViewTracking(), 150);
|
|
1069
|
+
window.setTimeout(() => {
|
|
1070
|
+
this.setupComponentViewTracking();
|
|
1071
|
+
this.refreshEventTracking();
|
|
1072
|
+
}, 800);
|
|
1073
|
+
}
|
|
897
1074
|
return pageConfig;
|
|
898
1075
|
}
|
|
899
1076
|
/**
|
|
@@ -901,10 +1078,10 @@ Available Console Commands:
|
|
|
901
1078
|
*/
|
|
902
1079
|
setupEventTracking(eventConfig) {
|
|
903
1080
|
if (typeof document === "undefined") return;
|
|
904
|
-
this.
|
|
905
|
-
this.eventTrackingConfig = eventConfig;
|
|
1081
|
+
this.detachEventListeners();
|
|
1082
|
+
this.eventTrackingConfig = Array.isArray(eventConfig) ? [...eventConfig] : [];
|
|
906
1083
|
if (this.config?.debug) {
|
|
907
|
-
console.log("[AmplifyUp SDK] Setting up event tracking:",
|
|
1084
|
+
console.log("[AmplifyUp SDK] Setting up event tracking:", this.eventTrackingConfig.length, "events");
|
|
908
1085
|
}
|
|
909
1086
|
if (document.readyState === "loading") {
|
|
910
1087
|
document.addEventListener("DOMContentLoaded", () => this.attachEventListeners());
|
|
@@ -919,19 +1096,35 @@ Available Console Commands:
|
|
|
919
1096
|
if (typeof document === "undefined") return;
|
|
920
1097
|
this.eventTrackingConfig.forEach((eventConfig) => {
|
|
921
1098
|
if (eventConfig.enabled === false) return;
|
|
1099
|
+
if (!eventConfig.selector) {
|
|
1100
|
+
if (this.config?.debug) {
|
|
1101
|
+
console.warn(`[AmplifyUp SDK] Event ${eventConfig.eventName} has no selector, skipping`);
|
|
1102
|
+
}
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
922
1105
|
let targetElements = [];
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
1106
|
+
try {
|
|
1107
|
+
const escapeAttr = (value) => typeof CSS !== "undefined" && typeof CSS.escape === "function" ? CSS.escape(value) : value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
1108
|
+
const scopeRoot = eventConfig.componentId ? document.querySelector(
|
|
1109
|
+
`[data-amplifyup-component="${escapeAttr(eventConfig.componentId)}"], [data-component-id="${escapeAttr(eventConfig.componentId)}"]`
|
|
1110
|
+
) : document;
|
|
1111
|
+
if (!scopeRoot) {
|
|
927
1112
|
if (this.config?.debug) {
|
|
928
|
-
console.
|
|
1113
|
+
console.log(
|
|
1114
|
+
`[AmplifyUp SDK] Component host not found for ${eventConfig.componentId}`
|
|
1115
|
+
);
|
|
929
1116
|
}
|
|
930
1117
|
return;
|
|
931
1118
|
}
|
|
932
|
-
|
|
1119
|
+
targetElements = Array.from(
|
|
1120
|
+
scopeRoot.querySelectorAll(eventConfig.selector)
|
|
1121
|
+
);
|
|
1122
|
+
if (scopeRoot instanceof Element && scopeRoot !== document.documentElement && scopeRoot.matches?.(eventConfig.selector)) {
|
|
1123
|
+
targetElements.unshift(scopeRoot);
|
|
1124
|
+
}
|
|
1125
|
+
} catch (e) {
|
|
933
1126
|
if (this.config?.debug) {
|
|
934
|
-
console.warn(`[AmplifyUp SDK]
|
|
1127
|
+
console.warn(`[AmplifyUp SDK] Invalid selector: ${eventConfig.selector}`, e);
|
|
935
1128
|
}
|
|
936
1129
|
return;
|
|
937
1130
|
}
|
|
@@ -987,8 +1180,15 @@ Available Console Commands:
|
|
|
987
1180
|
handleTrackedEvent(event, config, element) {
|
|
988
1181
|
const properties = {
|
|
989
1182
|
eventType: config.eventType,
|
|
990
|
-
selector: config.selector
|
|
1183
|
+
selector: config.selector,
|
|
1184
|
+
path: this.currentPath()
|
|
991
1185
|
};
|
|
1186
|
+
if (config.componentId) {
|
|
1187
|
+
properties.componentId = config.componentId;
|
|
1188
|
+
}
|
|
1189
|
+
if (config.componentName) {
|
|
1190
|
+
properties.componentName = config.componentName;
|
|
1191
|
+
}
|
|
992
1192
|
if (config.properties && config.properties.length > 0) {
|
|
993
1193
|
config.properties.forEach((prop) => {
|
|
994
1194
|
const dataAttrValue = element.getAttribute(`data-${prop}`);
|
|
@@ -1059,9 +1259,9 @@ Available Console Commands:
|
|
|
1059
1259
|
element._amplifyupViewObserver = observer;
|
|
1060
1260
|
}
|
|
1061
1261
|
/**
|
|
1062
|
-
*
|
|
1262
|
+
* Detach listeners/observers without clearing the saved event config.
|
|
1063
1263
|
*/
|
|
1064
|
-
|
|
1264
|
+
detachEventListeners() {
|
|
1065
1265
|
this.attachedEventListeners.forEach(({ element, eventType, handler }) => {
|
|
1066
1266
|
element.removeEventListener(eventType, handler);
|
|
1067
1267
|
});
|
|
@@ -1075,6 +1275,12 @@ Available Console Commands:
|
|
|
1075
1275
|
}
|
|
1076
1276
|
});
|
|
1077
1277
|
}
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* Clean up all attached event listeners and clear config
|
|
1281
|
+
*/
|
|
1282
|
+
cleanupEventTracking() {
|
|
1283
|
+
this.detachEventListeners();
|
|
1078
1284
|
this.eventTrackingConfig = [];
|
|
1079
1285
|
if (this.config?.debug) {
|
|
1080
1286
|
console.log("[AmplifyUp SDK] Cleaned up event tracking");
|
|
@@ -1084,11 +1290,13 @@ Available Console Commands:
|
|
|
1084
1290
|
* Manually trigger event tracking setup (useful after dynamic content loads)
|
|
1085
1291
|
*/
|
|
1086
1292
|
refreshEventTracking() {
|
|
1087
|
-
if (this.eventTrackingConfig.length
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1293
|
+
if (this.eventTrackingConfig.length === 0) return;
|
|
1294
|
+
const config = [...this.eventTrackingConfig];
|
|
1295
|
+
this.detachEventListeners();
|
|
1296
|
+
this.eventTrackingConfig = config;
|
|
1297
|
+
this.attachEventListeners();
|
|
1298
|
+
if (this.config?.debug) {
|
|
1299
|
+
console.log("[AmplifyUp SDK] Refreshed event tracking:", config.length, "events");
|
|
1092
1300
|
}
|
|
1093
1301
|
}
|
|
1094
1302
|
/** Origins allowed to send Composer postMessage commands to the SDK. */
|
|
@@ -2104,6 +2312,7 @@ var fetchPageConfig = (route, preview) => getSDK().fetchPageConfig(route, previe
|
|
|
2104
2312
|
var setupEventTracking = (config) => getSDK().setupEventTracking(config);
|
|
2105
2313
|
var cleanupEventTracking = () => getSDK().cleanupEventTracking();
|
|
2106
2314
|
var refreshEventTracking = () => getSDK().refreshEventTracking();
|
|
2315
|
+
var setupComponentViewTracking = () => getSDK().setupComponentViewTracking();
|
|
2107
2316
|
var getDiagnostics = () => getSDK().getDiagnostics();
|
|
2108
2317
|
var getStatus = () => {
|
|
2109
2318
|
const status = getSDK().getStatus();
|
|
@@ -2144,6 +2353,7 @@ exports.refreshEventTracking = refreshEventTracking;
|
|
|
2144
2353
|
exports.reset = reset;
|
|
2145
2354
|
exports.resolveAmplifyUpTarget = resolveAmplifyUpTarget;
|
|
2146
2355
|
exports.resolveAmplifyUpUrls = resolveAmplifyUpUrls;
|
|
2356
|
+
exports.setupComponentViewTracking = setupComponentViewTracking;
|
|
2147
2357
|
exports.setupEventTracking = setupEventTracking;
|
|
2148
2358
|
exports.testTracking = testTracking;
|
|
2149
2359
|
exports.track = track;
|