react-fathom 0.1.11 → 0.2.0

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.
Files changed (70) hide show
  1. package/README.md +886 -24
  2. package/dist/cjs/index.cjs +55 -9
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs/native/index.cjs +1079 -0
  5. package/dist/cjs/native/index.cjs.map +1 -0
  6. package/dist/cjs/next/index.cjs +51 -5
  7. package/dist/cjs/next/index.cjs.map +1 -1
  8. package/dist/es/index.js +55 -9
  9. package/dist/es/index.js.map +1 -1
  10. package/dist/es/native/index.js +1071 -0
  11. package/dist/es/native/index.js.map +1 -0
  12. package/dist/es/next/index.js +51 -5
  13. package/dist/es/next/index.js.map +1 -1
  14. package/dist/react-fathom.js +55 -9
  15. package/dist/react-fathom.js.map +1 -1
  16. package/dist/react-fathom.min.js +2 -2
  17. package/dist/react-fathom.min.js.map +1 -1
  18. package/package.json +27 -4
  19. package/src/FathomContext.tsx +30 -1
  20. package/src/FathomProvider.test.tsx +115 -15
  21. package/src/FathomProvider.tsx +10 -2
  22. package/src/components/TrackClick.test.tsx +7 -7
  23. package/src/components/TrackClick.tsx +1 -1
  24. package/src/components/TrackVisible.test.tsx +7 -7
  25. package/src/components/TrackVisible.tsx +1 -1
  26. package/src/hooks/useFathom.test.tsx +14 -3
  27. package/src/hooks/useTrackOnClick.test.tsx +4 -4
  28. package/src/hooks/useTrackOnClick.ts +1 -1
  29. package/src/hooks/useTrackOnVisible.test.tsx +4 -4
  30. package/src/hooks/useTrackOnVisible.ts +1 -1
  31. package/src/index.ts +1 -0
  32. package/src/native/FathomWebView.test.tsx +410 -0
  33. package/src/native/FathomWebView.tsx +297 -0
  34. package/src/native/NativeFathomProvider.test.tsx +372 -0
  35. package/src/native/NativeFathomProvider.tsx +113 -0
  36. package/src/native/createWebViewClient.test.ts +380 -0
  37. package/src/native/createWebViewClient.ts +271 -0
  38. package/src/native/index.ts +29 -0
  39. package/src/native/react-native.d.ts +74 -0
  40. package/src/native/types.ts +145 -0
  41. package/src/native/useAppStateTracking.test.ts +249 -0
  42. package/src/native/useAppStateTracking.ts +66 -0
  43. package/src/native/useNavigationTracking.test.ts +446 -0
  44. package/src/native/useNavigationTracking.ts +177 -0
  45. package/src/types.ts +36 -9
  46. package/types/FathomContext.d.ts +1 -1
  47. package/types/FathomContext.d.ts.map +1 -1
  48. package/types/FathomProvider.d.ts.map +1 -1
  49. package/types/components/TrackClick.d.ts +1 -1
  50. package/types/components/TrackVisible.d.ts +1 -1
  51. package/types/hooks/useTrackOnClick.d.ts +1 -1
  52. package/types/hooks/useTrackOnVisible.d.ts +1 -1
  53. package/types/index.d.ts +1 -0
  54. package/types/index.d.ts.map +1 -1
  55. package/types/native/FathomWebView.d.ts +59 -0
  56. package/types/native/FathomWebView.d.ts.map +1 -0
  57. package/types/native/NativeFathomProvider.d.ts +36 -0
  58. package/types/native/NativeFathomProvider.d.ts.map +1 -0
  59. package/types/native/createWebViewClient.d.ts +51 -0
  60. package/types/native/createWebViewClient.d.ts.map +1 -0
  61. package/types/native/index.d.ts +10 -0
  62. package/types/native/index.d.ts.map +1 -0
  63. package/types/native/types.d.ts +125 -0
  64. package/types/native/types.d.ts.map +1 -0
  65. package/types/native/useAppStateTracking.d.ts +25 -0
  66. package/types/native/useAppStateTracking.d.ts.map +1 -0
  67. package/types/native/useNavigationTracking.d.ts +30 -0
  68. package/types/native/useNavigationTracking.d.ts.map +1 -0
  69. package/types/types.d.ts +34 -9
  70. package/types/types.d.ts.map +1 -1
