@litemetrics/react 0.1.0 → 0.1.1
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/README.md +111 -0
- package/package.json +11 -3
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# @litemetrics/react
|
|
2
|
+
|
|
3
|
+
React bindings for Litemetrics analytics. Provider component and hooks for tracking pageviews and custom events.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @litemetrics/react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { LitemetricsProvider } from '@litemetrics/react';
|
|
15
|
+
|
|
16
|
+
function App() {
|
|
17
|
+
return (
|
|
18
|
+
<LitemetricsProvider
|
|
19
|
+
siteId="your-site-id"
|
|
20
|
+
endpoint="https://your-server.com/api/collect"
|
|
21
|
+
>
|
|
22
|
+
<YourApp />
|
|
23
|
+
</LitemetricsProvider>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Hooks
|
|
29
|
+
|
|
30
|
+
### `useTrackEvent`
|
|
31
|
+
|
|
32
|
+
Track custom events from any component:
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { useTrackEvent } from '@litemetrics/react';
|
|
36
|
+
|
|
37
|
+
function SignupButton() {
|
|
38
|
+
const track = useTrackEvent();
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<button onClick={() => track('Signup', { plan: 'pro' })}>
|
|
42
|
+
Sign Up
|
|
43
|
+
</button>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### `usePageView`
|
|
49
|
+
|
|
50
|
+
Manually trigger a pageview:
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
import { usePageView } from '@litemetrics/react';
|
|
54
|
+
|
|
55
|
+
function Page() {
|
|
56
|
+
usePageView(); // Tracks on mount
|
|
57
|
+
return <div>...</div>;
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### `useLitemetrics`
|
|
62
|
+
|
|
63
|
+
Access the full tracker instance:
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import { useLitemetrics } from '@litemetrics/react';
|
|
67
|
+
|
|
68
|
+
function UserProfile({ user }) {
|
|
69
|
+
const tracker = useLitemetrics();
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
tracker.identify(user.id, { name: user.name });
|
|
73
|
+
}, [user]);
|
|
74
|
+
|
|
75
|
+
return <div>...</div>;
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Next.js (App Router)
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
// app/providers.tsx
|
|
83
|
+
'use client';
|
|
84
|
+
import { LitemetricsProvider } from '@litemetrics/react';
|
|
85
|
+
|
|
86
|
+
export function Providers({ children }: { children: React.ReactNode }) {
|
|
87
|
+
return (
|
|
88
|
+
<LitemetricsProvider
|
|
89
|
+
siteId="your-site-id"
|
|
90
|
+
endpoint="https://your-server.com/api/collect"
|
|
91
|
+
>
|
|
92
|
+
{children}
|
|
93
|
+
</LitemetricsProvider>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// app/layout.tsx
|
|
98
|
+
import { Providers } from './providers';
|
|
99
|
+
|
|
100
|
+
export default function RootLayout({ children }) {
|
|
101
|
+
return (
|
|
102
|
+
<html><body>
|
|
103
|
+
<Providers>{children}</Providers>
|
|
104
|
+
</body></html>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@litemetrics/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "React bindings for Litemetrics analytics (hooks + provider)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Metehan Kurucu",
|
|
@@ -9,7 +9,13 @@
|
|
|
9
9
|
"url": "https://github.com/metehankurucu/litemetrics",
|
|
10
10
|
"directory": "packages/react"
|
|
11
11
|
},
|
|
12
|
-
"keywords": [
|
|
12
|
+
"keywords": [
|
|
13
|
+
"analytics",
|
|
14
|
+
"litemetrics",
|
|
15
|
+
"react",
|
|
16
|
+
"hooks",
|
|
17
|
+
"tracking"
|
|
18
|
+
],
|
|
13
19
|
"type": "module",
|
|
14
20
|
"main": "./dist/index.cjs",
|
|
15
21
|
"module": "./dist/index.js",
|
|
@@ -21,7 +27,9 @@
|
|
|
21
27
|
"require": "./dist/index.cjs"
|
|
22
28
|
}
|
|
23
29
|
},
|
|
24
|
-
"files": [
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
25
33
|
"publishConfig": {
|
|
26
34
|
"access": "public"
|
|
27
35
|
},
|