react-fathom 0.1.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.
- package/LICENSE +21 -0
- package/README.md +199 -0
- package/dist/cjs/index.cjs +410 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/next/index.cjs +910 -0
- package/dist/cjs/next/index.cjs.map +1 -0
- package/dist/es/index.js +381 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/next/index.js +885 -0
- package/dist/es/next/index.js.map +1 -0
- package/dist/react-fathom.js +413 -0
- package/dist/react-fathom.js.map +1 -0
- package/dist/react-fathom.min.js +3 -0
- package/dist/react-fathom.min.js.map +1 -0
- package/package.json +127 -0
- package/src/FathomContext.tsx +5 -0
- package/src/FathomProvider.test.tsx +532 -0
- package/src/FathomProvider.tsx +122 -0
- package/src/components/TrackClick.test.tsx +191 -0
- package/src/components/TrackClick.tsx +62 -0
- package/src/components/TrackPageview.test.tsx +111 -0
- package/src/components/TrackPageview.tsx +36 -0
- package/src/components/TrackVisible.test.tsx +311 -0
- package/src/components/TrackVisible.tsx +105 -0
- package/src/components/index.ts +3 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useFathom.test.tsx +51 -0
- package/src/hooks/useFathom.ts +11 -0
- package/src/hooks/useTrackOnClick.test.tsx +197 -0
- package/src/hooks/useTrackOnClick.ts +65 -0
- package/src/hooks/useTrackOnMount.test.tsx +79 -0
- package/src/hooks/useTrackOnMount.ts +24 -0
- package/src/hooks/useTrackOnVisible.test.tsx +313 -0
- package/src/hooks/useTrackOnVisible.ts +99 -0
- package/src/index.ts +4 -0
- package/src/next/NextFathomProvider.test.tsx +131 -0
- package/src/next/NextFathomProvider.tsx +62 -0
- package/src/next/NextFathomProviderApp.test.tsx +308 -0
- package/src/next/NextFathomProviderApp.tsx +106 -0
- package/src/next/NextFathomProviderPages.test.tsx +330 -0
- package/src/next/NextFathomProviderPages.tsx +112 -0
- package/src/next/compositions/withAppRouter.test.tsx +113 -0
- package/src/next/compositions/withAppRouter.tsx +48 -0
- package/src/next/compositions/withPagesRouter.test.tsx +113 -0
- package/src/next/compositions/withPagesRouter.tsx +44 -0
- package/src/next/index.ts +7 -0
- package/src/next/types.ts +19 -0
- package/src/types.ts +37 -0
- package/types/FathomContext.d.ts +3 -0
- package/types/FathomContext.d.ts.map +1 -0
- package/types/FathomProvider.d.ts +5 -0
- package/types/FathomProvider.d.ts.map +1 -0
- package/types/components/TrackClick.d.ts +39 -0
- package/types/components/TrackClick.d.ts.map +1 -0
- package/types/components/TrackPageview.d.ts +21 -0
- package/types/components/TrackPageview.d.ts.map +1 -0
- package/types/components/TrackVisible.d.ts +39 -0
- package/types/components/TrackVisible.d.ts.map +1 -0
- package/types/components/index.d.ts +4 -0
- package/types/components/index.d.ts.map +1 -0
- package/types/hooks/index.d.ts +5 -0
- package/types/hooks/index.d.ts.map +1 -0
- package/types/hooks/useFathom.d.ts +6 -0
- package/types/hooks/useFathom.d.ts.map +1 -0
- package/types/hooks/useTrackOnClick.d.ts +39 -0
- package/types/hooks/useTrackOnClick.d.ts.map +1 -0
- package/types/hooks/useTrackOnMount.d.ts +14 -0
- package/types/hooks/useTrackOnMount.d.ts.map +1 -0
- package/types/hooks/useTrackOnVisible.d.ts +43 -0
- package/types/hooks/useTrackOnVisible.d.ts.map +1 -0
- package/types/index.d.ts +5 -0
- package/types/index.d.ts.map +1 -0
- package/types/next/AppRouterProvider.d.ts +7 -0
- package/types/next/AppRouterProvider.d.ts.map +1 -0
- package/types/next/NextFathomProvider.d.ts +34 -0
- package/types/next/NextFathomProvider.d.ts.map +1 -0
- package/types/next/NextFathomProviderApp.d.ts +6 -0
- package/types/next/NextFathomProviderApp.d.ts.map +1 -0
- package/types/next/NextFathomProviderPages.d.ts +6 -0
- package/types/next/NextFathomProviderPages.d.ts.map +1 -0
- package/types/next/PagesRouterProvider.d.ts +7 -0
- package/types/next/PagesRouterProvider.d.ts.map +1 -0
- package/types/next/compositions/withAppRouter.d.ts +29 -0
- package/types/next/compositions/withAppRouter.d.ts.map +1 -0
- package/types/next/compositions/withPagesRouter.d.ts +25 -0
- package/types/next/compositions/withPagesRouter.d.ts.map +1 -0
- package/types/next/index.d.ts +6 -0
- package/types/next/index.d.ts.map +1 -0
- package/types/next/types.d.ts +16 -0
- package/types/next/types.d.ts.map +1 -0
- package/types/test-setup.d.ts +2 -0
- package/types/test-setup.d.ts.map +1 -0
- package/types/types.d.ts +34 -0
- package/types/types.d.ts.map +1 -0
- package/types/useFathom.d.ts +7 -0
- package/types/useFathom.d.ts.map +1 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
4
|
+
|
|
5
|
+
import { render, screen } from '@testing-library/react'
|
|
6
|
+
|
|
7
|
+
import { withPagesRouter } from './withPagesRouter'
|
|
8
|
+
|
|
9
|
+
// Mock NextFathomProviderPages
|
|
10
|
+
vi.mock('../NextFathomProviderPages', () => ({
|
|
11
|
+
default: ({
|
|
12
|
+
children,
|
|
13
|
+
siteId,
|
|
14
|
+
}: {
|
|
15
|
+
children: React.ReactNode
|
|
16
|
+
siteId?: string
|
|
17
|
+
}) => (
|
|
18
|
+
<div data-testid="pages-provider" data-site-id={siteId}>
|
|
19
|
+
{children}
|
|
20
|
+
</div>
|
|
21
|
+
),
|
|
22
|
+
}))
|
|
23
|
+
|
|
24
|
+
describe('withPagesRouter', () => {
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
vi.clearAllMocks()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('should wrap component with NextFathomProviderPages', () => {
|
|
30
|
+
const TestComponent = ({ name }: { name: string }) => (
|
|
31
|
+
<div>Hello {name}</div>
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
const WrappedComponent = withPagesRouter(TestComponent, {
|
|
35
|
+
siteId: 'TEST_SITE_ID',
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
render(<WrappedComponent name="World" />)
|
|
39
|
+
|
|
40
|
+
expect(screen.getByTestId('pages-provider')).toBeInTheDocument()
|
|
41
|
+
expect(screen.getByTestId('pages-provider')).toHaveAttribute(
|
|
42
|
+
'data-site-id',
|
|
43
|
+
'TEST_SITE_ID',
|
|
44
|
+
)
|
|
45
|
+
expect(screen.getByText('Hello World')).toBeInTheDocument()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('should pass props to wrapped component', () => {
|
|
49
|
+
const TestComponent = ({ count }: { count: number }) => (
|
|
50
|
+
<div>Count: {count}</div>
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
const WrappedComponent = withPagesRouter(TestComponent)
|
|
54
|
+
|
|
55
|
+
render(<WrappedComponent count={42} />)
|
|
56
|
+
|
|
57
|
+
expect(screen.getByText('Count: 42')).toBeInTheDocument()
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('should pass provider props to NextFathomProviderPages', () => {
|
|
61
|
+
const TestComponent = () => <div>Test</div>
|
|
62
|
+
|
|
63
|
+
const WrappedComponent = withPagesRouter(TestComponent, {
|
|
64
|
+
siteId: 'TEST_SITE_ID',
|
|
65
|
+
disableAutoTrack: true,
|
|
66
|
+
clientOptions: { honorDNT: true },
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
render(<WrappedComponent />)
|
|
70
|
+
|
|
71
|
+
expect(screen.getByTestId('pages-provider')).toBeInTheDocument()
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('should work without provider props', () => {
|
|
75
|
+
const TestComponent = () => <div>Test</div>
|
|
76
|
+
|
|
77
|
+
const WrappedComponent = withPagesRouter(TestComponent)
|
|
78
|
+
|
|
79
|
+
render(<WrappedComponent />)
|
|
80
|
+
|
|
81
|
+
expect(screen.getByTestId('pages-provider')).toBeInTheDocument()
|
|
82
|
+
expect(screen.getByText('Test')).toBeInTheDocument()
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('should set displayName correctly', () => {
|
|
86
|
+
const TestComponent = () => <div>Test</div>
|
|
87
|
+
TestComponent.displayName = 'TestComponent'
|
|
88
|
+
|
|
89
|
+
const WrappedComponent = withPagesRouter(TestComponent)
|
|
90
|
+
|
|
91
|
+
expect(WrappedComponent.displayName).toBe('withPagesRouter(TestComponent)')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('should set displayName with component name when displayName is not set', () => {
|
|
95
|
+
function TestComponent() {
|
|
96
|
+
return <div>Test</div>
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const WrappedComponent = withPagesRouter(TestComponent)
|
|
100
|
+
|
|
101
|
+
expect(WrappedComponent.displayName).toBe('withPagesRouter(TestComponent)')
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('should set displayName with Component fallback', () => {
|
|
105
|
+
const TestComponent = () => <div>Test</div>
|
|
106
|
+
// Remove displayName and name
|
|
107
|
+
Object.defineProperty(TestComponent, 'name', { value: '' })
|
|
108
|
+
|
|
109
|
+
const WrappedComponent = withPagesRouter(TestComponent)
|
|
110
|
+
|
|
111
|
+
expect(WrappedComponent.displayName).toBe('withPagesRouter(Component)')
|
|
112
|
+
})
|
|
113
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import type { ComponentType } from 'react'
|
|
3
|
+
|
|
4
|
+
import NextFathomProviderPages from '../NextFathomProviderPages'
|
|
5
|
+
import type { NextFathomProviderProps } from '../types'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Higher-order component that wraps your Next.js Pages Router app with FathomProvider
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* // pages/_app.tsx
|
|
13
|
+
* import { withPagesRouter } from 'react-fathom/next'
|
|
14
|
+
*
|
|
15
|
+
* function MyApp({ Component, pageProps }) {
|
|
16
|
+
* return <Component {...pageProps} />
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* export default withPagesRouter(MyApp, {
|
|
20
|
+
* siteId: 'YOUR_SITE_ID',
|
|
21
|
+
* clientOptions: {
|
|
22
|
+
* spa: 'auto',
|
|
23
|
+
* },
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
const withPagesRouter = <P extends object>(
|
|
28
|
+
Component: ComponentType<P>,
|
|
29
|
+
providerProps?: NextFathomProviderProps,
|
|
30
|
+
): ComponentType<P> => {
|
|
31
|
+
const WithPagesRouter: React.FC<P> = (props) => {
|
|
32
|
+
return (
|
|
33
|
+
<NextFathomProviderPages {...providerProps}>
|
|
34
|
+
<Component {...props} />
|
|
35
|
+
</NextFathomProviderPages>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
WithPagesRouter.displayName = `withPagesRouter(${Component.displayName || Component.name || 'Component'})`
|
|
40
|
+
|
|
41
|
+
return WithPagesRouter
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { withPagesRouter }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PropsWithChildren } from 'react'
|
|
2
|
+
|
|
3
|
+
import type { PageViewOptions } from 'fathom-client'
|
|
4
|
+
|
|
5
|
+
import type { FathomProviderProps } from '../types'
|
|
6
|
+
|
|
7
|
+
export interface NextFathomProviderProps
|
|
8
|
+
extends PropsWithChildren, Omit<FathomProviderProps, 'disableDefaultTrack'> {
|
|
9
|
+
/**
|
|
10
|
+
* Disable automatic pageview tracking on route changes
|
|
11
|
+
* @default false
|
|
12
|
+
*/
|
|
13
|
+
disableAutoTrack?: boolean
|
|
14
|
+
/**
|
|
15
|
+
* Default options to pass to trackPageview on route changes
|
|
16
|
+
* @deprecated Use `defaultPageviewOptions` instead
|
|
17
|
+
*/
|
|
18
|
+
trackDefaultOptions?: PageViewOptions
|
|
19
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { PropsWithChildren } from 'react'
|
|
2
|
+
|
|
3
|
+
import type { EventOptions, LoadOptions, PageViewOptions } from 'fathom-client'
|
|
4
|
+
|
|
5
|
+
export interface FathomClient {
|
|
6
|
+
blockTrackingForMe: () => void
|
|
7
|
+
enableTrackingForMe: () => void
|
|
8
|
+
trackPageview: (opts?: PageViewOptions) => void
|
|
9
|
+
trackGoal: (code: string, cents: number) => void
|
|
10
|
+
trackEvent: (eventName: string, opts?: EventOptions) => void
|
|
11
|
+
setSite: (id: string) => void
|
|
12
|
+
load: (siteId: string, options?: LoadOptions) => void
|
|
13
|
+
isTrackingEnabled: () => boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface FathomContextInterface {
|
|
17
|
+
blockTrackingForMe?: () => void
|
|
18
|
+
enableTrackingForMe?: () => void
|
|
19
|
+
isTrackingEnabled?: () => boolean
|
|
20
|
+
load?: (siteId: string, options?: LoadOptions) => void
|
|
21
|
+
setSite?: (siteId: string) => void
|
|
22
|
+
trackPageview?: (options?: PageViewOptions) => void
|
|
23
|
+
trackEvent?: (eventName: string, options?: EventOptions) => void
|
|
24
|
+
trackGoal?: (code: string, cents: number) => void
|
|
25
|
+
client?: FathomClient
|
|
26
|
+
defaultPageviewOptions?: PageViewOptions
|
|
27
|
+
defaultEventOptions?: EventOptions
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface FathomProviderProps extends PropsWithChildren {
|
|
31
|
+
client?: FathomClient
|
|
32
|
+
clientOptions?: LoadOptions
|
|
33
|
+
siteId?: string
|
|
34
|
+
disableDefaultTrack?: boolean
|
|
35
|
+
defaultPageviewOptions?: PageViewOptions
|
|
36
|
+
defaultEventOptions?: EventOptions
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FathomContext.d.ts","sourceRoot":"","sources":["../src/FathomContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAErD,eAAO,MAAM,aAAa,0DAAqD,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FathomProvider.d.ts","sourceRoot":"","sources":["../src/FathomProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsD,MAAM,OAAO,CAAA;AAM1E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAElD,QAAA,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CA6GjD,CAAA;AAID,OAAO,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ElementType, MouseEvent, ReactNode } from 'react';
|
|
3
|
+
import type { EventOptions } from 'fathom-client';
|
|
4
|
+
export interface TrackClickProps extends EventOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Event name to track
|
|
7
|
+
*/
|
|
8
|
+
eventName: string;
|
|
9
|
+
/**
|
|
10
|
+
* Child element(s) to wrap
|
|
11
|
+
*/
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* Whether to prevent default behavior
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
preventDefault?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Custom onClick handler (will be called before tracking)
|
|
20
|
+
*/
|
|
21
|
+
onClick?: (e: MouseEvent) => void;
|
|
22
|
+
/**
|
|
23
|
+
* HTML element to render as wrapper
|
|
24
|
+
* @default 'div'
|
|
25
|
+
*/
|
|
26
|
+
as?: ElementType;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Component wrapper that automatically tracks clicks on its children
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* <TrackClick eventName="cta-clicked" id="hero-cta">
|
|
34
|
+
* <button>Get Started</button>
|
|
35
|
+
* </TrackClick>
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare const TrackClick: React.FC<TrackClickProps>;
|
|
39
|
+
//# sourceMappingURL=TrackClick.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TrackClick.d.ts","sourceRoot":"","sources":["../../src/components/TrackClick.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAE/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAIjD,MAAM,WAAW,eAAgB,SAAQ,YAAY;IACnD;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAA;IACnB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,CAAA;IACjC;;;OAGG;IACH,EAAE,CAAC,EAAE,WAAW,CAAA;CACjB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAmBhD,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import type { PageViewOptions } from 'fathom-client';
|
|
4
|
+
export interface TrackPageviewProps extends PageViewOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Child element(s) to render
|
|
7
|
+
*/
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Component that tracks a pageview when it mounts
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* <TrackPageview url="/custom-page">
|
|
16
|
+
* <div>Page content</div>
|
|
17
|
+
* </TrackPageview>
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const TrackPageview: React.FC<TrackPageviewProps>;
|
|
21
|
+
//# sourceMappingURL=TrackPageview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TrackPageview.d.ts","sourceRoot":"","sources":["../../src/components/TrackPageview.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAA;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAIpD,MAAM,WAAW,kBAAmB,SAAQ,eAAe;IACzD;;OAEG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAWtD,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ElementType, ReactNode } from 'react';
|
|
3
|
+
import type { EventOptions } from 'fathom-client';
|
|
4
|
+
export interface TrackVisibleProps extends EventOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Event name to track
|
|
7
|
+
*/
|
|
8
|
+
eventName: string;
|
|
9
|
+
/**
|
|
10
|
+
* Child element(s) to render
|
|
11
|
+
*/
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* Intersection observer options
|
|
15
|
+
*/
|
|
16
|
+
observerOptions?: IntersectionObserverInit;
|
|
17
|
+
/**
|
|
18
|
+
* Whether to track only once or every time it becomes visible
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
trackOnce?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* HTML element to render as wrapper
|
|
24
|
+
* @default 'div'
|
|
25
|
+
*/
|
|
26
|
+
as?: ElementType;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Component that tracks an event when it becomes visible in the viewport
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* <TrackVisible eventName="section-viewed" section="hero">
|
|
34
|
+
* <HeroSection />
|
|
35
|
+
* </TrackVisible>
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare const TrackVisible: React.ForwardRefExoticComponent<TrackVisibleProps & React.RefAttributes<HTMLDivElement>>;
|
|
39
|
+
//# sourceMappingURL=TrackVisible.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TrackVisible.d.ts","sourceRoot":"","sources":["../../src/components/TrackVisible.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqD,MAAM,OAAO,CAAA;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAIjD,MAAM,WAAW,iBAAkB,SAAQ,YAAY;IACrD;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB;;OAEG;IACH,eAAe,CAAC,EAAE,wBAAwB,CAAA;IAC1C;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;;OAGG;IACH,EAAE,CAAC,EAAE,WAAW,CAAA;CACjB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,0FA8DxB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFathom.d.ts","sourceRoot":"","sources":["../../src/hooks/useFathom.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA;AAEtD,eAAO,MAAM,SAAS;QAAO,sBAAsB;;CAGlD,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { MouseEvent } from 'react';
|
|
2
|
+
import type { EventOptions } from 'fathom-client';
|
|
3
|
+
export interface UseTrackOnClickOptions extends EventOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Event name to track
|
|
6
|
+
*/
|
|
7
|
+
eventName: string;
|
|
8
|
+
/**
|
|
9
|
+
* Whether to prevent default behavior
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
preventDefault?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Optional callback function to run after tracking
|
|
15
|
+
* Receives the click event as a parameter
|
|
16
|
+
*/
|
|
17
|
+
callback?: (e?: MouseEvent) => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Hook that returns a click handler function that tracks an event
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```tsx
|
|
24
|
+
* function Button() {
|
|
25
|
+
* const handleClick = useTrackOnClick({
|
|
26
|
+
* eventName: 'button-click',
|
|
27
|
+
* id: 'signup-button',
|
|
28
|
+
* callback: (e) => {
|
|
29
|
+
* console.log('Button clicked!')
|
|
30
|
+
* // Your custom logic here
|
|
31
|
+
* },
|
|
32
|
+
* })
|
|
33
|
+
*
|
|
34
|
+
* return <button onClick={handleClick}>Sign Up</button>
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare const useTrackOnClick: (options: UseTrackOnClickOptions) => ((e?: MouseEvent) => void);
|
|
39
|
+
//# sourceMappingURL=useTrackOnClick.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTrackOnClick.d.ts","sourceRoot":"","sources":["../../src/hooks/useTrackOnClick.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAEvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAIjD,MAAM,WAAW,sBAAuB,SAAQ,YAAY;IAC1D;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,CAAA;CACpC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,eAAe,GAC1B,SAAS,sBAAsB,KAC9B,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,CAmB3B,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PageViewOptions } from 'fathom-client';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to track a pageview when a component mounts
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* function MyComponent() {
|
|
8
|
+
* useTrackOnMount({ url: '/custom-page' })
|
|
9
|
+
* return <div>Content</div>
|
|
10
|
+
* }
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare const useTrackOnMount: (options?: PageViewOptions) => void;
|
|
14
|
+
//# sourceMappingURL=useTrackOnMount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTrackOnMount.d.ts","sourceRoot":"","sources":["../../src/hooks/useTrackOnMount.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAIpD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,GAAI,UAAU,eAAe,SAMxD,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
import type { EventOptions } from 'fathom-client';
|
|
3
|
+
export interface UseTrackOnVisibleOptions extends EventOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Event name to track
|
|
6
|
+
*/
|
|
7
|
+
eventName: string;
|
|
8
|
+
/**
|
|
9
|
+
* Intersection observer options
|
|
10
|
+
*/
|
|
11
|
+
observerOptions?: IntersectionObserverInit;
|
|
12
|
+
/**
|
|
13
|
+
* Whether to track only once or every time it becomes visible
|
|
14
|
+
* @default true
|
|
15
|
+
*/
|
|
16
|
+
trackOnce?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Optional callback function to run after tracking
|
|
19
|
+
* Receives the intersection observer entry as a parameter
|
|
20
|
+
*/
|
|
21
|
+
callback?: (entry: IntersectionObserverEntry) => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Hook to track an event when an element becomes visible (using Intersection Observer)
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* function Section() {
|
|
29
|
+
* const ref = useTrackOnVisible({
|
|
30
|
+
* eventName: 'section-viewed',
|
|
31
|
+
* section: 'hero',
|
|
32
|
+
* callback: (entry) => {
|
|
33
|
+
* console.log('Section is visible!', entry.isIntersecting)
|
|
34
|
+
* // Your custom logic here
|
|
35
|
+
* },
|
|
36
|
+
* })
|
|
37
|
+
*
|
|
38
|
+
* return <section ref={ref}>Content</section>
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare const useTrackOnVisible: (options: UseTrackOnVisibleOptions) => RefObject<HTMLElement | null>;
|
|
43
|
+
//# sourceMappingURL=useTrackOnVisible.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTrackOnVisible.d.ts","sourceRoot":"","sources":["../../src/hooks/useTrackOnVisible.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAIjD,MAAM,WAAW,wBAAyB,SAAQ,YAAY;IAC5D;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,eAAe,CAAC,EAAE,wBAAwB,CAAA;IAC1C;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,yBAAyB,KAAK,IAAI,CAAA;CACtD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,iBAAiB,GAC5B,SAAS,wBAAwB,KAChC,SAAS,CAAC,WAAW,GAAG,IAAI,CAiD9B,CAAA"}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppRouterProvider.d.ts","sourceRoot":"","sources":["../../src/next/AppRouterProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAA;AAK7D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEtD,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CAqExD,CAAA;AAID,OAAO,EAAE,iBAAiB,EAAE,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { NextFathomProviderProps } from './types';
|
|
3
|
+
export interface NextFathomProviderComponentProps extends NextFathomProviderProps {
|
|
4
|
+
/**
|
|
5
|
+
* Router type to use
|
|
6
|
+
* @default 'app'
|
|
7
|
+
*/
|
|
8
|
+
router?: 'pages' | 'app';
|
|
9
|
+
/**
|
|
10
|
+
* Fallback component to show while loading the router provider
|
|
11
|
+
* @default null
|
|
12
|
+
*/
|
|
13
|
+
fallback?: React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Unified provider component that conditionally renders the appropriate
|
|
17
|
+
* Next.js router provider based on the `router` prop.
|
|
18
|
+
* Providers are dynamically loaded to avoid bundling both router types.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* // App Router (default)
|
|
23
|
+
* <NextFathomProvider siteId="YOUR_SITE_ID" router="app">
|
|
24
|
+
* <App>{children}</App>
|
|
25
|
+
* </NextFathomProvider>
|
|
26
|
+
*
|
|
27
|
+
* // Pages Router
|
|
28
|
+
* <NextFathomProvider siteId="YOUR_SITE_ID" router="pages">
|
|
29
|
+
* <App>{children}</App>
|
|
30
|
+
* </NextFathomProvider>
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare const NextFathomProvider: React.FC<NextFathomProviderComponentProps>;
|
|
34
|
+
//# sourceMappingURL=NextFathomProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NextFathomProvider.d.ts","sourceRoot":"","sources":["../../src/next/NextFathomProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkC,MAAM,OAAO,CAAA;AAEtD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEtD,MAAM,WAAW,gCAAiC,SAAQ,uBAAuB;IAC/E;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,KAAK,CAAA;IACxB;;;OAGG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B;AAUD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,gCAAgC,CAgBzE,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { NextFathomProviderProps } from './types';
|
|
3
|
+
declare const NextFathomProviderApp: React.FC<NextFathomProviderProps>;
|
|
4
|
+
export default NextFathomProviderApp;
|
|
5
|
+
export { NextFathomProviderApp };
|
|
6
|
+
//# sourceMappingURL=NextFathomProviderApp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NextFathomProviderApp.d.ts","sourceRoot":"","sources":["../../src/next/NextFathomProviderApp.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkD,MAAM,OAAO,CAAA;AAOtE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAGtD,QAAA,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CA0F5D,CAAA;AAID,eAAe,qBAAqB,CAAA;AACpC,OAAO,EAAE,qBAAqB,EAAE,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { NextFathomProviderProps } from './types';
|
|
3
|
+
declare const NextFathomProviderPages: React.FC<NextFathomProviderProps>;
|
|
4
|
+
export default NextFathomProviderPages;
|
|
5
|
+
export { NextFathomProviderPages };
|
|
6
|
+
//# sourceMappingURL=NextFathomProviderPages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NextFathomProviderPages.d.ts","sourceRoot":"","sources":["../../src/next/NextFathomProviderPages.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkD,MAAM,OAAO,CAAA;AAOtE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAGtD,QAAA,MAAM,uBAAuB,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CAgG9D,CAAA;AAID,eAAe,uBAAuB,CAAA;AACtC,OAAO,EAAE,uBAAuB,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PagesRouterProvider.d.ts","sourceRoot":"","sources":["../../src/next/PagesRouterProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAA;AAK7D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEtD,QAAA,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CAoF1D,CAAA;AAID,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
import type { NextFathomProviderProps } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Higher-order component that wraps your Next.js App Router app with FathomProvider
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* // app/layout.tsx
|
|
9
|
+
* import { withAppRouter } from 'react-fathom/next'
|
|
10
|
+
*
|
|
11
|
+
* function RootLayout({ children }) {
|
|
12
|
+
* return (
|
|
13
|
+
* <html>
|
|
14
|
+
* <body>{children}</body>
|
|
15
|
+
* </html>
|
|
16
|
+
* )
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* export default withAppRouter(RootLayout, {
|
|
20
|
+
* siteId: 'YOUR_SITE_ID',
|
|
21
|
+
* clientOptions: {
|
|
22
|
+
* spa: 'auto',
|
|
23
|
+
* },
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare const withAppRouter: <P extends object>(Component: ComponentType<P>, providerProps?: NextFathomProviderProps) => ComponentType<P>;
|
|
28
|
+
export { withAppRouter };
|
|
29
|
+
//# sourceMappingURL=withAppRouter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withAppRouter.d.ts","sourceRoot":"","sources":["../../../src/next/compositions/withAppRouter.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAG1C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,QAAA,MAAM,aAAa,GAAI,CAAC,SAAS,MAAM,EACrC,WAAW,aAAa,CAAC,CAAC,CAAC,EAC3B,gBAAgB,uBAAuB,KACtC,aAAa,CAAC,CAAC,CAYjB,CAAA;AAED,OAAO,EAAE,aAAa,EAAE,CAAA"}
|