@journium/js 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/README.md CHANGED
@@ -4,243 +4,64 @@
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
5
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
6
6
 
7
- **The official Journium JavaScript SDK for web browsers**
7
+ The official Journium JavaScript SDK for web browsers. Track events, pageviews, and user interactions with ease.
8
8
 
9
- Track events, pageviews, and user interactions with ease. Perfect for SPAs, vanilla JavaScript apps, and any web application.
9
+ ---
10
10
 
11
- ## Installation
11
+ ## Getting Started
12
12
 
13
- ### npm
14
- ```bash
15
- npm install @journium/js
16
- ```
13
+ Learn how to use Journium to power your application:
17
14
 
18
- ### pnpm
19
- ```bash
20
- pnpm add @journium/js
21
- ```
15
+ - [Quick Start Guide](https://journium.app/docs/js)
16
+ - [Concepts](https://journium.app/docs/js/concepts)
17
+ - [SDK Reference](https://journium.app/docs/js)
18
+
19
+ ### Prerequisites
20
+ - Modern browser (ES2017+)
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_js).
23
+
24
+ ## Installation
22
25
 
23
- ### yarn
24
26
  ```bash
25
- yarn add @journium/js
27
+ npm install @journium/js
26
28
  ```
27
29
 
28
- ## Basic Setup
29
-
30
- ### Initialize Journium
31
- Initialize the Journium SDK with your publishable key to start tracking events.
30
+ ## Usage
32
31
 
33
32
  ```javascript
34
33
  import { init } from '@journium/js';
35
34
 
36
35
  const journium = init({
37
- publishableKey: 'your-journium-publishable-key'
36
+ publishableKey: "your-publishable-key"
38
37
  });
39
- ```
40
38
 
41
- ### Track a Custom Event
42
- Track user actions and business events with custom properties.
43
-
44
- ```javascript
45
39
  journium.track('button_clicked', {
46
- button_name: 'signup',
47
- page: 'homepage',
48
- user_type: 'visitor'
40
+ button_name: 'signup'
49
41
  });
50
42
  ```
51
43
 
52
- ### Identify a User
53
- Identify users when they log in or sign up to connect their actions across sessions.
44
+ For more detailed examples and configuration options, visit the [Journium documentation](https://journium.app/docs/js/).
54
45
 
55
- ```javascript
56
- journium.identify('user_12345', {
57
- name: 'John Doe',
58
- email: 'john@example.com',
59
- plan: 'premium'
60
- });
61
- ```
62
-
63
- ### Reset User Identity
64
- Reset user identity when they log out to ensure privacy and accurate tracking.
65
-
66
- ```javascript
67
- journium.reset();
68
- ```
69
-
70
- ## Advanced Setup
71
-
72
- You can override default configurations:
73
-
74
- ```javascript
75
- import { init } from '@journium/js';
76
-
77
- const journium = init({
78
- publishableKey: 'your-journium-publishable-key',
79
- apiHost: 'https://your-custom-instance.com', // Optional: defaults to 'https://events.journium.app'
80
- options: {
81
- debug: true, // Enable debug logging
82
- flushAt: 10, // Send events after N events
83
- flushInterval: 5000, // Send events every N milliseconds
84
- sessionTimeout: 1800000, // Session timeout (30 minutes)
85
- autoTrackPageviews: true, // Track pageview events (default: true)
86
- autocapture: { // Configure automatic event capture
87
- captureClicks: true, // Track click events
88
- captureFormSubmits: true, // Track form submissions
89
- captureFormChanges: false, // Track form field changes
90
- ignoreClasses: ['no-track'], // CSS classes to ignore
91
- ignoreElements: ['input[type="password"]'] // Elements to ignore
92
- }
93
- }
94
- });
95
-
96
- // Start automatic event capture
97
- journium.startAutocapture();
98
- ```
46
+ ## Other SDKs
99
47
 
100
- ## API Reference
48
+ - [@journium/nextjs](https://www.npmjs.com/package/@journium/nextjs) - Next.js SDK
49
+ - [@journium/react](https://www.npmjs.com/package/@journium/react) - React SDK
101
50
 
102
- ### Functions
51
+ ## Support
103
52
 
104
- #### `init(config: JourniumConfig)`
105
- Initializes and returns a new JourniumAnalytics instance.
106
-
107
- **Parameters:**
108
- - `config: JourniumConfig` - Configuration object for Journium
109
- - `publishableKey: string` - Your Journium publishable key (required)
110
- - `apiHost?: string` - Custom API endpoint (optional, defaults to 'https://events.journium.app')
111
- - `options?: JourniumLocalOptions` - Local configuration options (optional)
112
-
113
- **Returns:** `JourniumAnalytics` - Analytics instance for tracking events
114
-
115
- ### JourniumAnalytics Instance Methods
116
-
117
- #### `track(event: string, properties?: Record<string, unknown>): void`
118
- Tracks custom events with optional properties.
119
-
120
- **Parameters:**
121
- - `event: string` - Event name to track
122
- - `properties?: Record<string, unknown>` - Optional event properties
123
-
124
- #### `identify(distinctId: string, attributes?: Record<string, unknown>): void`
125
- Identifies a user and associates future events with their identity.
126
-
127
- **Parameters:**
128
- - `distinctId: string` - Unique user identifier
129
- - `attributes?: Record<string, unknown>` - Optional user attributes
130
-
131
- #### `reset(): void`
132
- Resets user identity, typically called on logout.
133
-
134
- **Returns:** `void`
135
-
136
- #### `capturePageview(properties?: Record<string, unknown>): void`
137
- Manually captures pageview events.
138
-
139
- **Parameters:**
140
- - `properties?: Record<string, unknown>` - Optional pageview properties
141
-
142
- #### `startAutocapture(): void`
143
- Starts automatic event capture for clicks, form interactions, and pageviews.
144
-
145
- **Returns:** `void`
146
-
147
- **Note:** Autocapture behavior is configured during initialization via the `autocapture` option.
148
-
149
- #### `stopAutocapture(): void`
150
- Stops automatic event capture.
151
-
152
- **Returns:** `void`
153
-
154
- #### `flush(): Promise<void>`
155
- Manually sends all queued events to the server immediately.
156
-
157
- **Returns:** `Promise<void>` - Promise that resolves when events are sent
158
-
159
- #### `destroy(): void`
160
- Cleans up the SDK, stops all tracking, and sends remaining events.
161
-
162
- **Returns:** `void`
163
-
164
- #### `getEffectiveOptions(): JourniumLocalOptions`
165
- Returns the effective configuration options (merged local and remote options).
166
-
167
- **Returns:** `JourniumLocalOptions` - Current effective configuration
168
-
169
- ### Types
170
-
171
- #### `JourniumConfig`
172
- Configuration object for initializing Journium.
173
-
174
- ```typescript
175
- interface JourniumConfig {
176
- publishableKey: string;
177
- apiHost?: string;
178
- options?: JourniumLocalOptions;
179
- }
180
- ```
181
-
182
- #### `JourniumLocalOptions`
183
- Local configuration options that can be set on the client.
184
-
185
- ```typescript
186
- interface JourniumLocalOptions {
187
- debug?: boolean; // Enable debug logging
188
- flushAt?: number; // Number of events before auto-flush
189
- flushInterval?: number; // Flush interval in milliseconds
190
- autocapture?: boolean | AutocaptureOptions; // Auto-capture configuration
191
- autoTrackPageviews?: boolean; // Automatic pageview tracking
192
- sessionTimeout?: number; // Session timeout in milliseconds
193
- sampling?: {
194
- enabled?: boolean;
195
- rate?: number;
196
- };
197
- features?: {
198
- enableGeolocation?: boolean;
199
- enableSessionRecording?: boolean;
200
- enablePerformanceTracking?: boolean;
201
- };
202
- }
203
- ```
204
-
205
- #### `AutocaptureOptions`
206
- Configuration for automatic event capture.
207
-
208
- ```typescript
209
- interface AutocaptureOptions {
210
- captureClicks?: boolean; // Capture click events
211
- captureFormSubmits?: boolean; // Capture form submissions
212
- captureFormChanges?: boolean; // Capture form field changes
213
- captureTextSelection?: boolean; // Capture text selection events
214
- ignoreClasses?: string[]; // CSS classes to ignore
215
- ignoreElements?: string[]; // HTML elements to ignore
216
- captureContentText?: boolean; // Capture element text content
217
- }
218
- ```
53
+ Need help? Reach out to us:
219
54
 
220
- ### Browser Support
55
+ - 📖 Join our official community [Discord server](https://journium.app/discord)
56
+ - 🐛 [Issue Tracker](https://github.com/journium/journium-js/issues)
221
57
 
222
- - ✅ Modern browsers (ES2017+)
223
- - ✅ Chrome 60+
224
- - ✅ Firefox 55+
225
- - ✅ Safari 11+
226
- - ✅ Edge 79+
58
+ ## Contributing
227
59
 
228
- ### Bundle Formats
60
+ 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).
229
61
 
230
- The package includes multiple build formats:
231
62
 
232
- - **ESM**: `dist/index.esm.js` - For modern bundlers (webpack, Vite, Rollup)
233
- - **CommonJS**: `dist/index.cjs` - For Node.js environments
234
- - **UMD**: `dist/index.umd.js` - For browser `<script>` tags
63
+ ## License
235
64
 
236
- #### UMD Usage
65
+ This project is licensed under the **MIT license**.
237
66
 
238
- ```html
239
- <script src="node_modules/@journium/js/dist/index.umd.js"></script>
240
- <script>
241
- const analytics = window.JourniumAnalytics.init({
242
- publishableKey: 'your-publishable-key'
243
- });
244
- analytics.track('page_loaded');
245
- </script>
246
- ```
67
+ See [LICENSE](https://github.com/journium/journium-js/blob/main/LICENSE) for more information.
@@ -14,6 +14,11 @@ export declare class JourniumAnalytics {
14
14
  capturePageview(properties?: Record<string, unknown>): void;
15
15
  startAutocapture(): void;
16
16
  stopAutocapture(): void;
17
+ /**
18
+ * Automatically start autocapture if enabled in options
19
+ * Handles both initial options and empty options during remote-first initialization
20
+ */
21
+ private startAutocaptureIfEnabled;
17
22
  /**
18
23
  * Handle effective options change (e.g., when remote options are fetched)
19
24
  */
@@ -1 +1 @@
1
- {"version":3,"file":"JourniumAnalytics.d.ts","sourceRoot":"","sources":["../src/JourniumAnalytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAsB,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAK1F,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,kBAAkB,CAAqB;IAC/C,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,kBAAkB,CAAkB;IAC5C,OAAO,CAAC,wBAAwB,CAAC,CAAa;gBAElC,MAAM,EAAE,cAAc;IAiBlC,OAAO,CAAC,yBAAyB;IAiBjC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAIhE,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAIxE,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AM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI3D,gBAAgB,IAAI,IAAI;IA4BxB,eAAe,IAAI,IAAI;IAMvB;;;OAGG;IACH,OAAO,CAAC,yBAAyB;IAkCjC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA6BrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,mBAAmB;IAInB;;OAEG;IACH,eAAe,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,GAAG,MAAM,IAAI;IAI9E,OAAO,IAAI,IAAI;CAQhB;AAED,eAAO,MAAM,IAAI,GAAI,QAAQ,cAAc,KAAG,iBAE7C,CAAC;;mBAF2B,cAAc,KAAG,iBAAiB;;;AAI/D,wBAA2C"}
@@ -3,22 +3,25 @@ export declare class JourniumClient {
3
3
  private config;
4
4
  private effectiveOptions;
5
5
  private queue;
6
+ private stagedEvents;
6
7
  private flushTimer;
7
- private initialized;
8
+ private initializationComplete;
9
+ private initializationFailed;
8
10
  private identityManager;
9
11
  private optionsStorageKey;
12
+ private disabled;
10
13
  private optionsChangeCallbacks;
11
14
  constructor(config: JourniumConfig);
12
15
  private loadCachedOptions;
13
16
  private saveCachedOptions;
14
- private initializeSync;
15
- private fetchRemoteOptionsAsync;
16
- private fetchAndCacheRemoteOptions;
17
+ private initializeAsync;
18
+ private fetchRemoteOptionsWithRetry;
17
19
  /**
18
20
  * Register a callback to be notified when effective options change (e.g., when remote options are fetched)
19
21
  */
20
22
  onOptionsChange(callback: (options: JourniumLocalOptions) => void): () => void;
21
23
  private notifyOptionsChange;
24
+ private processStagedEvents;
22
25
  private startFlushTimer;
23
26
  private sendEvents;
24
27
  identify(distinctId: string, attributes?: Record<string, unknown>): void;
@@ -1 +1 @@
1
- {"version":3,"file":"JourniumClient.d.ts","sourceRoot":"","sources":["../src/JourniumClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,cAAc,EAAE,oBAAoB,EAAyG,MAAM,gBAAgB,CAA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O,CAAC,UAAU,CAA+C;IACjE,OAAO,CAAC,sBAAsB,CAAkB;IAChD,OAAO,CAAC,oBAAoB,CAAkB;IAC9C,OAAO,CAAC,eAAe,CAA0B;IACjD,OAAO,CAAC,iBAAiB,CAAU;IACnC,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,sBAAsB,CAA2D;gBAE7E,MAAM,EAAE,cAAc;IAoClC,OAAO,CAAC,iBAAiB;IAczB,OAAO,CAAC,iBAAiB;YAYX,eAAe;YAwEf,2BAA2B;IA8CzC;;OAEG;IACH,eAAe,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,GAAG,MAAM,IAAI;IAQ9E,OAAO,CAAC,mBAAmB;IAU3B,OAAO,CAAC,mBAAmB;IA0C3B,OAAO,CAAC,eAAe;YAYT,UAAU;IA0BxB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,IAAI;IA2B5E,KAAK,IAAI,IAAI;IAmBb,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,IAAI;IAiE9D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAyB5B,OAAO,IAAI,IAAI;IAQf,mBAAmB,IAAI,oBAAoB;CAG5C"}
@@ -11,7 +11,7 @@ export declare class PageviewTracker {
11
11
  * Start automatic autocapture for pageviews
12
12
  * @returns void
13
13
  */
14
- startAutocapture(): void;
14
+ startAutoPageviewTracking(): void;
15
15
  /**
16
16
  * Stop automatic autocapture for pageviews
17
17
  * @returns void
@@ -1 +1 @@
1
- {"version":3,"file":"PageviewTracker.d.ts","sourceRoot":"","sources":["../src/PageviewTracker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,iBAAiB,CAAgD;IACzE,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,eAAe,CAA6B;gBAExC,MAAM,EAAE,cAAc;IAIlC,eAAe,CAAC,gBAAgB,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,IAAI;IAkBrE;;;OAGG;IACH,gBAAgB,IAAI,IAAI;IA0BxB;;;OAGG;IACH,eAAe,IAAI,IAAI;CAmBxB"}
1
+ {"version":3,"file":"PageviewTracker.d.ts","sourceRoot":"","sources":["../src/PageviewTracker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,iBAAiB,CAAgD;IACzE,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,eAAe,CAA6B;gBAExC,MAAM,EAAE,cAAc;IAIlC,eAAe,CAAC,gBAAgB,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,IAAI;IAkBrE;;;OAGG;IACH,yBAAyB,IAAI,IAAI;IA0BjC;;;OAGG;IACH,eAAe,IAAI,IAAI;CAmBxB"}