mytart 0.6.2 → 0.6.4

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
@@ -379,8 +379,9 @@ Returns `null` when `crossProviderLinking` is disabled.
379
379
  ```typescript
380
380
  interface MytartConfig {
381
381
  providers: ProviderConfig[];
382
- defaultUserId?: string; // applied to every track/page call if no userId given
383
- defaultAnonymousId?: string; // applied to every track/page call if no anonymousId given
382
+ defaultUserId?: string; // applied to every track/page call if no userId given
383
+ defaultAnonymousId?: string; // applied to every track/page call if no anonymousId given
384
+ defaultSessionId?: string; // applied to every track/page call if no sessionId given
384
385
  debug?: boolean;
385
386
  ignoreBots?: boolean; // when true, silently drops all tracking calls from known bots/crawlers
386
387
  crossProviderLinking?: boolean; // when true, auto-captures click IDs & cookies and injects them into every call
@@ -406,6 +407,7 @@ interface TrackOptions {
406
407
  properties?: Record<string, unknown>;
407
408
  userId?: string;
408
409
  anonymousId?: string;
410
+ sessionId?: string;
409
411
  timestamp?: Date;
410
412
  context?: EventContext;
411
413
  }
@@ -418,6 +420,7 @@ interface IdentifyOptions {
418
420
  userId: string;
419
421
  traits?: Record<string, unknown>;
420
422
  anonymousId?: string;
423
+ sessionId?: string;
421
424
  timestamp?: Date;
422
425
  }
423
426
  ```
@@ -432,6 +435,7 @@ interface PageOptions {
432
435
  properties?: Record<string, unknown>;
433
436
  userId?: string;
434
437
  anonymousId?: string;
438
+ sessionId?: string;
435
439
  timestamp?: Date;
436
440
  }
437
441
  ```
package/dist/index.d.mts CHANGED
@@ -37,12 +37,64 @@ interface ConsentSettings {
37
37
  }
38
38
  type ProviderName = 'google-analytics' | 'mixpanel' | 'segment' | 'amplitude' | 'plausible' | 'posthog' | 'meta-pixel' | 'clarity';
39
39
  type GoogleAnalyticsAppType = 'browser' | 'server';
40
+ /**
41
+ * Configuration for the Google Analytics (GA4) provider.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * {
46
+ * provider: 'google-analytics',
47
+ * enabled: true,
48
+ * measurementId: 'G-XXXXXXXXXX',
49
+ * appType: 'browser',
50
+ * debug: true,
51
+ * signals: true,
52
+ * }
53
+ * ```
54
+ */
40
55
  interface GoogleAnalyticsConfig extends BaseProviderConfig {
41
56
  provider: 'google-analytics';
57
+ /**
58
+ * The GA4 Measurement ID for your data stream.
59
+ * Found in GA4 under Admin › Data Streams › your stream.
60
+ *
61
+ * @example 'G-XXXXXXXXXX'
62
+ */
42
63
  measurementId: string;
64
+ /**
65
+ * API secret for the GA4 Measurement Protocol (server-side).
66
+ * Generate one in GA4 under Admin › Data Streams › Measurement Protocol API secrets.
67
+ * Required when `appType` is `'server'`.
68
+ *
69
+ * @example 'xYzAbCdEfGhIjKlM'
70
+ */
43
71
  apiSecret?: string;
72
+ /**
73
+ * A unique identifier for the client (device/browser instance).
74
+ * In server mode this is required to associate hits with a user session.
75
+ * In browser mode it is managed automatically by gtag.js and can be omitted.
76
+ *
77
+ * @example 'client-123456.7890123456'
78
+ */
44
79
  clientId?: string;
80
+ /**
81
+ * When `true`, enables GA4 debug mode.
82
+ * In browser mode this sends events to the DebugView in the GA4 dashboard.
83
+ * In server mode this sets `debug_mode: true` on Measurement Protocol payloads.
84
+ *
85
+ * @default false
86
+ */
45
87
  debug?: boolean;
88
+ /**
89
+ * Determines how events are sent to Google Analytics.
90
+ *
91
+ * - `'browser'` — injects the gtag.js snippet and uses `window.gtag()` calls.
92
+ * Suitable for client-side web apps.
93
+ * - `'server'` — sends events via the GA4 Measurement Protocol HTTP API.
94
+ * Requires `apiSecret` and `clientId`. Suitable for Node.js / edge / SSR.
95
+ *
96
+ * @default 'browser'
97
+ */
46
98
  appType?: GoogleAnalyticsAppType;
47
99
  /**
48
100
  * Default consent state set before gtag('config'). In browser mode this
@@ -83,31 +135,198 @@ interface GoogleAnalyticsConfig extends BaseProviderConfig {
83
135
  */
84
136
  signals?: boolean;
85
137
  }
