@journium/react 1.0.1 → 1.0.2
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 +5 -3
- package/dist/context.d.ts.map +1 -1
- package/dist/hooks.d.ts +4 -4
- package/dist/hooks.d.ts.map +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.esm.js +144 -131
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +144 -131
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/readme.md +181 -124
package/readme.md
CHANGED
|
@@ -27,6 +27,19 @@ yarn add @journium/react
|
|
|
27
27
|
|
|
28
28
|
## Basic Setup
|
|
29
29
|
|
|
30
|
+
### Environment Variables
|
|
31
|
+
First, create a `.env.local` file in your project root:
|
|
32
|
+
|
|
33
|
+
**Note:** For CRA projects, use `REACT_APP_` prefix:
|
|
34
|
+
```env
|
|
35
|
+
REACT_APP_JOURNIUM_PUBLISHABLE_KEY=your-actual-publishable-key-here
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Note:** For Vite projects, use `VITE_` prefix:
|
|
39
|
+
```env
|
|
40
|
+
VITE_JOURNIUM_PUBLISHABLE_KEY=your-actual-publishable-key-here
|
|
41
|
+
```
|
|
42
|
+
|
|
30
43
|
### Initialize Journium
|
|
31
44
|
Wrap your app with the `JourniumProvider` to enable analytics throughout your React application.
|
|
32
45
|
|
|
@@ -39,7 +52,7 @@ function Root() {
|
|
|
39
52
|
return (
|
|
40
53
|
<JourniumProvider
|
|
41
54
|
config={{
|
|
42
|
-
publishableKey:
|
|
55
|
+
publishableKey: process.env.REACT_APP_JOURNIUM_PUBLISHABLE_KEY!
|
|
43
56
|
}}
|
|
44
57
|
>
|
|
45
58
|
<App />
|
|
@@ -50,6 +63,38 @@ function Root() {
|
|
|
50
63
|
export default Root;
|
|
51
64
|
```
|
|
52
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
|
+
|
|
74
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
75
|
+
<React.StrictMode>
|
|
76
|
+
<JourniumProvider
|
|
77
|
+
config={{
|
|
78
|
+
publishableKey: import.meta.env.VITE_JOURNIUM_PUBLISHABLE_KEY!
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
81
|
+
<App />
|
|
82
|
+
</JourniumProvider>
|
|
83
|
+
</React.StrictMode>
|
|
84
|
+
);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Vite .env file:**
|
|
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
|
+
|
|
53
98
|
### Track a Custom Event
|
|
54
99
|
Use the `useTrackEvent` hook to track custom events from any component.
|
|
55
100
|
|
|
@@ -119,9 +164,9 @@ function LogoutButton() {
|
|
|
119
164
|
```
|
|
120
165
|
|
|
121
166
|
## Advanced Setup
|
|
122
|
-
|
|
123
167
|
You can override default configurations and control autocapture:
|
|
124
168
|
|
|
169
|
+
**React/CRA Example:**
|
|
125
170
|
```jsx
|
|
126
171
|
import React from 'react';
|
|
127
172
|
import { JourniumProvider } from '@journium/react';
|
|
@@ -131,13 +176,14 @@ function Root() {
|
|
|
131
176
|
return (
|
|
132
177
|
<JourniumProvider
|
|
133
178
|
config={{
|
|
134
|
-
publishableKey:
|
|
135
|
-
apiHost: 'https://
|
|
136
|
-
|
|
137
|
-
debug: true,
|
|
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',
|
|
138
183
|
flushAt: 5, // Send events after N events
|
|
139
184
|
flushInterval: 10000, // Send events every N milliseconds
|
|
140
185
|
sessionTimeout: 1800000, // Session timeout (30 minutes)
|
|
186
|
+
autoTrackPageviews: true, // Automatically track pageview events (default: true)
|
|
141
187
|
autocapture: { // Configure automatic event capture
|
|
142
188
|
captureClicks: true, // Track click events
|
|
143
189
|
captureFormSubmits: true, // Track form submissions
|
|
@@ -156,156 +202,167 @@ function Root() {
|
|
|
156
202
|
export default Root;
|
|
157
203
|
```
|
|
158
204
|
|
|
159
|
-
|
|
205
|
+
**Vite Example:**
|
|
206
|
+
```jsx
|
|
207
|
+
import React from 'react';
|
|
208
|
+
import { JourniumProvider } from '@journium/react';
|
|
209
|
+
import App from './App';
|
|
160
210
|
|
|
161
|
-
|
|
162
|
-
|
|
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
|
+
}
|
|
163
237
|
|
|
164
|
-
|
|
165
|
-
<JourniumProvider
|
|
166
|
-
config={{
|
|
167
|
-
publishableKey: 'your-journium-publishable-key',
|
|
168
|
-
apiHost: 'https://events.journium.app', // Optional
|
|
169
|
-
config: { /* optional local config */ }
|
|
170
|
-
}}
|
|
171
|
-
>
|
|
172
|
-
<App />
|
|
173
|
-
</JourniumProvider>
|
|
238
|
+
export default Root;
|
|
174
239
|
```
|
|
175
240
|
|
|
176
|
-
|
|
177
|
-
Hook for tracking custom events with optional properties.
|
|
178
|
-
|
|
179
|
-
```jsx
|
|
180
|
-
import { useTrackEvent } from '@journium/react';
|
|
241
|
+
## API Reference
|
|
181
242
|
|
|
182
|
-
|
|
183
|
-
const trackEvent = useTrackEvent();
|
|
243
|
+
### Components
|
|
184
244
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
product_id: 'prod_123',
|
|
188
|
-
price: 29.99,
|
|
189
|
-
currency: 'USD'
|
|
190
|
-
});
|
|
191
|
-
};
|
|
245
|
+
#### `<JourniumProvider>`
|
|
246
|
+
Provider component that initializes Journium analytics throughout your React application.
|
|
192
247
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
248
|
+
**Props:**
|
|
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
|
|
196
254
|
|
|
197
|
-
###
|
|
198
|
-
Hook for identifying users on login or signup.
|
|
255
|
+
### Hooks
|
|
199
256
|
|
|
200
|
-
|
|
201
|
-
|
|
257
|
+
#### `useTrackEvent()`
|
|
258
|
+
Returns a function to track custom events.
|
|
202
259
|
|
|
203
|
-
|
|
204
|
-
|
|
260
|
+
**Returns:** `(event: string, properties?: Record<string, unknown>) => void`
|
|
261
|
+
- `event: string` - Event name to track
|
|
262
|
+
- `properties?: Record<string, unknown>` - Optional event properties
|
|
205
263
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
};
|
|
264
|
+
#### `useIdentify()`
|
|
265
|
+
Returns a function to identify users.
|
|
209
266
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
267
|
+
**Returns:** `(distinctId: string, attributes?: Record<string, unknown>) => void`
|
|
268
|
+
- `distinctId: string` - Unique user identifier
|
|
269
|
+
- `attributes?: Record<string, unknown>` - Optional user attributes
|
|
213
270
|
|
|
214
|
-
|
|
215
|
-
|
|
271
|
+
#### `useReset()`
|
|
272
|
+
Returns a function to reset user identity (typically on logout).
|
|
216
273
|
|
|
217
|
-
|
|
218
|
-
import { useReset } from '@journium/react';
|
|
274
|
+
**Returns:** `() => void`
|
|
219
275
|
|
|
220
|
-
|
|
221
|
-
|
|
276
|
+
#### `useTrackPageview()`
|
|
277
|
+
Returns a function to manually track pageview events.
|
|
222
278
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
};
|
|
279
|
+
**Returns:** `(properties?: Record<string, unknown>) => void`
|
|
280
|
+
- `properties?: Record<string, unknown>` - Optional pageview properties
|
|
226
281
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
```
|
|
282
|
+
#### `useAutoTrackPageview()`
|
|
283
|
+
Automatically tracks pageview when component mounts or dependencies change.
|
|
230
284
|
|
|
231
|
-
|
|
232
|
-
|
|
285
|
+
**Parameters:**
|
|
286
|
+
- `dependencies?: React.DependencyList` - Dependencies to watch for changes (defaults to empty array)
|
|
287
|
+
- `properties?: Record<string, unknown>` - Optional pageview properties
|
|
233
288
|
|
|
234
|
-
|
|
235
|
-
import { useTrackPageview } from '@journium/react';
|
|
289
|
+
**Returns:** `void`
|
|
236
290
|
|
|
237
|
-
|
|
238
|
-
|
|
291
|
+
#### `useAutocapture()`
|
|
292
|
+
Returns functions to control automatic event capture.
|
|
239
293
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
content_type: 'pricing_calculator'
|
|
244
|
-
});
|
|
245
|
-
};
|
|
294
|
+
**Returns:** `{ startAutocapture: () => void, stopAutocapture: () => void }`
|
|
295
|
+
- `startAutocapture()` - Enable automatic event capture
|
|
296
|
+
- `stopAutocapture()` - Disable automatic event capture
|
|
246
297
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
```
|
|
298
|
+
#### `useJournium()`
|
|
299
|
+
Returns the Journium context for advanced use cases.
|
|
250
300
|
|
|
251
|
-
|
|
252
|
-
|
|
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)
|
|
253
305
|
|
|
254
|
-
|
|
255
|
-
import { useAutoTrackPageview } from '@journium/react';
|
|
306
|
+
### Types
|
|
256
307
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
useAutoTrackPageview([productId], {
|
|
260
|
-
page_type: 'product_detail',
|
|
261
|
-
product_id: productId,
|
|
262
|
-
category: category
|
|
263
|
-
});
|
|
308
|
+
#### `JourniumConfig`
|
|
309
|
+
Configuration object for initializing Journium.
|
|
264
310
|
|
|
265
|
-
|
|
311
|
+
```typescript
|
|
312
|
+
interface JourniumConfig {
|
|
313
|
+
publishableKey: string;
|
|
314
|
+
apiHost?: string;
|
|
315
|
+
options?: JourniumLocalOptions;
|
|
266
316
|
}
|
|
267
317
|
```
|
|
268
318
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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;
|
|
280
333
|
};
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
334
|
+
features?: {
|
|
335
|
+
enableGeolocation?: boolean;
|
|
336
|
+
enableSessionRecording?: boolean;
|
|
337
|
+
enablePerformanceTracking?: boolean;
|
|
284
338
|
};
|
|
285
|
-
|
|
286
|
-
return (
|
|
287
|
-
<div>
|
|
288
|
-
<button onClick={handleAccept}>Accept</button>
|
|
289
|
-
<button onClick={handleDecline}>Decline</button>
|
|
290
|
-
</div>
|
|
291
|
-
);
|
|
292
339
|
}
|
|
293
340
|
```
|
|
294
341
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
return <button onClick={handleAdvancedTracking}>Advanced Track</button>;
|
|
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
|
|
310
354
|
}
|
|
311
|
-
```
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
#### `JourniumAnalytics`
|
|
358
|
+
The main analytics class instance available through hooks.
|
|
359
|
+
|
|
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
|