saasco-sdk 0.2.4 → 0.2.6

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/index.d.cts CHANGED
@@ -39,7 +39,7 @@ type Integration = {
39
39
  /**
40
40
  * The function to track an event
41
41
  */
42
- track?: (name: string, properties?: Record<string, unknown>, context?: AnalyticsContext) => void;
42
+ track?: (name: string, properties?: Record<string, unknown>, context?: AnalyticsContext) => void | Promise<void>;
43
43
  /**
44
44
  * The function to identify a user
45
45
  */
@@ -51,6 +51,7 @@ type IntegrationState = {
51
51
  status: IntegrationStatus;
52
52
  };
53
53
  type ManagerConfig = {
54
+ deduplicationNamespace?: string;
54
55
  /**
55
56
  * Enable logger level
56
57
  */
@@ -60,7 +61,7 @@ type ManagerConfig = {
60
61
  */
61
62
  maxQueueSize?: number;
62
63
  /**
63
- * Max integration wait time, this is how long we will wait for an integration to be ready before flushing the queue. If an integration is not ready after this time it will miss any previous events.
64
+ * Max integration wait time, this is how long we will wait for an integration to be ready before flushing the queue. Unsent events expire after this time without consuming their delivery guard, so an explicit retry or page refresh can retry them.
64
65
  */
65
66
  maxIntegrationWaitTime?: number;
66
67
  /**
@@ -74,7 +75,6 @@ declare class IntegrationManager {
74
75
  private globalQueue;
75
76
  private config;
76
77
  private logger;
77
- private initTime;
78
78
  private currentEnvironment;
79
79
  private flushTimer?;
80
80
  private unloadHandler?;
@@ -96,12 +96,10 @@ declare class IntegrationManager {
96
96
  */
97
97
  private send;
98
98
  private deliver;
99
- /**
100
- * Flush queued events FIFO once at least one integration is ready.
101
- */
99
+ /** Each ready destination drains its own copy; a slow/blocked pixel cannot
100
+ * discard another pixel's queued events or hold up the ready destinations. */
102
101
  private flush;
103
102
  private readyCount;
104
- private isReady;
105
103
  /**
106
104
  * Setup periodic flushing if enabled
107
105
  */
@@ -139,6 +137,8 @@ declare global {
139
137
  }
140
138
  interface Fbq {
141
139
  (...args: unknown[]): void;
140
+ callMethod?: (...args: unknown[]) => void;
141
+ push?: (...args: unknown[]) => void;
142
142
  queue?: unknown[];
143
143
  loaded?: boolean;
144
144
  version?: string;
@@ -217,13 +217,16 @@ declare global {
217
217
  }
218
218
  interface Ttq {
219
219
  (...args: unknown[]): void;
220
+ ready?: (callback: () => void) => void;
220
221
  methods?: string[];
221
222
  _i?: Record<string, unknown>;
222
223
  _t?: Record<string, number>;
223
224
  _o?: Record<string, unknown>;
224
225
  load?: (pixelId: string, options?: Record<string, unknown>) => void;
225
226
  page?: () => void;
226
- track?: (eventName: string, properties?: Record<string, unknown>) => void;
227
+ track?: (eventName: string, properties?: Record<string, unknown>, options?: {
228
+ event_id: string;
229
+ }) => void;
227
230
  identify?: (properties?: Record<string, unknown>) => void;
228
231
  setAndDefer?: (obj: Record<string, unknown>, method: string) => void;
229
232
  instance?: (pixelId: string) => Ttq;
@@ -287,17 +290,22 @@ type DoRequestResponse = {
287
290
  };
288
291
  type IntegrationsConfig = (FacebookPixelIntegrationConfig | PinterestTagIntegrationConfig | TikTokPixelIntegrationConfig)[];
289
292
  /**
290
- * Opt-in config for the support widget, set on the `Saasco` constructor.
291
- * The widget is a cross-origin iframe loaded by a lean host-page loader
292
- * (`saasco-support-loader.js`); no React ships in this analytics entry,
293
- * which stays React-free by lazily injecting the loader rather than importing
294
- * it. Providing this object opts in; pass `enabled: false` to keep it off (e.g.
295
- * behind your own runtime flag). The projectId is shared from the analytics
296
- * config — you never declare it twice.
293
+ * Optional config for the support widget. Support is **always available
294
+ * wherever the analytics SDK runs** — you don't need to pass this object at
295
+ * all. Whether the widget actually renders is decided **server-side**: on init
296
+ * the SDK runs a cheap `{ enabled }` check and lazily injects the lean loader
297
+ * (`saasco-support-loader.js`) only when the project has the widget enabled
298
+ * in the dashboard, so pages where it's off never download it — and the
299
+ * dashboard toggle controls every install (CDN and npm) uniformly.
300
+ *
301
+ * The loader origin is resolved automatically: the CDN `<script>` origin for
302
+ * CDN installs, else the public Saasco CDN for npm/bundled installs. Pass this
303
+ * object only to override those defaults: `baseUrl`/`scriptUrl` point a
304
+ * same-origin, proxied, or self-hosted install at the right origin.
305
+ * The projectId is shared from the analytics config — you never declare it
306
+ * twice.
297
307
  */
298
308
  type SupportInit = {
299
- /** Defaults to `true` when the `support` object is provided. */
300
- enabled?: boolean;
301
309
  /** Origin of the saasco app hosting the support API. Defaults server-side to where the widget bundle is served from. */
302
310
  baseUrl?: string;
303
311
  /** Input placeholder for the chat composer. */
@@ -323,19 +331,11 @@ type SupportInit = {
323
331
  * The loader + widget-payload origin is resolved automatically: the CDN
324
332
  * `<script>` origin for CDN installs, else the public Saasco CDN for
325
333
  * npm/bundled installs (which carry no script tag on the page). Pass this object
326
- * only to override those defaults or to opt out: `enabled: false` (or
327
- * `data-social-proof-enabled="false"` on the CDN tag) is a client kill-switch
328
- * that skips the check entirely; `baseUrl`/`scriptUrl` point a same-origin,
334
+ * only to override those defaults: `baseUrl`/`scriptUrl` point a same-origin,
329
335
  * proxied, or self-hosted install at the right origin. The projectId is shared
330
336
  * from the analytics config — you never declare it twice.
331
337
  */
332
338
  type SocialProofInit = {
333
- /**
334
- * Client kill-switch. Defaults to `true`. When `false`, the SDK skips the
335
- * server check and never injects the loader, regardless of the dashboard
336
- * setting.
337
- */
338
- enabled?: boolean;
339
339
  /**
340
340
  * Origin of the saasco app hosting the social-proof widget-payload API.
341
341
  * Defaults to the loader bundle's origin — the CDN `<script>` origin for CDN
@@ -357,12 +357,13 @@ declare class Saasco {
357
357
  private integrationManager;
358
358
  private logger;
359
359
  private lastSupportIdentity;
360
+ private ingestFailureKeys;
360
361
  /**
361
362
  * Creates an instance of the Saasco SDK.
362
363
  * @param config Configuration options.
363
364
  * @param config.projectId The unique identifier for the project.
364
365
  * @param config.proxy The URL of the proxy server to use, if any.
365
- * @param config.autoPageTracking Whether to automatically track page views. Default is false.
366
+ * @param config.autoPageTracking Whether to automatically track page views. Default is true.
366
367
  * @param config.enabled Whether analytics is enabled. Default is true. Set to false for development and staging envioronments. Will still allow debug mode to be true, just no events will be sent
367
368
  * @param config.debug Whether to log debug information. Default is false.
368
369
  * @param config.trackUrlParams Whether to track URL parameters. Default is true.
@@ -387,20 +388,6 @@ declare class Saasco {
387
388
  init(): void;
388
389
  disableDebug(): void;
389
390
  enableDebug(): void;
390
- /**
391
- * Enables and injects the support widget when it was constructed with
392
- * `support: { enabled: false }`. Safe to call multiple times.
393
- */
394
- enableSupport(): void;
395
- /**
396
- * Enables and injects the social-proof widget (e.g. after constructing with
397
- * `socialProof: { enabled: false }`, or when no `socialProof` block was
398
- * passed). Injection still runs the server check, so the loader only
399
- * downloads when the project has the app enabled in the dashboard.
400
- * Safe to call multiple times — the loader injection is guarded against
401
- * double-injection.
402
- */
403
- enableSocialProof(): void;
404
391
  /**
405
392
  * Initialize third-party integrations
406
393
  */
@@ -414,7 +401,7 @@ declare class Saasco {
414
401
  track(payload: TrackPayload): Promise<DoRequestResponse>;
415
402
  /**
416
403
  * The page method lets you record page views on your website
417
- * This records the page title and path and names the event useing the reserved property "Page Viewed"
404
+ * This records the page title and path and names the event using the reserved name "Page View"
418
405
  *
419
406
  * Before implementing this make sure you have disabled the autoPageTracking in the config or you will get duplicate page views
420
407
  */
@@ -465,11 +452,8 @@ declare class Saasco {
465
452
  readyCount: number;
466
453
  };
467
454
  /**
468
- * Lazily injects the support **loader** from the same `/sdk/` origin as
469
- * the analytics bundle, forwarding the shared `projectId` and the widget
470
- * config as `data-*` attributes. The loader (no React) injects the
471
- * cross-origin embed iframe. Deferred (`async`) and guarded against
472
- * double-injection so re-running `init()` is a no-op.
455
+ * Lazily injects the support **loader** (server-gated). See
456
+ * {@link injectSupportLoader}. Replays identity once the script loads.
473
457
  */
474
458
  private injectSupport;
475
459
  /**
@@ -479,14 +463,13 @@ declare class Saasco {
479
463
  private injectSocialProof;
480
464
  /**
481
465
  * Records the latest CRM identity and forwards it to the support widget.
482
- * No-op when support isn't enabled.
483
466
  */
484
467
  private updateSupportIdentity;
485
468
  /**
486
469
  * Pushes the current identity onto `window.SaascoSupport.identify`. The
487
470
  * widget bundle publishes that global asynchronously, so this short-polls for
488
- * it (same approach as tool registration); the load handler also calls this,
489
- * so a fresh page load with a stored distinctId still identifies the chat.
471
+ * it (same approach as tool registration). `injectSupport` calls this on
472
+ * script load (or immediately when the loader is already present).
490
473
  */
491
474
  private pushSupportIdentity;
492
475
  }
package/dist/index.d.ts CHANGED
@@ -39,7 +39,7 @@ type Integration = {
39
39
  /**
40
40
  * The function to track an event
41
41
  */
42
- track?: (name: string, properties?: Record<string, unknown>, context?: AnalyticsContext) => void;
42
+ track?: (name: string, properties?: Record<string, unknown>, context?: AnalyticsContext) => void | Promise<void>;
43
43
  /**
44
44
  * The function to identify a user
45
45
  */
@@ -51,6 +51,7 @@ type IntegrationState = {
51
51
  status: IntegrationStatus;
52
52
  };
53
53
  type ManagerConfig = {
54
+ deduplicationNamespace?: string;
54
55
  /**
55
56
  * Enable logger level
56
57
  */
@@ -60,7 +61,7 @@ type ManagerConfig = {
60
61
  */
61
62
  maxQueueSize?: number;
62
63
  /**
63
- * Max integration wait time, this is how long we will wait for an integration to be ready before flushing the queue. If an integration is not ready after this time it will miss any previous events.
64
+ * Max integration wait time, this is how long we will wait for an integration to be ready before flushing the queue. Unsent events expire after this time without consuming their delivery guard, so an explicit retry or page refresh can retry them.
64
65
  */
65
66
  maxIntegrationWaitTime?: number;
66
67
  /**
@@ -74,7 +75,6 @@ declare class IntegrationManager {
74
75
  private globalQueue;
75
76
  private config;
76
77
  private logger;
77
- private initTime;
78
78
  private currentEnvironment;
79
79
  private flushTimer?;
80
80
  private unloadHandler?;
@@ -96,12 +96,10 @@ declare class IntegrationManager {
96
96
  */
97
97
  private send;
98
98
  private deliver;
99
- /**
100
- * Flush queued events FIFO once at least one integration is ready.
101
- */
99
+ /** Each ready destination drains its own copy; a slow/blocked pixel cannot
100
+ * discard another pixel's queued events or hold up the ready destinations. */
102
101
  private flush;
103
102
  private readyCount;
104
- private isReady;
105
103
  /**
106
104
  * Setup periodic flushing if enabled
107
105
  */
@@ -139,6 +137,8 @@ declare global {
139
137
  }
140
138
  interface Fbq {
141
139
  (...args: unknown[]): void;
140
+ callMethod?: (...args: unknown[]) => void;
141
+ push?: (...args: unknown[]) => void;
142
142
  queue?: unknown[];
143
143
  loaded?: boolean;
144
144
  version?: string;
@@ -217,13 +217,16 @@ declare global {
217
217
  }
218
218
  interface Ttq {
219
219
  (...args: unknown[]): void;
220
+ ready?: (callback: () => void) => void;
220
221
  methods?: string[];
221
222
  _i?: Record<string, unknown>;
222
223
  _t?: Record<string, number>;
223
224
  _o?: Record<string, unknown>;
224
225
  load?: (pixelId: string, options?: Record<string, unknown>) => void;
225
226
  page?: () => void;
226
- track?: (eventName: string, properties?: Record<string, unknown>) => void;
227
+ track?: (eventName: string, properties?: Record<string, unknown>, options?: {
228
+ event_id: string;
229
+ }) => void;
227
230
  identify?: (properties?: Record<string, unknown>) => void;
228
231
  setAndDefer?: (obj: Record<string, unknown>, method: string) => void;
229
232
  instance?: (pixelId: string) => Ttq;
@@ -287,17 +290,22 @@ type DoRequestResponse = {
287
290
  };
288
291
  type IntegrationsConfig = (FacebookPixelIntegrationConfig | PinterestTagIntegrationConfig | TikTokPixelIntegrationConfig)[];
289
292
  /**
290
- * Opt-in config for the support widget, set on the `Saasco` constructor.
291
- * The widget is a cross-origin iframe loaded by a lean host-page loader
292
- * (`saasco-support-loader.js`); no React ships in this analytics entry,
293
- * which stays React-free by lazily injecting the loader rather than importing
294
- * it. Providing this object opts in; pass `enabled: false` to keep it off (e.g.
295
- * behind your own runtime flag). The projectId is shared from the analytics
296
- * config — you never declare it twice.
293
+ * Optional config for the support widget. Support is **always available
294
+ * wherever the analytics SDK runs** — you don't need to pass this object at
295
+ * all. Whether the widget actually renders is decided **server-side**: on init
296
+ * the SDK runs a cheap `{ enabled }` check and lazily injects the lean loader
297
+ * (`saasco-support-loader.js`) only when the project has the widget enabled
298
+ * in the dashboard, so pages where it's off never download it — and the
299
+ * dashboard toggle controls every install (CDN and npm) uniformly.
300
+ *
301
+ * The loader origin is resolved automatically: the CDN `<script>` origin for
302
+ * CDN installs, else the public Saasco CDN for npm/bundled installs. Pass this
303
+ * object only to override those defaults: `baseUrl`/`scriptUrl` point a
304
+ * same-origin, proxied, or self-hosted install at the right origin.
305
+ * The projectId is shared from the analytics config — you never declare it
306
+ * twice.
297
307
  */
298
308
  type SupportInit = {
299
- /** Defaults to `true` when the `support` object is provided. */
300
- enabled?: boolean;
301
309
  /** Origin of the saasco app hosting the support API. Defaults server-side to where the widget bundle is served from. */
302
310
  baseUrl?: string;
303
311
  /** Input placeholder for the chat composer. */
@@ -323,19 +331,11 @@ type SupportInit = {
323
331
  * The loader + widget-payload origin is resolved automatically: the CDN
324
332
  * `<script>` origin for CDN installs, else the public Saasco CDN for
325
333
  * npm/bundled installs (which carry no script tag on the page). Pass this object
326
- * only to override those defaults or to opt out: `enabled: false` (or
327
- * `data-social-proof-enabled="false"` on the CDN tag) is a client kill-switch
328
- * that skips the check entirely; `baseUrl`/`scriptUrl` point a same-origin,
334
+ * only to override those defaults: `baseUrl`/`scriptUrl` point a same-origin,
329
335
  * proxied, or self-hosted install at the right origin. The projectId is shared
330
336
  * from the analytics config — you never declare it twice.
331
337
  */
332
338
  type SocialProofInit = {
333
- /**
334
- * Client kill-switch. Defaults to `true`. When `false`, the SDK skips the
335
- * server check and never injects the loader, regardless of the dashboard
336
- * setting.
337
- */
338
- enabled?: boolean;
339
339
  /**
340
340
  * Origin of the saasco app hosting the social-proof widget-payload API.
341
341
  * Defaults to the loader bundle's origin — the CDN `<script>` origin for CDN
@@ -357,12 +357,13 @@ declare class Saasco {
357
357
  private integrationManager;
358
358
  private logger;
359
359
  private lastSupportIdentity;
360
+ private ingestFailureKeys;
360
361
  /**
361
362
  * Creates an instance of the Saasco SDK.
362
363
  * @param config Configuration options.
363
364
  * @param config.projectId The unique identifier for the project.
364
365
  * @param config.proxy The URL of the proxy server to use, if any.
365
- * @param config.autoPageTracking Whether to automatically track page views. Default is false.
366
+ * @param config.autoPageTracking Whether to automatically track page views. Default is true.
366
367
  * @param config.enabled Whether analytics is enabled. Default is true. Set to false for development and staging envioronments. Will still allow debug mode to be true, just no events will be sent
367
368
  * @param config.debug Whether to log debug information. Default is false.
368
369
  * @param config.trackUrlParams Whether to track URL parameters. Default is true.
@@ -387,20 +388,6 @@ declare class Saasco {
387
388
  init(): void;
388
389
  disableDebug(): void;
389
390
  enableDebug(): void;
390
- /**
391
- * Enables and injects the support widget when it was constructed with
392
- * `support: { enabled: false }`. Safe to call multiple times.
393
- */
394
- enableSupport(): void;
395
- /**
396
- * Enables and injects the social-proof widget (e.g. after constructing with
397
- * `socialProof: { enabled: false }`, or when no `socialProof` block was
398
- * passed). Injection still runs the server check, so the loader only
399
- * downloads when the project has the app enabled in the dashboard.
400
- * Safe to call multiple times — the loader injection is guarded against
401
- * double-injection.
402
- */
403
- enableSocialProof(): void;
404
391
  /**
405
392
  * Initialize third-party integrations
406
393
  */
@@ -414,7 +401,7 @@ declare class Saasco {
414
401
  track(payload: TrackPayload): Promise<DoRequestResponse>;
415
402
  /**
416
403
  * The page method lets you record page views on your website
417
- * This records the page title and path and names the event useing the reserved property "Page Viewed"
404
+ * This records the page title and path and names the event using the reserved name "Page View"
418
405
  *
419
406
  * Before implementing this make sure you have disabled the autoPageTracking in the config or you will get duplicate page views
420
407
  */
@@ -465,11 +452,8 @@ declare class Saasco {
465
452
  readyCount: number;
466
453
  };
467
454
  /**
468
- * Lazily injects the support **loader** from the same `/sdk/` origin as
469
- * the analytics bundle, forwarding the shared `projectId` and the widget
470
- * config as `data-*` attributes. The loader (no React) injects the
471
- * cross-origin embed iframe. Deferred (`async`) and guarded against
472
- * double-injection so re-running `init()` is a no-op.
455
+ * Lazily injects the support **loader** (server-gated). See
456
+ * {@link injectSupportLoader}. Replays identity once the script loads.
473
457
  */
474
458
  private injectSupport;
475
459
  /**
@@ -479,14 +463,13 @@ declare class Saasco {
479
463
  private injectSocialProof;
480
464
  /**
481
465
  * Records the latest CRM identity and forwards it to the support widget.
482
- * No-op when support isn't enabled.
483
466
  */
484
467
  private updateSupportIdentity;
485
468
  /**
486
469
  * Pushes the current identity onto `window.SaascoSupport.identify`. The
487
470
  * widget bundle publishes that global asynchronously, so this short-polls for
488
- * it (same approach as tool registration); the load handler also calls this,
489
- * so a fresh page load with a stored distinctId still identifies the chat.
471
+ * it (same approach as tool registration). `injectSupport` calls this on
472
+ * script load (or immediately when the loader is already present).
490
473
  */
491
474
  private pushSupportIdentity;
492
475
  }