138
+ /**
139
+ * Configuration for the Mixpanel provider.
140
+ *
141
+ * @example
142
+ * ```ts
143
+ * {
144
+ * provider: 'mixpanel',
145
+ * enabled: true,
146
+ * token: 'abc123def456',
147
+ * }
148
+ * ```
149
+ */
86
150
  interface MixpanelConfig extends BaseProviderConfig {
87
151
  provider: 'mixpanel';
152
+ /**
153
+ * Your Mixpanel project token.
154
+ * Found in Mixpanel under Settings › Project Settings › Project Token.
155
+ *
156
+ * @example 'abc123def456'
157
+ */
88
158
  token: string;
159
+ /**
160
+ * Custom Mixpanel API endpoint. Use this if you are routing events through
161
+ * a proxy or using Mixpanel's EU residency endpoint.
162
+ *
163
+ * @default 'https://api.mixpanel.com'
164
+ * @example 'https://api-eu.mixpanel.com'
165
+ */
89
166
  apiUrl?: string;
90
167
  }
168
+ /**
169
+ * Configuration for the Segment provider.
170
+ *
171
+ * @example
172
+ * ```ts
173
+ * {
174
+ * provider: 'segment',
175
+ * enabled: true,
176
+ * writeKey: 'wk_abc123...',
177
+ * }
178
+ * ```
179
+ */
91
180
  interface SegmentConfig extends BaseProviderConfig {
92
181
  provider: 'segment';
182
+ /**
183
+ * The Segment source Write Key.
184
+ * Found in Segment under Sources › your source › Settings › API Keys.
185
+ *
186
+ * @example 'wk_abc123def456ghi789'
187
+ */
93
188
  writeKey: string;
189
+ /**
190
+ * Custom Segment API endpoint. Use this if you are routing events through
191
+ * a proxy or a custom Segment data plane.
192
+ *
193
+ * @default 'https://api.segment.io/v1'
194
+ * @example 'https://events.yourdomain.com/v1'
195
+ */
94
196
  apiUrl?: string;
95
197
  }
198
+ /**
199
+ * Configuration for the Amplitude provider.
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * {
204
+ * provider: 'amplitude',
205
+ * enabled: true,
206
+ * apiKey: 'your-amplitude-api-key',
207
+ * }
208
+ * ```
209
+ */
96
210
  interface AmplitudeConfig extends BaseProviderConfig {
97
211
  provider: 'amplitude';
212
+ /**
213
+ * Your Amplitude project API key.
214
+ * Found in Amplitude under Settings › Projects › your project › General.
215
+ *
216
+ * @example 'a1b2c3d4e5f6a1b2c3d4e5f6'
217
+ */
98
218
  apiKey: string;
219
+ /**
220
+ * Custom Amplitude API endpoint. Use this if you are routing events through
221
+ * a proxy or using Amplitude's EU data centre.
222
+ *
223
+ * @default 'https://api2.amplitude.com/2/httpapi'
224
+ * @example 'https://api.eu.amplitude.com/2/httpapi'
225
+ */
99
226
  apiUrl?: string;
100
227
  }
