@datalyr/web 1.0.1 → 1.0.3

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
@@ -34,16 +34,13 @@ pnpm add @datalyr/web
34
34
  ## Quick Start
35
35
 
36
36
  ```javascript
37
- import { Datalyr } from '@datalyr/web';
37
+ import datalyr from '@datalyr/web';
38
38
 
39
- // Initialize with your workspace ID
40
- const datalyr = new Datalyr({
39
+ // Initialize the SDK with your workspace ID
40
+ datalyr.init({
41
41
  workspaceId: 'YOUR_WORKSPACE_ID'
42
42
  });
43
43
 
44
- // Initialize the SDK
45
- await datalyr.init();
46
-
47
44
  // Track an event
48
45
  datalyr.track('Button Clicked', {
49
46
  button_name: 'Sign Up',
@@ -63,7 +60,10 @@ datalyr.identify('user_123', {
63
60
  ### Initialization
64
61
 
65
62
  ```javascript
66
- const datalyr = new Datalyr({
63
+ import datalyr from '@datalyr/web';
64
+
65
+ // Initialize the SDK with configuration
66
+ datalyr.init({
67
67
  workspaceId: 'YOUR_WORKSPACE_ID',
68
68
 
69
69
  // Optional configuration
@@ -79,8 +79,6 @@ const datalyr = new Datalyr({
79
79
  trackSPA: true, // Track SPA route changes
80
80
  trackPageViews: true // Track initial page view
81
81
  });
82
-
83
- await datalyr.init();
84
82
  ```
85
83
 
86
84
  ### Track Events
@@ -243,7 +241,9 @@ datalyr.track('Signup');
243
241
  // Includes: utm_source, utm_medium, first_touch_source, last_touch_source, etc.
244
242
 
245
243
  // Track custom URL parameters
246
- const datalyr = new Datalyr({
244
+ import datalyr from '@datalyr/web';
245
+
246
+ datalyr.init({
247
247
  workspaceId: 'YOUR_WORKSPACE_ID',
248
248
  trackedParams: ['ref', 'affiliate_id', 'promo_code']
249
249
  });
@@ -254,7 +254,9 @@ const datalyr = new Datalyr({
254
254
  For single-page applications:
255
255
 
256
256
  ```javascript
257
- const datalyr = new Datalyr({
257
+ import datalyr from '@datalyr/web';
258
+
259
+ datalyr.init({
258
260
  workspaceId: 'YOUR_WORKSPACE_ID',
259
261
  trackSPA: true // Auto-track route changes (default: true)
260
262
  });
@@ -270,14 +272,16 @@ datalyr.page('Product Details', {
270
272
  Control data collection:
271
273
 
272
274
  ```javascript
275
+ import datalyr from '@datalyr/web';
276
+
273
277
  // Standard mode (default) - balanced privacy
274
- const datalyr = new Datalyr({
278
+ datalyr.init({
275
279
  workspaceId: 'YOUR_WORKSPACE_ID',
276
280
  privacyMode: 'standard'
277
281
  });
278
282
 
279
- // Strict mode - minimal data collection
280
- const datalyr = new Datalyr({
283
+ // Or strict mode - minimal data collection
284
+ datalyr.init({
281
285
  workspaceId: 'YOUR_WORKSPACE_ID',
282
286
  privacyMode: 'strict'
283
287
  });
@@ -300,14 +304,16 @@ await datalyr.flush();
300
304
  Automatically track users across subdomains:
301
305
 
302
306
  ```javascript
307
+ import datalyr from '@datalyr/web';
308
+
303
309
  // Auto-detect domain for *.example.com
304
- const datalyr = new Datalyr({
310
+ datalyr.init({
305
311
  workspaceId: 'YOUR_WORKSPACE_ID',
306
312
  cookieDomain: 'auto' // Default
307
313
  });
308
314
 
309
315
  // Or set explicitly
310
- const datalyr = new Datalyr({
316
+ datalyr.init({
311
317
  workspaceId: 'YOUR_WORKSPACE_ID',
312
318
  cookieDomain: '.example.com'
313
319
  });
@@ -318,7 +324,9 @@ const datalyr = new Datalyr({
318
324
  The SDK can automatically load and manage third-party tracking scripts with built-in security:
319
325
 
320
326
  ```javascript
321
- const datalyr = new Datalyr({
327
+ import datalyr from '@datalyr/web';
328
+
329
+ datalyr.init({
322
330
  workspaceId: 'YOUR_WORKSPACE_ID',
323
331
  enableContainer: true // Default: true
324
332
  });
@@ -352,6 +360,8 @@ The container manager supports:
352
360
  Extend SDK functionality:
353
361
 
354
362
  ```javascript
363
+ import datalyr from '@datalyr/web';
364
+
355
365
  // Create a plugin
356
366
  const myPlugin = {
357
367
  name: 'my-plugin',
@@ -373,8 +383,8 @@ const myPlugin = {
373
383
  }
374
384
  };
375
385
 
376
- // Register plugin
377
- const datalyr = new Datalyr({
386
+ // Register plugin during initialization
387
+ datalyr.init({
378
388
  workspaceId: 'YOUR_WORKSPACE_ID',
379
389
  plugins: [myPlugin]
380
390
  });
@@ -385,9 +395,10 @@ const datalyr = new Datalyr({
385
395
  Full TypeScript definitions are included:
386
396
 
387
397
  ```typescript
388
- import { Datalyr, EventProperties, UserTraits } from '@datalyr/web';
398
+ import datalyr, { EventProperties, UserTraits } from '@datalyr/web';
389
399
 
390
- const datalyr = new Datalyr({
400
+ // Initialize the SDK
401
+ datalyr.init({
391
402
  workspaceId: 'YOUR_WORKSPACE_ID'
392
403
  });
393
404
 
@@ -416,15 +427,13 @@ datalyr.identify('user_123', traits);
416
427
 
417
428
  ```jsx
418
429
  import { useEffect } from 'react';
419
- import { Datalyr } from '@datalyr/web';
420
-
421
- const datalyr = new Datalyr({
422
- workspaceId: 'YOUR_WORKSPACE_ID'
423
- });
430
+ import datalyr from '@datalyr/web';
424
431
 
425
432
  function App() {
426
433
  useEffect(() => {
427
- datalyr.init();
434
+ datalyr.init({
435
+ workspaceId: 'YOUR_WORKSPACE_ID'
436
+ });
428
437
  }, []);
429
438
 
430
439
  const handleClick = () => {
@@ -442,14 +451,12 @@ function App() {
442
451
  ```vue
443
452
  <script setup>
444
453
  import { onMounted } from 'vue';
445
- import { Datalyr } from '@datalyr/web';
446
-
447
- const datalyr = new Datalyr({
448
- workspaceId: 'YOUR_WORKSPACE_ID'
449
- });
454
+ import datalyr from '@datalyr/web';
450
455
 
451
456
  onMounted(() => {
452
- datalyr.init();
457
+ datalyr.init({
458
+ workspaceId: 'YOUR_WORKSPACE_ID'
459
+ });
453
460
  });
454
461
 
455
462
  const trackClick = () => {
@@ -469,15 +476,13 @@ const trackClick = () => {
469
476
  'use client';
470
477
 
471
478
  import { useEffect } from 'react';
472
- import { Datalyr } from '@datalyr/web';
473
-
474
- const datalyr = new Datalyr({
475
- workspaceId: process.env.NEXT_PUBLIC_DATALYR_WORKSPACE_ID
476
- });
479
+ import datalyr from '@datalyr/web';
477
480
 
478
481
  export function AnalyticsProvider({ children }) {
479
482
  useEffect(() => {
480
- datalyr.init();
483
+ datalyr.init({
484
+ workspaceId: process.env.NEXT_PUBLIC_DATALYR_WORKSPACE_ID
485
+ });
481
486
  }, []);
482
487
 
483
488
  return children;
@@ -506,16 +511,14 @@ Initialize the SDK as early as possible in your application lifecycle:
506
511
 
507
512
  ```javascript
508
513
  // In your main entry file
509
- import { Datalyr } from '@datalyr/web';
514
+ import datalyr from '@datalyr/web';
510
515
 
511
- const datalyr = new Datalyr({
516
+ // Initialize before other code
517
+ datalyr.init({
512
518
  workspaceId: 'YOUR_WORKSPACE_ID'
513
519
  });
514
520
 
515
- // Initialize before other code
516
- datalyr.init().then(() => {
517
- // Start your app
518
- });
521
+ // Your app code...
519
522
  ```
520
523
 
521
524
  ### 2. Use Consistent Event Naming
@@ -617,13 +620,12 @@ If you're currently using the Datalyr script tag, migration is straightforward:
617
620
 
618
621
  ### After (Web SDK):
619
622
  ```javascript
620
- import { Datalyr } from '@datalyr/web';
623
+ import datalyr from '@datalyr/web';
621
624
 
622
- const datalyr = new Datalyr({
625
+ datalyr.init({
623
626
  workspaceId: 'YOUR_WORKSPACE_ID'
624
627
  });
625
628
 
626
- await datalyr.init();
627
629
  datalyr.track('Button Clicked');
628
630
  ```
629
631
 
@@ -660,7 +662,9 @@ The SDK is designed with privacy in mind:
660
662
  Enable debug mode for detailed logging:
661
663
 
662
664
  ```javascript
663
- const datalyr = new Datalyr({
665
+ import datalyr from '@datalyr/web';
666
+
667
+ datalyr.init({
664
668
  workspaceId: 'YOUR_WORKSPACE_ID',
665
669
  debug: true
666
670
  });
@@ -672,7 +676,7 @@ const datalyr = new Datalyr({
672
676
 
673
677
  ## API Reference
674
678
 
675
- ### Constructor Options
679
+ ### Initialization Options
676
680
 
677
681
  | Option | Type | Default | Description |
678
682
  |--------|------|---------|-------------|
@@ -694,7 +698,7 @@ const datalyr = new Datalyr({
694
698
 
695
699
  | Method | Description |
696
700
  |--------|-------------|
697
- | `init()` | Initialize the SDK |
701
+ | `init(config)` | Initialize the SDK with configuration |
698
702
  | `track(event, properties?)` | Track an event |
699
703
  | `identify(userId?, traits?)` | Identify a user |
700
704
  | `page(name?, properties?)` | Track a page view |
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @datalyr/web v1.0.1
2
+ * @datalyr/web v1.0.3
3
3
  * Datalyr Web SDK - Modern attribution tracking for web applications
4
4
  * (c) 2025 Datalyr Inc.
5
5
  * Released under the MIT License
@@ -1795,8 +1795,8 @@ class ContainerManager {
1795
1795
  this.pixels = null;
1796
1796
  this.initialized = false;
1797
1797
  this.workspaceId = options.workspaceId;
1798
- // Container scripts always use the app endpoint, not ingest
1799
- this.endpoint = this.extractAppEndpoint(options.endpoint);
1798
+ // Container scripts use the same endpoint as tracking (ingest)
1799
+ this.endpoint = options.endpoint || 'https://ingest.datalyr.com';
1800
1800
  this.debug = options.debug || false;
1801
1801
  // Load session scripts from storage
1802
1802
  const sessionScripts = storage.get('dl_session_scripts', []);