@journium/react 1.0.7 → 1.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/dist/context.d.ts.map +1 -1
- package/dist/index.cjs +268 -128
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +268 -128
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -3
- package/readme.md +30 -326
package/readme.md
CHANGED
|
@@ -4,78 +4,39 @@
|
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
[](https://www.typescriptlang.org/)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
The official Journium SDK for React. Track events, pageviews, and user interactions with built-in hooks and providers.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
---
|
|
10
10
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
### npm
|
|
14
|
-
```bash
|
|
15
|
-
npm install @journium/react
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
### pnpm
|
|
19
|
-
```bash
|
|
20
|
-
pnpm add @journium/react
|
|
21
|
-
```
|
|
11
|
+
## Getting Started
|
|
22
12
|
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
yarn add @journium/react
|
|
26
|
-
```
|
|
13
|
+
Learn how to use Journium in your React application:
|
|
27
14
|
|
|
28
|
-
|
|
15
|
+
- [Quick Start Guide](https://journium.app/docs/react)
|
|
16
|
+
- [Concepts](https://journium.app/docs/react/concepts)
|
|
17
|
+
- [SDK Reference](https://journium.app/docs/react/hooks)
|
|
29
18
|
|
|
30
|
-
###
|
|
31
|
-
|
|
19
|
+
### Prerequisites
|
|
20
|
+
- React 16.8.0 or later (see [React Version Compatibility](COMPATIBILITY.md))
|
|
21
|
+
- Node.js `>=18.17.0` or later
|
|
22
|
+
- An existing Journium application. [Create your account for free](https://dashboard.journium.app/sign-up?utm_source=github&utm_medium=journium_react).
|
|
32
23
|
|
|
33
|
-
|
|
34
|
-
```env
|
|
35
|
-
REACT_APP_JOURNIUM_PUBLISHABLE_KEY=your-actual-publishable-key-here
|
|
36
|
-
```
|
|
24
|
+
## Installation
|
|
37
25
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
VITE_JOURNIUM_PUBLISHABLE_KEY=your-actual-publishable-key-here
|
|
26
|
+
```bash
|
|
27
|
+
npm install @journium/react
|
|
41
28
|
```
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
Wrap your app with the `JourniumProvider` to enable analytics throughout your React application.
|
|
30
|
+
## Usage
|
|
45
31
|
|
|
46
|
-
```
|
|
47
|
-
import React from 'react';
|
|
32
|
+
```tsx
|
|
48
33
|
import { JourniumProvider } from '@journium/react';
|
|
49
|
-
import App from './App';
|
|
50
|
-
|
|
51
|
-
function Root() {
|
|
52
|
-
return (
|
|
53
|
-
<JourniumProvider
|
|
54
|
-
config={{
|
|
55
|
-
publishableKey: process.env.REACT_APP_JOURNIUM_PUBLISHABLE_KEY!
|
|
56
|
-
}}
|
|
57
|
-
>
|
|
58
|
-
<App />
|
|
59
|
-
</JourniumProvider>
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export default Root;
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
**Vite Example:**
|
|
67
|
-
```jsx
|
|
68
|
-
// main.tsx
|
|
69
|
-
import React from 'react';
|
|
70
|
-
import ReactDOM from 'react-dom/client';
|
|
71
|
-
import { JourniumProvider } from '@journium/react';
|
|
72
|
-
import App from './App';
|
|
73
34
|
|
|
74
35
|
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
75
36
|
<React.StrictMode>
|
|
76
37
|
<JourniumProvider
|
|
77
38
|
config={{
|
|
78
|
-
publishableKey:
|
|
39
|
+
publishableKey: "your-publishable-key"
|
|
79
40
|
}}
|
|
80
41
|
>
|
|
81
42
|
<App />
|
|
@@ -84,285 +45,28 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
|
84
45
|
);
|
|
85
46
|
```
|
|
86
47
|
|
|
87
|
-
|
|
88
|
-
```env
|
|
89
|
-
VITE_JOURNIUM_PUBLISHABLE_KEY=your-actual-publishable-key-here
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
**For Next.js applications, use the dedicated [`@journium/nextjs`](../journium-nextjs) package instead.**
|
|
93
|
-
|
|
94
|
-
### API Classes and Types
|
|
95
|
-
|
|
96
|
-
The main analytics class is `JourniumAnalytics`, available through the React hooks and context.
|
|
97
|
-
|
|
98
|
-
### Track a Custom Event
|
|
99
|
-
Use the `useTrackEvent` hook to track custom events from any component.
|
|
100
|
-
|
|
101
|
-
```jsx
|
|
102
|
-
import React from 'react';
|
|
103
|
-
import { useTrackEvent } from '@journium/react';
|
|
104
|
-
|
|
105
|
-
function SignupButton() {
|
|
106
|
-
const trackEvent = useTrackEvent();
|
|
107
|
-
|
|
108
|
-
const handleSignup = () => {
|
|
109
|
-
trackEvent('user_signup', {
|
|
110
|
-
method: 'email',
|
|
111
|
-
source: 'landing_page',
|
|
112
|
-
plan: 'free'
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
return <button onClick={handleSignup}>Sign Up</button>;
|
|
117
|
-
}
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
### Identify a User
|
|
121
|
-
Use the `useIdentify` hook to identify users when they log in or sign up.
|
|
122
|
-
|
|
123
|
-
```jsx
|
|
124
|
-
import React from 'react';
|
|
125
|
-
import { useIdentify } from '@journium/react';
|
|
126
|
-
|
|
127
|
-
function LoginForm() {
|
|
128
|
-
const identify = useIdentify();
|
|
129
|
-
|
|
130
|
-
const handleLogin = async (email, password) => {
|
|
131
|
-
const user = await loginUser(email, password);
|
|
132
|
-
|
|
133
|
-
identify(user.id, {
|
|
134
|
-
name: user.name,
|
|
135
|
-
email: user.email
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
return (
|
|
140
|
-
<form onSubmit={handleLogin}>
|
|
141
|
-
{/* Login form fields */}
|
|
142
|
-
</form>
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### Reset User Identity
|
|
148
|
-
Use the `useReset` hook to reset user identity when they log out.
|
|
149
|
-
|
|
150
|
-
```jsx
|
|
151
|
-
import React from 'react';
|
|
152
|
-
import { useReset } from '@journium/react';
|
|
153
|
-
|
|
154
|
-
function LogoutButton() {
|
|
155
|
-
const reset = useReset();
|
|
156
|
-
|
|
157
|
-
const handleLogout = async () => {
|
|
158
|
-
await logoutUser();
|
|
159
|
-
reset();
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
return <button onClick={handleLogout}>Log Out</button>;
|
|
163
|
-
}
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
## Advanced Setup
|
|
167
|
-
You can override default configurations and control autocapture:
|
|
48
|
+
For more detailed examples, hooks, and configuration options, visit the [Journium documentation](https://journium.app/docs/react).
|
|
168
49
|
|
|
169
|
-
|
|
170
|
-
```jsx
|
|
171
|
-
import React from 'react';
|
|
172
|
-
import { JourniumProvider } from '@journium/react';
|
|
173
|
-
import App from './App';
|
|
174
|
-
|
|
175
|
-
function Root() {
|
|
176
|
-
return (
|
|
177
|
-
<JourniumProvider
|
|
178
|
-
config={{
|
|
179
|
-
publishableKey: process.env.REACT_APP_JOURNIUM_PUBLISHABLE_KEY!,
|
|
180
|
-
apiHost: 'https://events.journium.app',
|
|
181
|
-
options: {
|
|
182
|
-
debug: process.env.REACT_APP_JOURNIUM_DEBUG === 'true',
|
|
183
|
-
flushAt: 5, // Send events after N events
|
|
184
|
-
flushInterval: 10000, // Send events every N milliseconds
|
|
185
|
-
sessionTimeout: 1800000, // Session timeout (30 minutes)
|
|
186
|
-
autoTrackPageviews: true, // Automatically track pageview events (default: true)
|
|
187
|
-
autocapture: { // Configure automatic event capture
|
|
188
|
-
captureClicks: true, // Track click events
|
|
189
|
-
captureFormSubmits: true, // Track form submissions
|
|
190
|
-
captureFormChanges: false, // Track form field changes
|
|
191
|
-
ignoreClasses: ['no-track', 'sensitive'], // CSS classes to ignore
|
|
192
|
-
ignoreElements: ['input[type="password"]'] // Elements to ignore
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}}
|
|
196
|
-
>
|
|
197
|
-
<App />
|
|
198
|
-
</JourniumProvider>
|
|
199
|
-
);
|
|
200
|
-
}
|
|
50
|
+
## Other SDKs
|
|
201
51
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
**Vite Example:**
|
|
206
|
-
```jsx
|
|
207
|
-
import React from 'react';
|
|
208
|
-
import { JourniumProvider } from '@journium/react';
|
|
209
|
-
import App from './App';
|
|
210
|
-
|
|
211
|
-
function Root() {
|
|
212
|
-
return (
|
|
213
|
-
<JourniumProvider
|
|
214
|
-
config={{
|
|
215
|
-
publishableKey: import.meta.env.VITE_JOURNIUM_PUBLISHABLE_KEY!,
|
|
216
|
-
apiHost: 'https://events.journium.app',
|
|
217
|
-
options: {
|
|
218
|
-
debug: import.meta.env.VITE_JOURNIUM_DEBUG === 'true',
|
|
219
|
-
flushAt: 5,
|
|
220
|
-
flushInterval: 10000,
|
|
221
|
-
sessionTimeout: 1800000,
|
|
222
|
-
autoTrackPageviews: true,
|
|
223
|
-
autocapture: {
|
|
224
|
-
captureClicks: true,
|
|
225
|
-
captureFormSubmits: true,
|
|
226
|
-
captureFormChanges: false,
|
|
227
|
-
ignoreClasses: ['no-track', 'sensitive'],
|
|
228
|
-
ignoreElements: ['input[type="password"]']
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}}
|
|
232
|
-
>
|
|
233
|
-
<App />
|
|
234
|
-
</JourniumProvider>
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
export default Root;
|
|
239
|
-
```
|
|
52
|
+
- [@journium/nextjs](https://www.npmjs.com/package/@journium/nextjs) - Next.js SDK
|
|
53
|
+
- [@journium/js](https://www.npmjs.com/package/@journium/js) - JavaScript SDK
|
|
240
54
|
|
|
241
|
-
##
|
|
55
|
+
## Support
|
|
242
56
|
|
|
243
|
-
|
|
57
|
+
Need help? Reach out to us:
|
|
244
58
|
|
|
245
|
-
|
|
246
|
-
|
|
59
|
+
- 📖 Join our official community [Discord server](https://journium.app/discord)
|
|
60
|
+
- 🐛 [Issue Tracker](https://github.com/journium/journium-js/issues)
|
|
247
61
|
|
|
248
|
-
|
|
249
|
-
- `config: JourniumConfig` - Configuration object for Journium
|
|
250
|
-
- `publishableKey: string` - Your Journium publishable key (required)
|
|
251
|
-
- `apiHost?: string` - Custom API endpoint (optional, defaults to 'https://events.journium.app')
|
|
252
|
-
- `options?: JourniumLocalOptions` - Local configuration options (optional)
|
|
253
|
-
- `children: ReactNode` - React children to wrap
|
|
62
|
+
## Contributing
|
|
254
63
|
|
|
255
|
-
|
|
64
|
+
We're open to all community contributions! If you'd like to contribute in any way, please read [our contribution guidelines](https://github.com/journium/journium-js/blob/main/CONTRIBUTING.md) and [code of conduct](https://github.com/journium/journium-js/blob/main/CODE_OF_CONDUCT.md).
|
|
256
65
|
|
|
257
|
-
#### `useTrackEvent()`
|
|
258
|
-
Returns a function to track custom events.
|
|
259
66
|
|
|
260
|
-
|
|
261
|
-
- `event: string` - Event name to track
|
|
262
|
-
- `properties?: Record<string, unknown>` - Optional event properties
|
|
67
|
+
## License
|
|
263
68
|
|
|
264
|
-
|
|
265
|
-
Returns a function to identify users.
|
|
266
|
-
|
|
267
|
-
**Returns:** `(distinctId: string, attributes?: Record<string, unknown>) => void`
|
|
268
|
-
- `distinctId: string` - Unique user identifier
|
|
269
|
-
- `attributes?: Record<string, unknown>` - Optional user attributes
|
|
270
|
-
|
|
271
|
-
#### `useReset()`
|
|
272
|
-
Returns a function to reset user identity (typically on logout).
|
|
273
|
-
|
|
274
|
-
**Returns:** `() => void`
|
|
275
|
-
|
|
276
|
-
#### `useTrackPageview()`
|
|
277
|
-
Returns a function to manually track pageview events.
|
|
278
|
-
|
|
279
|
-
**Returns:** `(properties?: Record<string, unknown>) => void`
|
|
280
|
-
- `properties?: Record<string, unknown>` - Optional pageview properties
|
|
281
|
-
|
|
282
|
-
#### `useAutoTrackPageview()`
|
|
283
|
-
Automatically tracks pageview when component mounts or dependencies change.
|
|
284
|
-
|
|
285
|
-
**Parameters:**
|
|
286
|
-
- `dependencies?: React.DependencyList` - Dependencies to watch for changes (defaults to empty array)
|
|
287
|
-
- `properties?: Record<string, unknown>` - Optional pageview properties
|
|
288
|
-
|
|
289
|
-
**Returns:** `void`
|
|
290
|
-
|
|
291
|
-
#### `useAutocapture()`
|
|
292
|
-
Returns functions to control automatic event capture.
|
|
293
|
-
|
|
294
|
-
**Returns:** `{ startAutocapture: () => void, stopAutocapture: () => void }`
|
|
295
|
-
- `startAutocapture()` - Enable automatic event capture
|
|
296
|
-
- `stopAutocapture()` - Disable automatic event capture
|
|
297
|
-
|
|
298
|
-
#### `useJournium()`
|
|
299
|
-
Returns the Journium context for advanced use cases.
|
|
300
|
-
|
|
301
|
-
**Returns:** `JourniumContextValue`
|
|
302
|
-
- `analytics: JourniumAnalytics | null` - The analytics instance
|
|
303
|
-
- `config: JourniumConfig | null` - The configuration object
|
|
304
|
-
- `effectiveOptions: JourniumLocalOptions | null` - The effective options (merged local and remote)
|
|
305
|
-
|
|
306
|
-
### Types
|
|
307
|
-
|
|
308
|
-
#### `JourniumConfig`
|
|
309
|
-
Configuration object for initializing Journium.
|
|
310
|
-
|
|
311
|
-
```typescript
|
|
312
|
-
interface JourniumConfig {
|
|
313
|
-
publishableKey: string;
|
|
314
|
-
apiHost?: string;
|
|
315
|
-
options?: JourniumLocalOptions;
|
|
316
|
-
}
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
#### `JourniumLocalOptions`
|
|
320
|
-
Local configuration options that can be set on the client.
|
|
321
|
-
|
|
322
|
-
```typescript
|
|
323
|
-
interface JourniumLocalOptions {
|
|
324
|
-
debug?: boolean; // Enable debug logging
|
|
325
|
-
flushAt?: number; // Number of events before auto-flush
|
|
326
|
-
flushInterval?: number; // Flush interval in milliseconds
|
|
327
|
-
autocapture?: boolean | AutocaptureOptions; // Auto-capture configuration
|
|
328
|
-
autoTrackPageviews?: boolean; // Automatic pageview tracking
|
|
329
|
-
sessionTimeout?: number; // Session timeout in milliseconds
|
|
330
|
-
sampling?: {
|
|
331
|
-
enabled?: boolean;
|
|
332
|
-
rate?: number;
|
|
333
|
-
};
|
|
334
|
-
features?: {
|
|
335
|
-
enableGeolocation?: boolean;
|
|
336
|
-
enableSessionRecording?: boolean;
|
|
337
|
-
enablePerformanceTracking?: boolean;
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
```
|
|
341
|
-
|
|
342
|
-
#### `AutocaptureOptions`
|
|
343
|
-
Configuration for automatic event capture.
|
|
344
|
-
|
|
345
|
-
```typescript
|
|
346
|
-
interface AutocaptureOptions {
|
|
347
|
-
captureClicks?: boolean; // Capture click events
|
|
348
|
-
captureFormSubmits?: boolean; // Capture form submissions
|
|
349
|
-
captureFormChanges?: boolean; // Capture form field changes
|
|
350
|
-
captureTextSelection?: boolean; // Capture text selection events
|
|
351
|
-
ignoreClasses?: string[]; // CSS classes to ignore
|
|
352
|
-
ignoreElements?: string[]; // HTML elements to ignore
|
|
353
|
-
captureContentText?: boolean; // Capture element text content
|
|
354
|
-
}
|
|
355
|
-
```
|
|
69
|
+
This project is licensed under the **MIT license**.
|
|
356
70
|
|
|
357
|
-
|
|
358
|
-
The main analytics class instance available through hooks.
|
|
71
|
+
See [LICENSE](https://github.com/journium/journium-js/blob/main/LICENSE) for more information.
|
|
359
72
|
|
|
360
|
-
**Methods:**
|
|
361
|
-
- `track(event: string, properties?: Record<string, unknown>): void` - Track custom event
|
|
362
|
-
- `identify(distinctId: string, attributes?: Record<string, unknown>): void` - Identify user
|
|
363
|
-
- `reset(): void` - Reset user identity
|
|
364
|
-
- `capturePageview(properties?: Record<string, unknown>): void` - Track pageview
|
|
365
|
-
- `startAutocapture(): void` - Start automatic event capture
|
|
366
|
-
- `stopAutocapture(): void` - Stop automatic event capture
|
|
367
|
-
- `flush(): void` - Flush pending events immediately
|
|
368
|
-
- `getEffectiveOptions(): JourniumLocalOptions` - Get effective configuration
|