228
+ /**
229
+ * Configuration for the Plausible Analytics provider.
230
+ *
231
+ * Plausible is a privacy-focused analytics platform. Server-side usage
232
+ * requires `userAgent` and `xForwardedFor` so Plausible can attribute
233
+ * visits without cookies.
234
+ *
235
+ * @example
236
+ * ```ts
237
+ * // Browser usage
238
+ * {
239
+ * provider: 'plausible',
240
+ * enabled: true,
241
+ * domain: 'example.com',
242
+ * }
243
+ * ```
244
+ *
245
+ * @example
246
+ * ```ts
247
+ * // Server-side usage
248
+ * {
249
+ * provider: 'plausible',
250
+ * enabled: true,
251
+ * domain: 'example.com',
252
+ * apiUrl: 'https://plausible.example.com',
253
+ * userAgent: req.headers['user-agent'],
254
+ * xForwardedFor: req.headers['x-forwarded-for'],
255
+ * }
256
+ * ```
257
+ */
101
258
  interface PlausibleConfig extends BaseProviderConfig {
102
259
  provider: 'plausible';
260
+ /**
261
+ * The domain name of the site as configured in your Plausible dashboard.
262
+ * Must match exactly (no protocol, no trailing slash).
263
+ *
264
+ * @example 'example.com'
265
+ */
103
266
  domain: string;
267
+ /**
268
+ * Custom Plausible API endpoint. Use this if you self-host Plausible
269
+ * or route events through a proxy to avoid ad-blockers.
270
+ *
271
+ * @default 'https://plausible.io'
272
+ * @example 'https://plausible.example.com'
273
+ */
104
274
  apiUrl?: string;
275
+ /**
276
+ * The visitor's User-Agent string. Required for server-side usage so
277
+ * Plausible can perform unique-visitor counting without cookies.
278
+ *
279
+ * @example 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ...'
280
+ */
105
281
  userAgent?: string;
282
+ /**
283
+ * The visitor's IP address, used by Plausible for geolocation and
284
+ * unique-visitor hashing. Required for server-side usage.
285
+ * Pass the `X-Forwarded-For` header value from the incoming request.
286
+ *
287
+ * @example '203.0.113.42'
288
+ */
106
289
  xForwardedFor?: string;
107
290
  }
291
+ /**
292
+ * Configuration for the PostHog provider.
293
+ *
294
+ * @example
295
+ * ```ts
296
+ * {
297
+ * provider: 'posthog',
298
+ * enabled: true,
299
+ * apiKey: 'phc_abc123def456',
300
+ * }
301
+ * ```
302
+ *
303
+ * @example
304
+ * ```ts
305
+ * // Self-hosted PostHog
306
+ * {
307
+ * provider: 'posthog',
308
+ * enabled: true,
309
+ * apiKey: 'phc_abc123def456',
310
+ * apiUrl: 'https://posthog.example.com',
311
+ * }
312
+ * ```
313
+ */
108
314
  interface PostHogConfig extends BaseProviderConfig {
109
315
  provider: 'posthog';
316
+ /**
317
+ * Your PostHog project API key (starts with `phc_`).
318
+ * Found in PostHog under Project Settings › Project API Key.
319
+ *
320
+ * @example 'phc_abc123def456ghi789'
321
+ */
110
322
  apiKey: string;
323
+ /**
324
+ * Custom PostHog API endpoint. Use this if you self-host PostHog
325
+ * or use PostHog's EU cloud instance.
326
+ *
327
+ * @default 'https://us.i.posthog.com' (PostHog US Cloud)
328
+ * @example 'https://eu.i.posthog.com'
329
+ */
111
330
  apiUrl?: string;
112
331
  }
113
332
  /**
@@ -116,35 +335,113 @@ interface PostHogConfig extends BaseProviderConfig {
116
335
  * In server mode they are included in the `user_data` object sent to the
117
336
  * Conversions API — plain-text values are automatically SHA-256 hashed before
118
337
  * sending.
338
+ *
339
+ * @example
340
+ * ```ts
341
+ * {
342
+ * em: 'user@example.com',
343
+ * fn: 'jane',
344
+ * ln: 'doe',
345
+ * country: 'us',
346
+ * }
347
+ * ```
119
348
  */
120
349
  interface MetaPixelAdvancedMatching {
121
- /** Email address */
350
+ /**
351
+ * Email address. Lowercased before hashing.
352
+ * @example 'user@example.com'
353
+ */
122
354
  em?: string;
123
- /** Phone number */
355
+ /**
356
+ * Phone number including country code, digits only (no dashes or spaces).
357
+ * @example '15551234567'
358
+ */
124
359
  ph?: string;
125
- /** First name */
360
+ /**
361
+ * First name. Lowercased before hashing.
362
+ * @example 'jane'
363
+ */
126
364
  fn?: string;
127
- /** Last name */
365
+ /**
366
+ * Last name. Lowercased before hashing.
367
+ * @example 'doe'
368
+ */
128
369
  ln?: string;
129
- /** Gender (m or f) */
370
+ /**
371
+ * Gender. Single lowercase letter: `'m'` for male, `'f'` for female.
372
+ * @example 'm'
373
+ */
130
374
  ge?: string;
131
- /** Date of birth (YYYYMMDD) */
375
+ /**
376
+ * Date of birth in `YYYYMMDD` format.
377
+ * @example '19900115'
378
+ */
132
379
  db?: string;
133
- /** City */
380
+ /**
381
+ * City name. Lowercased, no spaces or punctuation.
382
+ * @example 'newyork'
383
+ */
134
384
  ct?: string;
135
- /** State / province (2-letter code) */
385
+ /**
386
+ * State or province as a 2-letter code. Lowercased.
387
+ * @example 'ny'
388
+ */
136
389
  st?: string;
137
- /** Zip / postal code */
390
+ /**
391
+ * Zip or postal code. For US, use 5-digit format.
392
+ * @example '10001'
393
+ */
138
394
  zp?: string;
139
- /** Country (2-letter ISO code) */
395
+ /**
396
+ * Country as a 2-letter ISO 3166-1 alpha-2 code. Lowercased.
397
+ * @example 'us'
398
+ */
140
399
  country?: string;
141
- /** External ID */
400
+ /**
401
+ * External ID — your own unique identifier for the user.
402
+ * Useful for deduplicating browser and server events.
403
+ * @example 'user_abc123'
404
+ */
142
405
  external_id?: string;
143
406
  }
