@temps-sdk/react-analytics 0.0.1-beta.39 → 0.0.1-beta.40
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/SessionRecorder.js
CHANGED
|
@@ -55,7 +55,7 @@ domain, enabled = false, excludedPaths = [], sessionSampleRate = 1.0, maskAllInp
|
|
|
55
55
|
}, maskInputOptions = {
|
|
56
56
|
password: true,
|
|
57
57
|
email: true,
|
|
58
|
-
}, batchSize =
|
|
58
|
+
}, batchSize = 100, flushInterval = 10000, sampling = {}, }) {
|
|
59
59
|
const stopFnRef = useRef(null);
|
|
60
60
|
const eventsRef = useRef([]);
|
|
61
61
|
const sessionIdRef = useRef("");
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./useTrackPageview";
|
|
|
6
6
|
export * from "./usePageLeave";
|
|
7
7
|
export * from "./useSpeedAnalytics";
|
|
8
8
|
export * from "./useEngagementTracking";
|
|
9
|
+
export * from "./useScrollVisibility";
|
|
9
10
|
export { EngagementTracker, type EngagementTrackerOptions, type EngagementData } from "./EngagementTracker";
|
|
10
11
|
export { SessionRecorder, SESSION_RECORDER_ENDPOINT } from "./SessionRecorder";
|
|
11
12
|
export { SessionRecordingProvider, useSessionRecording, useSessionRecordingControl } from "./useSessionRecording";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,KAAK,wBAAwB,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC5G,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,0BAA0B,EAC3B,MAAM,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,KAAK,wBAAwB,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC5G,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,0BAA0B,EAC3B,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./useTrackPageview";
|
|
|
7
7
|
export * from "./usePageLeave";
|
|
8
8
|
export * from "./useSpeedAnalytics";
|
|
9
9
|
export * from "./useEngagementTracking";
|
|
10
|
+
export * from "./useScrollVisibility";
|
|
10
11
|
export { EngagementTracker } from "./EngagementTracker";
|
|
11
12
|
export { SessionRecorder, SESSION_RECORDER_ENDPOINT } from "./SessionRecorder";
|
|
12
13
|
export { SessionRecordingProvider, useSessionRecording, useSessionRecordingControl } from "./useSessionRecording";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { JsonValue } from "./types";
|
|
2
|
+
export interface UseScrollVisibilityOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Event name to track when component becomes visible.
|
|
5
|
+
* @default "component_visible"
|
|
6
|
+
*/
|
|
7
|
+
eventName?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Additional data to send with the event.
|
|
10
|
+
*/
|
|
11
|
+
eventData?: Record<string, JsonValue>;
|
|
12
|
+
/**
|
|
13
|
+
* Percentage of the element that must be visible (0.0 to 1.0).
|
|
14
|
+
* @default 0.5
|
|
15
|
+
*/
|
|
16
|
+
threshold?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Root element for intersection observer (null = viewport).
|
|
19
|
+
* @default null
|
|
20
|
+
*/
|
|
21
|
+
root?: Element | null;
|
|
22
|
+
/**
|
|
23
|
+
* Margin around root element.
|
|
24
|
+
* @default "0px"
|
|
25
|
+
*/
|
|
26
|
+
rootMargin?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to track only once (true) or every time it becomes visible (false).
|
|
29
|
+
* @default true
|
|
30
|
+
*/
|
|
31
|
+
once?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether tracking is enabled.
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
enabled?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Hook that tracks when a component scrolls into view using Intersection Observer.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* function MyComponent() {
|
|
44
|
+
* const ref = useScrollVisibility({
|
|
45
|
+
* eventName: "hero_section_viewed",
|
|
46
|
+
* eventData: { section: "hero" },
|
|
47
|
+
* threshold: 0.75
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* return <div ref={ref}>Hero Section</div>;
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @param options - Configuration options
|
|
55
|
+
* @returns A ref callback to attach to the element you want to track
|
|
56
|
+
*/
|
|
57
|
+
export declare function useScrollVisibility(options?: UseScrollVisibilityOptions): (node: HTMLElement | null) => void;
|
|
58
|
+
//# sourceMappingURL=useScrollVisibility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScrollVisibility.d.ts","sourceRoot":"","sources":["../src/useScrollVisibility.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAEtC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAEtB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,0BAA+B,UAyBjE,WAAW,GAAG,IAAI,UAwC5B"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
3
|
+
import { useTempsAnalytics } from "./Provider";
|
|
4
|
+
/**
|
|
5
|
+
* Hook that tracks when a component scrolls into view using Intersection Observer.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* function MyComponent() {
|
|
10
|
+
* const ref = useScrollVisibility({
|
|
11
|
+
* eventName: "hero_section_viewed",
|
|
12
|
+
* eventData: { section: "hero" },
|
|
13
|
+
* threshold: 0.75
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* return <div ref={ref}>Hero Section</div>;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @param options - Configuration options
|
|
21
|
+
* @returns A ref callback to attach to the element you want to track
|
|
22
|
+
*/
|
|
23
|
+
export function useScrollVisibility(options = {}) {
|
|
24
|
+
const { eventName = "component_visible", eventData, threshold = 0.5, root = null, rootMargin = "0px", once = true, enabled = true, } = options;
|
|
25
|
+
const { trackEvent } = useTempsAnalytics();
|
|
26
|
+
const hasTrackedRef = useRef(false);
|
|
27
|
+
const observerRef = useRef(null);
|
|
28
|
+
// Cleanup function
|
|
29
|
+
const cleanup = useCallback(() => {
|
|
30
|
+
if (observerRef.current) {
|
|
31
|
+
observerRef.current.disconnect();
|
|
32
|
+
observerRef.current = null;
|
|
33
|
+
}
|
|
34
|
+
}, []);
|
|
35
|
+
// Callback ref that sets up the observer when element is attached
|
|
36
|
+
const ref = useCallback((node) => {
|
|
37
|
+
// Clean up previous observer
|
|
38
|
+
cleanup();
|
|
39
|
+
if (!enabled || !node) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
// Reset tracking state if once is false
|
|
43
|
+
if (!once) {
|
|
44
|
+
hasTrackedRef.current = false;
|
|
45
|
+
}
|
|
46
|
+
observerRef.current = new IntersectionObserver((entries) => {
|
|
47
|
+
entries.forEach((entry) => {
|
|
48
|
+
if (entry.isIntersecting && (!once || !hasTrackedRef.current)) {
|
|
49
|
+
trackEvent(eventName, eventData);
|
|
50
|
+
hasTrackedRef.current = true;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}, {
|
|
54
|
+
root,
|
|
55
|
+
rootMargin,
|
|
56
|
+
threshold,
|
|
57
|
+
});
|
|
58
|
+
observerRef.current.observe(node);
|
|
59
|
+
}, [eventName, eventData, threshold, root, rootMargin, once, enabled, trackEvent, cleanup]);
|
|
60
|
+
// Cleanup on unmount
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
return cleanup;
|
|
63
|
+
}, [cleanup]);
|
|
64
|
+
return ref;
|
|
65
|
+
}
|