@@ -30,7 +30,7 @@ export interface TrackVisibleProps extends EventOptions {
30
30
  *
31
31
  * @example
32
32
  * ```tsx
33
- * <TrackVisible eventName="section-viewed" section="hero">
33
+ * <TrackVisible eventName="section-viewed" _value={1}>
34
34
  * <HeroSection />
35
35
  * </TrackVisible>
36
36
  * ```
@@ -24,7 +24,7 @@ export interface UseTrackOnClickOptions extends EventOptions {
24
24
  * function Button() {
25
25
  * const handleClick = useTrackOnClick({
26
26
  * eventName: 'button-click',
27
- * id: 'signup-button',
27
+ * _value: 100, // Optional: value in cents
28
28
  * callback: (e) => {
29
29
  * console.log('Button clicked!')
30
30
  * // Your custom logic here
@@ -28,7 +28,7 @@ export interface UseTrackOnVisibleOptions extends EventOptions {
28
28
  * function Section() {
29
29
  * const ref = useTrackOnVisible({
30
30
  * eventName: 'section-viewed',
31
- * section: 'hero',
31
+ * _value: 1, // Optional: value in cents
32
32
  * callback: (entry) => {
33
33
  * console.log('Section is visible!', entry.isIntersecting)
34
34
  * // Your custom logic here
package/types/index.d.ts CHANGED
@@ -2,4 +2,5 @@ export * from './FathomContext';
2
2
  export * from './FathomProvider';
3
3
  export * from './hooks';
4
4
  export * from './components';
5
+ export * from './types';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA"}
@@ -0,0 +1,59 @@
1
+ import React from 'react';
2
+ import type { EventOptions, PageViewOptions, LoadOptions } from '../types';
3
+ export interface FathomWebViewRef {
4
+ trackPageview: (opts?: PageViewOptions) => void;
5
+ trackEvent: (eventName: string, opts?: EventOptions) => void;
6
+ trackGoal: (code: string, cents: number) => void;
7
+ blockTrackingForMe: () => void;
8
+ enableTrackingForMe: () => void;
9
+ isReady: () => boolean;
10
+ }
11
+ export interface FathomWebViewProps {
12
+ /**
13
+ * Your Fathom Analytics site ID
14
+ */
15
+ siteId: string;
16
+ /**
17
+ * Options passed to fathom.load()
18
+ */
19
+ loadOptions?: LoadOptions;
20
+ /**
21
+ * Custom domain for Fathom script (if using custom domains feature)
22
+ * @default 'cdn.usefathom.com'
23
+ */
24
+ scriptDomain?: string;
25
+ /**
26
+ * Called when the Fathom script has loaded and is ready
27
+ */
28
+ onReady?: () => void;
29
+ /**
30
+ * Called when an error occurs loading the script
31
+ */
32
+ onError?: (error: string) => void;
33
+ /**
34
+ * Enable debug logging
35
+ */
36
+ debug?: boolean;
37
+ }
38
+ /**
39
+ * Hidden WebView component that loads and manages the Fathom Analytics script.
40
+ *
41
+ * This component renders an invisible WebView that loads the official Fathom
42
+ * tracking script, allowing React Native apps to use Fathom's full functionality.
43
+ *
44
+ * @example
45
+ * ```tsx
46
+ * const fathomRef = useRef<FathomWebViewRef>(null)
47
+ *
48
+ * <FathomWebView
49
+ * ref={fathomRef}
50
+ * siteId="ABCDEFGH"
51
+ * onReady={() => console.log('Fathom ready!')}
52
+ * />
53
+ *
54
+ * // Later, track events:
55
+ * fathomRef.current?.trackPageview({ url: '/home' })
56
+ * ```
57
+ */
58
+ export declare const FathomWebView: React.ForwardRefExoticComponent<FathomWebViewProps & React.RefAttributes<FathomWebViewRef>>;
59
+ //# sourceMappingURL=FathomWebView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FathomWebView.d.ts","sourceRoot":"","sources":["../../src/native/FathomWebView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAMN,MAAM,OAAO,CAAA;AAId,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAE1E,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,CAAC,IAAI,CAAC,EAAE,eAAe,KAAK,IAAI,CAAA;IAC/C,UAAU,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY,KAAK,IAAI,CAAA;IAC5D,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAChD,kBAAkB,EAAE,MAAM,IAAI,CAAA;IAC9B,mBAAmB,EAAE,MAAM,IAAI,CAAA;IAC/B,OAAO,EAAE,MAAM,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,WAAW,CAAC,EAAE,WAAW,CAAA;IAEzB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IAEpB;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAEjC;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,aAAa,6FAgNzB,CAAA"}
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import type { NativeFathomProviderProps } from './types';
3
+ /**
4
+ * A convenience provider for React Native apps that uses a hidden WebView
5
+ * to load the official Fathom Analytics script.
6
+ *
7
+ * This approach ensures full compatibility with Fathom's tracking by using
8
+ * their official JavaScript client, while providing a native React API.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * import { NativeFathomProvider } from 'react-fathom/native'
13
+ *
14
+ * function App() {
15
+ * return (
16
+ * <NativeFathomProvider
17
+ * siteId="YOUR_SITE_ID"
18
+ * debug={__DEV__}
19
+ * trackAppState
20
+ * >
21
+ * <YourApp />
22
+ * </NativeFathomProvider>
23
+ * )
24
+ * }
25
+ * ```
26
+ *
27
+ * @remarks
28
+ * This component renders a hidden WebView that loads Fathom's tracking script.
29
+ * Events are queued until the WebView is ready, then automatically flushed.
30
+ *
31
+ * The WebView approach is used because Fathom Analytics does not currently
32
+ * provide a public API for server-side or mobile event tracking. This ensures
33
+ * your analytics are recorded correctly using Fathom's official client.
34
+ */
35
+ export declare const NativeFathomProvider: React.FC<NativeFathomProviderProps>;
36
+ //# sourceMappingURL=NativeFathomProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeFathomProvider.d.ts","sourceRoot":"","sources":["../../src/native/NativeFathomProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkD,MAAM,OAAO,CAAA;AAMtE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAcxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC,yBAAyB,CA4DpE,CAAA"}
@@ -0,0 +1,51 @@
1
+ import type { FathomClient } from '../types';
2
+ import type { FathomWebViewRef } from './FathomWebView';
3
+ export interface WebViewClientOptions {
4
+ /**
5
+ * Enable debug logging (default: false)
6
+ */
7
+ debug?: boolean;
8
+ /**
9
+ * Enable offline event queuing (default: true)
10
+ * When enabled, events are queued if the WebView isn't ready yet
11
+ */
12
+ enableQueue?: boolean;
13
+ /**
14
+ * Maximum number of events to queue (default: 100)
15
+ */
16
+ maxQueueSize?: number;
17
+ }
18
+ /**
19
+ * Creates a Fathom client that communicates with a FathomWebView component.
20
+ *
21
+ * This client queues commands until the WebView is ready, then flushes them.
22
+ * It implements the standard FathomClient interface for compatibility with
23
+ * the FathomProvider component.
24
+ *
25
+ * @example
26
+ * ```tsx
27
+ * import { createWebViewClient, FathomWebView } from 'react-fathom/native'
28
+ *
29
+ * function App() {
30
+ * const webViewRef = useRef<FathomWebViewRef>(null)
31
+ * const client = useMemo(
32
+ * () => createWebViewClient(() => webViewRef.current, { debug: __DEV__ }),
33
+ * []
34
+ * )
35
+ *
36
+ * return (
37
+ * <FathomProvider client={client} siteId="YOUR_SITE_ID">
38
+ * <FathomWebView ref={webViewRef} siteId="YOUR_SITE_ID" />
39
+ * <YourApp />
40
+ * </FathomProvider>
41
+ * )
42
+ * }
43
+ * ```
44
+ */
45
+ export interface WebViewFathomClient extends FathomClient {
46
+ processQueue: () => number;
47
+ getQueueLength: () => number;
48
+ setWebViewReady: () => void;
49
+ }
50
+ export declare function createWebViewClient(getWebViewRef: () => FathomWebViewRef | null | undefined, options?: WebViewClientOptions): WebViewFathomClient;
51
+ //# sourceMappingURL=createWebViewClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createWebViewClient.d.ts","sourceRoot":"","sources":["../../src/native/createWebViewClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAA8C,MAAM,UAAU,CAAA;AACxF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAEvD,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IAEf;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IAErB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAQD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,mBAAoB,SAAQ,YAAY;IACvD,YAAY,EAAE,MAAM,MAAM,CAAA;IAC1B,cAAc,EAAE,MAAM,MAAM,CAAA;IAC5B,eAAe,EAAE,MAAM,IAAI,CAAA;CAC5B;AAED,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,MAAM,gBAAgB,GAAG,IAAI,GAAG,SAAS,EACxD,OAAO,GAAE,oBAAyB,GACjC,mBAAmB,CA+MrB"}
@@ -0,0 +1,10 @@
1
+ export { FathomWebView, type FathomWebViewRef, type FathomWebViewProps } from './FathomWebView';
2
+ export { createWebViewClient, type WebViewFathomClient, type WebViewClientOptions } from './createWebViewClient';
3
+ export { NativeFathomProvider } from './NativeFathomProvider';
4
+ export { FathomProvider } from '../FathomProvider';
5
+ export { useFathom } from '../hooks/useFathom';
6
+ export { useAppStateTracking } from './useAppStateTracking';
7
+ export { useNavigationTracking } from './useNavigationTracking';
8
+ export type { NativeFathomProviderProps, UseNavigationTrackingOptions, UseAppStateTrackingOptions, FathomClient, EventOptions, LoadOptions, PageViewOptions, } from './types';
9
+ export type { FathomContextInterface, FathomProviderProps, } from '../types';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/native/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAC/F,OAAO,EAAE,mBAAmB,EAAE,KAAK,mBAAmB,EAAE,KAAK,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAGhH,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAGlD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAG/D,YAAY,EACV,yBAAyB,EACzB,4BAA4B,EAC5B,0BAA0B,EAE1B,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,eAAe,GAChB,MAAM,SAAS,CAAA;AAEhB,YAAY,EACV,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,UAAU,CAAA"}
@@ -0,0 +1,125 @@
1
+ import type { MutableRefObject } from 'react';
2
+ import type { FathomClient, EventOptions, LoadOptions, PageViewOptions } from '../types';
3
+ import type { WebViewFathomClient } from './createWebViewClient';
4
+ /**
5
+ * Options for the NativeFathomProvider component
6
+ */
7
+ export interface NativeFathomProviderProps {
8
+ /**
9
+ * Your Fathom Analytics site ID
10
+ */
11
+ siteId: string;
12
+ /**
13
+ * Options passed to fathom.load() in the WebView
14
+ */
15
+ loadOptions?: LoadOptions;
16
+ /**
17
+ * Custom domain for Fathom script (if using Fathom's custom domains feature)
18
+ * @default 'cdn.usefathom.com'
19
+ */
20
+ scriptDomain?: string;
21
+ /**
22
+ * Default options merged into all trackPageview calls
23
+ */
24
+ defaultPageviewOptions?: PageViewOptions;
25
+ /**
26
+ * Default options merged into all trackEvent calls
27
+ */
28
+ defaultEventOptions?: EventOptions;
29
+ /**
30
+ * Enable automatic app state tracking (foreground/background)
31
+ * Tracks 'app-foreground' and 'app-background' events
32
+ * @default false
33
+ */
34
+ trackAppState?: boolean;
35
+ /**
36
+ * Enable debug logging
37
+ * @default false
38
+ */
39
+ debug?: boolean;
40
+ /**
41
+ * Called when the Fathom script has loaded and is ready
42
+ */
43
+ onReady?: () => void;
44
+ /**
45
+ * Called when an error occurs loading the script
46
+ */
47
+ onError?: (error: string) => void;
48
+ /**
49
+ * A ref that will be populated with the WebView-based Fathom client instance.
50
+ * This allows the parent component that composes the provider to access
51
+ * the client directly, since it cannot use useFathom() (context only flows
52
+ * downward to children).
53
+ *
54
+ * The client is a WebViewFathomClient which extends FathomClient with
55
+ * additional methods for queue management.
56
+ *
57
+ * @example
58
+ * ```tsx
59
+ * import { NativeFathomProvider, WebViewFathomClient } from 'react-fathom/native'
60
+ *
61
+ * function App() {
62
+ * const clientRef = useRef<WebViewFathomClient>(null);
63
+ *
64
+ * const handleDeepLink = (url: string) => {
65
+ * clientRef.current?.trackEvent('deep_link', { _url: url });
66
+ * };
67
+ *
68
+ * return (
69
+ * <NativeFathomProvider siteId="..." clientRef={clientRef}>
70
+ * <YourApp />
71
+ * </NativeFathomProvider>
72
+ * );
73
+ * }
74
+ * ```
75
+ */
76
+ clientRef?: MutableRefObject<WebViewFathomClient | null>;
77
+ /**
78
+ * Children to render
79
+ */
80
+ children: React.ReactNode;
81
+ }
82
+ /**
83
+ * Options for the useNavigationTracking hook
84
+ */
85
+ export interface UseNavigationTrackingOptions {
86
+ /**
87
+ * React Navigation navigation container ref
88
+ */
89
+ navigationRef: React.RefObject<any>;
90
+ /**
91
+ * Transform the route name before tracking (e.g., add prefixes)
92
+ */
93
+ transformRouteName?: (routeName: string) => string;
94
+ /**
95
+ * Filter which routes should be tracked (return false to skip)
96
+ */
97
+ shouldTrackRoute?: (routeName: string, params?: Record<string, any>) => boolean;
98
+ /**
99
+ * Include route params in the tracked URL
100
+ */
101
+ includeParams?: boolean;
102
+ }
103
+ /**
104
+ * Options for the useAppStateTracking hook
105
+ */
106
+ export interface UseAppStateTrackingOptions {
107
+ /**
108
+ * Event name for when the app comes to foreground (default: 'app-foreground')
109
+ */
110
+ foregroundEventName?: string;
111
+ /**
112
+ * Event name for when the app goes to background (default: 'app-background')
113
+ */
114
+ backgroundEventName?: string;
115
+ /**
116
+ * Additional event options to include with app state events
117
+ */
118
+ eventOptions?: EventOptions;
119
+ /**
120
+ * Callback when app state changes
121
+ */
122
+ onStateChange?: (state: 'active' | 'background' | 'inactive') => void;
123
+ }
124
+ export type { FathomClient, EventOptions, LoadOptions, PageViewOptions };
125
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/native/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AACxF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAEhE;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,WAAW,CAAC,EAAE,WAAW,CAAA;IAEzB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,sBAAsB,CAAC,EAAE,eAAe,CAAA;IAExC;;OAEG;IACH,mBAAmB,CAAC,EAAE,YAAY,CAAA;IAElC;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IAEvB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IAEf;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IAEpB;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAEjC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAA;IAExD;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,aAAa,EAAE,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;IAEnC;;OAEG;IACH,kBAAkB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;IAElD;;OAEG;IACH,gBAAgB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,CAAA;IAE/E;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAE5B;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAE5B;;OAEG;IACH,YAAY,CAAC,EAAE,YAAY,CAAA;IAE3B;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,GAAG,YAAY,GAAG,UAAU,KAAK,IAAI,CAAA;CACtE;AAGD,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,CAAA"}
@@ -0,0 +1,25 @@
1
+ import type { UseAppStateTrackingOptions } from './types';
2
+ /**
3
+ * Hook that tracks app state changes (foreground/background) as Fathom events.
4
+ *
5
+ * This is useful for understanding user engagement patterns and session behavior.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * import { useAppStateTracking } from 'react-fathom/native'
10
+ *
11
+ * function App() {
12
+ * useAppStateTracking({
13
+ * foregroundEventName: 'app-resumed',
14
+ * backgroundEventName: 'app-paused',
15
+ * onStateChange: (state) => {
16
+ * console.log('App state:', state)
17
+ * },
18
+ * })
19
+ *
20
+ * return <YourApp />
21
+ * }
22
+ * ```
23
+ */
24
+ export declare function useAppStateTracking(options?: UseAppStateTrackingOptions): void;
25
+ //# sourceMappingURL=useAppStateTracking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAppStateTracking.d.ts","sourceRoot":"","sources":["../../src/native/useAppStateTracking.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAEzD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,0BAA+B,QAqC3E"}
@@ -0,0 +1,30 @@
1
+ import type { UseNavigationTrackingOptions } from './types';
2
+ /**
3
+ * Hook that tracks screen navigation as pageviews using React Navigation.
4
+ *
5
+ * This integrates with React Navigation's navigation container to automatically
6
+ * track screen changes as Fathom pageviews.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * import { NavigationContainer } from '@react-navigation/native'
11
+ * import { useNavigationTracking } from 'react-fathom/native'
12
+ *
13
+ * function App() {
14
+ * const navigationRef = useNavigationContainerRef()
15
+ *
16
+ * useNavigationTracking({
17
+ * navigationRef,
18
+ * transformRouteName: (name) => `/screens/${name}`,
19
+ * })
20
+ *
21
+ * return (
22
+ * <NavigationContainer ref={navigationRef}>
23
+ * <Navigator />
24
+ * </NavigationContainer>
25
+ * )
26
+ * }
27
+ * ```
28
+ */
29
+ export declare function useNavigationTracking(options: UseNavigationTrackingOptions): void;
30
+ //# sourceMappingURL=useNavigationTracking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNavigationTracking.d.ts","sourceRoot":"","sources":["../../src/native/useNavigationTracking.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAA;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,4BAA4B,QAgJ1E"}
package/types/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type { PropsWithChildren } from 'react';
1
+ import type { MutableRefObject, PropsWithChildren } from 'react';
2
2
  import type { EventOptions, LoadOptions, PageViewOptions } from 'fathom-client';
3
+ export type { EventOptions, LoadOptions, PageViewOptions };
3
4
  export interface FathomClient {
4
5
  blockTrackingForMe: () => void;
5
6
  enableTrackingForMe: () => void;
@@ -11,20 +12,44 @@ export interface FathomClient {
11
12
  isTrackingEnabled: () => boolean;
12
13
  }
13
14
  export interface FathomContextInterface {
14
- blockTrackingForMe?: () => void;
15
- enableTrackingForMe?: () => void;
16
- isTrackingEnabled?: () => boolean;
17
- load?: (siteId: string, options?: LoadOptions) => void;
18
- setSite?: (siteId: string) => void;
19
- trackPageview?: (options?: PageViewOptions) => void;
20
- trackEvent?: (eventName: string, options?: EventOptions) => void;
21
- trackGoal?: (code: string, cents: number) => void;
15
+ blockTrackingForMe: () => void;
16
+ enableTrackingForMe: () => void;
17
+ isTrackingEnabled: () => boolean;
18
+ load: (siteId: string, options?: LoadOptions) => void;
19
+ setSite: (siteId: string) => void;
20
+ trackPageview: (options?: PageViewOptions) => void;
21
+ trackEvent: (eventName: string, options?: EventOptions) => void;
22
+ trackGoal: (code: string, cents: number) => void;
22
23
  client?: FathomClient;
23
24
  defaultPageviewOptions?: PageViewOptions;
24
25
  defaultEventOptions?: EventOptions;
25
26
  }
26
27
  export interface FathomProviderProps extends PropsWithChildren {
27
28
  client?: FathomClient;
29
+ /**
30
+ * A ref that will be populated with the resolved Fathom client instance.
31
+ * This allows the parent component that composes the provider to access
32
+ * the client directly, since it cannot use useFathom() (context only flows
33
+ * downward to children).
34
+ *
35
+ * @example
36
+ * ```tsx
37
+ * function App() {
38
+ * const clientRef = useRef<FathomClient>(null);
39
+ *
40
+ * const handleDeepLink = (url: string) => {
41
+ * clientRef.current?.trackEvent('deep_link', { _url: url });
42
+ * };
43
+ *
44
+ * return (
45
+ * <FathomProvider siteId="..." clientRef={clientRef}>
46
+ * <YourApp />
47
+ * </FathomProvider>
48
+ * );
49
+ * }
50
+ * ```
51
+ */
52
+ clientRef?: MutableRefObject<FathomClient | null>;
28
53
  clientOptions?: LoadOptions;
29
54
  siteId?: string;
30
55
  defaultPageviewOptions?: PageViewOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAE9C,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAE/E,MAAM,WAAW,YAAY;IAC3B,kBAAkB,EAAE,MAAM,IAAI,CAAA;IAC9B,mBAAmB,EAAE,MAAM,IAAI,CAAA;IAC/B,aAAa,EAAE,CAAC,IAAI,CAAC,EAAE,eAAe,KAAK,IAAI,CAAA;IAC/C,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAChD,UAAU,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY,KAAK,IAAI,CAAA;IAC5D,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7B,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,IAAI,CAAA;IACrD,iBAAiB,EAAE,MAAM,OAAO,CAAA;CACjC;AAED,MAAM,WAAW,sBAAsB;IACrC,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAA;IAC/B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