144
407
  type MetaPixelAppType = 'browser' | 'server';
408
+ /**
409
+ * Configuration for the Meta Pixel (Facebook Pixel) provider.
410
+ * Supports both browser-side pixel tracking and server-side Conversions API.
411
+ *
412
+ * @example
413
+ * ```ts
414
+ * // Browser mode
415
+ * {
416
+ * provider: 'meta-pixel',
417
+ * enabled: true,
418
+ * pixelId: '1234567890',
419
+ * appType: 'browser',
420
+ * debug: true,
421
+ * }
422
+ * ```
423
+ *
424
+ * @example
425
+ * ```ts
426
+ * // Server mode (Conversions API)
427
+ * {
428
+ * provider: 'meta-pixel',
429
+ * enabled: true,
430
+ * pixelId: '1234567890',
431
+ * appType: 'server',
432
+ * accessToken: 'EAABsb...',
433
+ * testEventCode: 'TEST12345',
434
+ * }
435
+ * ```
436
+ */
145
437
  interface MetaPixelConfig extends BaseProviderConfig {
146
438
  provider: 'meta-pixel';
147
- /** The Meta Pixel ID (numeric string). */
439
+ /**
440
+ * The Meta Pixel ID (numeric string).
441
+ * Found in Meta Events Manager under your pixel's settings.
442
+ *
443
+ * @example '1234567890'
444
+ */
148
445
  pixelId: string;
149
446
  /**
150
447
  * Access token for the Conversions API. Required when `appType` is
@@ -180,9 +477,29 @@ interface MetaPixelConfig extends BaseProviderConfig {
180
477
  /** Enable Meta Pixel debug mode (`fbq('set', 'debug', true)`). */
181
478
  debug?: boolean;
182
479
  }
480
+ /**
481
+ * Configuration for the Microsoft Clarity provider.
482
+ * Clarity provides session recordings, heatmaps, and behavioral analytics.
483
+ * Browser-only — this provider is a no-op in server environments.
484
+ *
485
+ * @example
486
+ * ```ts
487
+ * {
488
+ * provider: 'clarity',
489
+ * enabled: true,
490
+ * projectId: 'abc123def4',
491
+ * cookie: true,
492
+ * }
493
+ * ```
494
+ */
183
495
  interface ClarityConfig extends BaseProviderConfig {
184
496
  provider: 'clarity';
185
- /** The Clarity project ID (from the Clarity dashboard). */
497
+ /**
498
+ * The Clarity project ID found in your Clarity dashboard under
499
+ * Settings › Overview › Project ID.
500
+ *
501
+ * @example 'abc123def4'
502
+ */
186
503
  projectId: string;
187
504
  /**
188
505
  * Enable Clarity cookie consent mode. When `true`, calls
@@ -196,6 +513,7 @@ interface MytartConfig {
196
513
  providers: ProviderConfig[];
197
514
  defaultUserId?: string;
198
515
  defaultAnonymousId?: string;
516
+ defaultSessionId?: string;
199
517
  debug?: boolean;
200
518
  /**
201
519
  * When `true`, silently drops all `track`, `identify`, and `page` calls
@@ -240,6 +558,7 @@ interface TrackOptions {
240
558
  properties?: Record<string, unknown>;
241
559
  userId?: string;
242
560
  anonymousId?: string;
561
+ sessionId?: string;
243
562
  timestamp?: Date;
244
563
  context?: EventContext;
245
564
  }
@@ -247,6 +566,7 @@ interface IdentifyOptions {
247
566
  userId: string;
248
567
  traits?: Record<string, unknown>;
249
568
  anonymousId?: string;
569
+ sessionId?: string;
250
570
  timestamp?: Date;
251
571
  }
252
572
  interface PageOptions {
@@ -256,6 +576,7 @@ interface PageOptions {
256
576
  properties?: Record<string, unknown>;
257
577
  userId?: string;
258
578
  anonymousId?: string;
579
+ sessionId?: string;
259
580
  timestamp?: Date;
260
581
  }
261
582
  interface TrackResult {
@@ -408,9 +729,9 @@ declare class GoogleAnalyticsProvider extends BaseProvider {
408
729
  * support Consent Mode.
409
730
  */
410
731
  updateConsent(consent: ConsentSettings): Promise<void>;
411
- track({ event, properties, userId, anonymousId, timestamp }: TrackOptions): Promise<TrackResult>;
412
- identify({ userId, traits }: IdentifyOptions): Promise<TrackResult>;
413
- page({ name, url, referrer, userId, anonymousId }: PageOptions): Promise<TrackResult>;
732
+ track({ event, properties, userId, anonymousId, sessionId, timestamp }: TrackOptions): Promise<TrackResult>;
733
+ identify({ userId, traits, sessionId }: IdentifyOptions): Promise<TrackResult>;
734
+ page({ name, url, referrer, userId, anonymousId, sessionId }: PageOptions): Promise<TrackResult>;
414
735
  }
415
736
 
416
737
  declare class MixpanelProvider extends BaseProvider {
@@ -431,9 +752,9 @@ declare class SegmentProvider extends BaseProvider {
431
752
  private readonly baseUrl;
432
753
  constructor(config: SegmentConfig);
433
754
  private getAuth;
434
- track({ event, properties, userId, anonymousId, timestamp, context }: TrackOptions): Promise<TrackResult>;
435
- identify({ userId, traits, anonymousId, timestamp }: IdentifyOptions): Promise<TrackResult>;
436
- page({ name, url, referrer, properties, userId, anonymousId, timestamp }: PageOptions): Promise<TrackResult>;
755
+ track({ event, properties, userId, anonymousId, sessionId, timestamp, context }: TrackOptions): Promise<TrackResult>;
756
+ identify({ userId, traits, anonymousId, sessionId, timestamp }: IdentifyOptions): Promise<TrackResult>;
757
+ page({ name, url, referrer, properties, userId, anonymousId, sessionId, timestamp }: PageOptions): Promise<TrackResult>;
437
758
  }
438
759
 
439
760
  declare class AmplitudeProvider extends BaseProvider {
@@ -442,9 +763,9 @@ declare class AmplitudeProvider extends BaseProvider {
442
763
  private readonly http;
443
764
  private readonly endpoint;
444
765
  constructor(config: AmplitudeConfig);
445
- track({ event, properties, userId, anonymousId, timestamp }: TrackOptions): Promise<TrackResult>;
446
- identify({ userId, traits }: IdentifyOptions): Promise<TrackResult>;
447
- page({ name, url, userId, anonymousId, properties }: PageOptions): Promise<TrackResult>;
766
+ track({ event, properties, userId, anonymousId, sessionId, timestamp }: TrackOptions): Promise<TrackResult>;
767
+ identify({ userId, traits, anonymousId, sessionId }: IdentifyOptions): Promise<TrackResult>;
768
+ page({ name, url, userId, anonymousId, sessionId, properties }: PageOptions): Promise<TrackResult>;
448
769
  }
449
770
 
450
771
  declare class PlausibleProvider extends BaseProvider {
@@ -465,9 +786,9 @@ declare class PostHogProvider extends BaseProvider {
465
786
  private readonly http;
466
787
  private readonly endpoint;
467
788
  constructor(config: PostHogConfig);
468
- track({ event, properties, userId, anonymousId, timestamp }: TrackOptions): Promise<TrackResult>;
469
- identify({ userId, traits }: IdentifyOptions): Promise<TrackResult>;
470
- page({ name, url, userId, anonymousId, properties }: PageOptions): Promise<TrackResult>;
789
+ track({ event, properties, userId, anonymousId, sessionId, timestamp }: TrackOptions): Promise<TrackResult>;
790
+ identify({ userId, traits, anonymousId, sessionId }: IdentifyOptions): Promise<TrackResult>;
791
+ page({ name, url, userId, anonymousId, sessionId, properties }: PageOptions): Promise<TrackResult>;
471
792
  }
472
793
 
473
794
  declare global {