saasco-sdk 0.2.3 → 0.2.5

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
@@ -259,8 +259,8 @@ declare global {
259
259
  saascoAutoPageTrackingActive?: boolean;
260
260
  saasco: Saasco;
261
261
  saascoLastIdentifyKey?: string;
262
- /** Set once the lazy-loaded support-chat script has been injected. */
263
- __saascoSupportChatInjected?: boolean;
262
+ /** Set once the lazy-loaded support script has been injected. */
263
+ __saascoSupportInjected?: boolean;
264
264
  /** Set once the lazy-loaded social-proof loader script has been injected. */
265
265
  __saascoSocialProofInjected?: boolean;
266
266
  }
@@ -287,25 +287,30 @@ type DoRequestResponse = {
287
287
  };
288
288
  type IntegrationsConfig = (FacebookPixelIntegrationConfig | PinterestTagIntegrationConfig | TikTokPixelIntegrationConfig)[];
289
289
  /**
290
- * Opt-in config for the support chat widget, set on the `Saasco` constructor.
291
- * The widget is a cross-origin iframe loaded by a lean host-page loader
292
- * (`saasco-support-chat-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.
290
+ * Optional config for the support widget. Support is **always available
291
+ * wherever the analytics SDK runs** you don't need to pass this object at
292
+ * all. Whether the widget actually renders is decided **server-side**: on init
293
+ * the SDK runs a cheap `{ enabled }` check and lazily injects the lean loader
294
+ * (`saasco-support-loader.js`) only when the project has the widget enabled
295
+ * in the dashboard, so pages where it's off never download it — and the
296
+ * dashboard toggle controls every install (CDN and npm) uniformly.
297
+ *
298
+ * The loader origin is resolved automatically: the CDN `<script>` origin for
299
+ * CDN installs, else the public Saasco CDN for npm/bundled installs. Pass this
300
+ * object only to override those defaults: `baseUrl`/`scriptUrl` point a
301
+ * same-origin, proxied, or self-hosted install at the right origin.
302
+ * The projectId is shared from the analytics config — you never declare it
303
+ * twice.
297
304
  */
298
- type SupportChatInit = {
299
- /** Defaults to `true` when the `supportChat` object is provided. */
300
- enabled?: boolean;
301
- /** Origin of the saasco app hosting the support-chat API. Defaults server-side to where the widget bundle is served from. */
305
+ type SupportInit = {
306
+ /** Origin of the saasco app hosting the support API. Defaults server-side to where the widget bundle is served from. */
302
307
  baseUrl?: string;
303
308
  /** Input placeholder for the chat composer. */
304
309
  placeholder?: string;
305
310
  /**
306
311
  * URL the loader is loaded from. Accepts either the analytics
307
312
  * `saasco-sdk.js` URL (the loader URL is derived from it) or the
308
- * `saasco-support-chat-loader.js` URL directly. Defaults to deriving from the
313
+ * `saasco-support-loader.js` URL directly. Defaults to deriving from the
309
314
  * loaded analytics `<script>` tag, so CDN installs can omit it.
310
315
  */
311
316
  scriptUrl?: string;
@@ -323,19 +328,11 @@ type SupportChatInit = {
323
328
  * The loader + widget-payload origin is resolved automatically: the CDN
324
329
  * `<script>` origin for CDN installs, else the public Saasco CDN for
325
330
  * 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,
331
+ * only to override those defaults: `baseUrl`/`scriptUrl` point a same-origin,
329
332
  * proxied, or self-hosted install at the right origin. The projectId is shared
330
333
  * from the analytics config — you never declare it twice.
331
334
  */
332
335
  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
336
  /**
340
337
  * Origin of the saasco app hosting the social-proof widget-payload API.
341
338
  * Defaults to the loader bundle's origin — the CDN `<script>` origin for CDN
@@ -356,13 +353,13 @@ declare class Saasco {
356
353
  private isInitialized;
357
354
  private integrationManager;
358
355
  private logger;
359
- private lastSupportChatIdentity;
356
+ private lastSupportIdentity;
360
357
  /**
361
358
  * Creates an instance of the Saasco SDK.
362
359
  * @param config Configuration options.
363
360
  * @param config.projectId The unique identifier for the project.
364
361
  * @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.
362
+ * @param config.autoPageTracking Whether to automatically track page views. Default is true.
366
363
  * @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
364
  * @param config.debug Whether to log debug information. Default is false.
368
365
  * @param config.trackUrlParams Whether to track URL parameters. Default is true.
@@ -381,26 +378,12 @@ declare class Saasco {
381
378
  debug?: boolean;
382
379
  debugVerbose?: boolean;
383
380
  integrations?: IntegrationsConfig;
384
- supportChat?: SupportChatInit;
381
+ support?: SupportInit;
385
382
  socialProof?: SocialProofInit;
386
383
  });
387
384
  init(): void;
388
385
  disableDebug(): void;
389
386
  enableDebug(): void;
390
- /**
391
- * Enables and injects the support chat widget when it was constructed with
392
- * `supportChat: { enabled: false }`. Safe to call multiple times.
393
- */
394
- enableSupportChat(): 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
387
  /**
405
388
  * Initialize third-party integrations
406
389
  */
@@ -414,7 +397,7 @@ declare class Saasco {
414
397
  track(payload: TrackPayload): Promise<DoRequestResponse>;
415
398
  /**
416
399
  * 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"
400
+ * This records the page title and path and names the event using the reserved name "Page View"
418
401
  *
419
402
  * Before implementing this make sure you have disabled the autoPageTracking in the config or you will get duplicate page views
420
403
  */
@@ -465,33 +448,38 @@ declare class Saasco {
465
448
  readyCount: number;
466
449
  };
467
450
  /**
468
- * Lazily injects the support-chat **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.
451
+ * Lazily injects the support **loader** (server-gated). See
452
+ * {@link injectSupportLoader}. Replays identity once the script loads.
473
453
  */
474
- private injectSupportChat;
454
+ private injectSupport;
475
455
  /**
476
456
  * Lazily injects the social-proof loader (server-gated). See
477
457
  * {@link injectSocialProofLoader}.
478
458
  */
479
459
  private injectSocialProof;
480
460
  /**
481
- * Records the latest CRM identity and forwards it to the support-chat widget.
482
- * No-op when support chat isn't enabled.
461
+ * Records the latest CRM identity and forwards it to the support widget.
483
462
  */
484
- private updateSupportChatIdentity;
463
+ private updateSupportIdentity;
485
464
  /**
486
- * Pushes the current identity onto `window.SaascoSupportChat.identify`. The
465
+ * Pushes the current identity onto `window.SaascoSupport.identify`. The
487
466
  * 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.
467
+ * it (same approach as tool registration). `injectSupport` calls this on
468
+ * script load (or immediately when the loader is already present).
490
469
  */
491
- private pushSupportChatIdentity;
470
+ private pushSupportIdentity;
492
471
  }
493
472
 
494
- declare const browserContextSchema: z.ZodObject<{
473
+ /**
474
+ * Browser-collected context attached to track payloads by `getBrowserContext()`.
475
+ *
476
+ * Defined here rather than in `libs/analytics/sdk` because server and worker
477
+ * code validates it too. The SDK re-exports it, so `saasco-sdk`'s public API is
478
+ * unchanged — but a shared module importing the SDK barrel would drag the whole
479
+ * DOM-dependent bundle into every consumer's program, including the Cloudflare
480
+ * Worker, which has no DOM lib.
481
+ */
482
+ declare const BrowserContextSchema: z.ZodObject<{
495
483
  $href: z.ZodString;
496
484
  $locale: z.ZodString;
497
485
  $location: z.ZodString;
@@ -516,11 +504,11 @@ declare const browserContextSchema: z.ZodObject<{
516
504
  $utmSourcePlatform: z.ZodNullable<z.ZodString>;
517
505
  $utmTerm: z.ZodNullable<z.ZodString>;
518
506
  }, z.core.$strip>;
519
- type BrowserContext = z.infer<typeof browserContextSchema>;
507
+ type BrowserContext = z.infer<typeof BrowserContextSchema>;
520
508
  type SuperContext = Record<string, unknown>;
521
509
 
522
510
  declare function getBrowserContext(): BrowserContext;
523
511
 
524
512
  declare const timezones: Record<string, string>;
525
513
 
526
- export { type AnalyticsContext, type BrowserContext, type EventEnvelope, type EventType, type FacebookEventMapping, type FacebookPixelConfig, type FacebookPixelIntegrationConfig, type Integration, type IntegrationConfigBase, type IntegrationEnvironment, IntegrationManager, type IntegrationState, type IntegrationStatus, type IntegrationsConfig, type ManagerConfig, type PinterestEventMapping, type PinterestTagConfig, type PinterestTagIntegrationConfig, Saasco, type SocialProofInit, type StandardFacebookEvent, type StandardPinterestEvent, type StandardTikTokEvent, type SuperContext, type SupportChatInit, type TikTokEventMapping, type TikTokPixelConfig, type TikTokPixelIntegrationConfig, browserContextSchema, createFacebookPixelIntegration, createPinterestTagIntegration, createTikTokPixelIntegration, getBrowserContext, standardFacebookEvents, standardPinterestEvents, standardTikTokEvents, timezones };
514
+ export { type AnalyticsContext, type BrowserContext, BrowserContextSchema, type EventEnvelope, type EventType, type FacebookEventMapping, type FacebookPixelConfig, type FacebookPixelIntegrationConfig, type Integration, type IntegrationConfigBase, type IntegrationEnvironment, IntegrationManager, type IntegrationState, type IntegrationStatus, type IntegrationsConfig, type ManagerConfig, type PinterestEventMapping, type PinterestTagConfig, type PinterestTagIntegrationConfig, Saasco, type SocialProofInit, type StandardFacebookEvent, type StandardPinterestEvent, type StandardTikTokEvent, type SuperContext, type SupportInit, type TikTokEventMapping, type TikTokPixelConfig, type TikTokPixelIntegrationConfig, createFacebookPixelIntegration, createPinterestTagIntegration, createTikTokPixelIntegration, getBrowserContext, standardFacebookEvents, standardPinterestEvents, standardTikTokEvents, timezones };
package/dist/index.d.ts CHANGED
@@ -259,8 +259,8 @@ declare global {
259
259
  saascoAutoPageTrackingActive?: boolean;
260
260
  saasco: Saasco;
261
261
  saascoLastIdentifyKey?: string;
262
- /** Set once the lazy-loaded support-chat script has been injected. */
263
- __saascoSupportChatInjected?: boolean;
262
+ /** Set once the lazy-loaded support script has been injected. */
263
+ __saascoSupportInjected?: boolean;
264
264
  /** Set once the lazy-loaded social-proof loader script has been injected. */
265
265
  __saascoSocialProofInjected?: boolean;
266
266
  }
@@ -287,25 +287,30 @@ type DoRequestResponse = {
287
287
  };
288
288
  type IntegrationsConfig = (FacebookPixelIntegrationConfig | PinterestTagIntegrationConfig | TikTokPixelIntegrationConfig)[];
289
289
  /**
290
- * Opt-in config for the support chat widget, set on the `Saasco` constructor.
291
- * The widget is a cross-origin iframe loaded by a lean host-page loader
292
- * (`saasco-support-chat-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.
290
+ * Optional config for the support widget. Support is **always available
291
+ * wherever the analytics SDK runs** you don't need to pass this object at
292
+ * all. Whether the widget actually renders is decided **server-side**: on init
293
+ * the SDK runs a cheap `{ enabled }` check and lazily injects the lean loader
294
+ * (`saasco-support-loader.js`) only when the project has the widget enabled
295
+ * in the dashboard, so pages where it's off never download it — and the
296
+ * dashboard toggle controls every install (CDN and npm) uniformly.
297
+ *
298
+ * The loader origin is resolved automatically: the CDN `<script>` origin for
299
+ * CDN installs, else the public Saasco CDN for npm/bundled installs. Pass this
300
+ * object only to override those defaults: `baseUrl`/`scriptUrl` point a
301
+ * same-origin, proxied, or self-hosted install at the right origin.
302
+ * The projectId is shared from the analytics config — you never declare it
303
+ * twice.
297
304
  */
298
- type SupportChatInit = {
299
- /** Defaults to `true` when the `supportChat` object is provided. */
300
- enabled?: boolean;
301
- /** Origin of the saasco app hosting the support-chat API. Defaults server-side to where the widget bundle is served from. */
305
+ type SupportInit = {
306
+ /** Origin of the saasco app hosting the support API. Defaults server-side to where the widget bundle is served from. */
302
307
  baseUrl?: string;
303
308
  /** Input placeholder for the chat composer. */
304
309
  placeholder?: string;
305
310
  /**
306
311
  * URL the loader is loaded from. Accepts either the analytics
307
312
  * `saasco-sdk.js` URL (the loader URL is derived from it) or the
308
- * `saasco-support-chat-loader.js` URL directly. Defaults to deriving from the
313
+ * `saasco-support-loader.js` URL directly. Defaults to deriving from the
309
314
  * loaded analytics `<script>` tag, so CDN installs can omit it.
310
315
  */
311
316
  scriptUrl?: string;
@@ -323,19 +328,11 @@ type SupportChatInit = {
323
328
  * The loader + widget-payload origin is resolved automatically: the CDN
324
329
  * `<script>` origin for CDN installs, else the public Saasco CDN for
325
330
  * 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,
331
+ * only to override those defaults: `baseUrl`/`scriptUrl` point a same-origin,
329
332
  * proxied, or self-hosted install at the right origin. The projectId is shared
330
333
  * from the analytics config — you never declare it twice.
331
334
  */
332
335
  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
336
  /**
340
337
  * Origin of the saasco app hosting the social-proof widget-payload API.
341
338
  * Defaults to the loader bundle's origin — the CDN `<script>` origin for CDN
@@ -356,13 +353,13 @@ declare class Saasco {
356
353
  private isInitialized;
357
354
  private integrationManager;
358
355
  private logger;
359
- private lastSupportChatIdentity;
356
+ private lastSupportIdentity;
360
357
  /**
361
358
  * Creates an instance of the Saasco SDK.
362
359
  * @param config Configuration options.
363
360
  * @param config.projectId The unique identifier for the project.
364
361
  * @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.
362
+ * @param config.autoPageTracking Whether to automatically track page views. Default is true.
366
363
  * @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
364
  * @param config.debug Whether to log debug information. Default is false.
368
365
  * @param config.trackUrlParams Whether to track URL parameters. Default is true.
@@ -381,26 +378,12 @@ declare class Saasco {
381
378
  debug?: boolean;
382
379
  debugVerbose?: boolean;
383
380
  integrations?: IntegrationsConfig;
384
- supportChat?: SupportChatInit;
381
+ support?: SupportInit;
385
382
  socialProof?: SocialProofInit;
386
383
  });
387
384
  init(): void;
388
385
  disableDebug(): void;
389
386
  enableDebug(): void;
390
- /**
391
- * Enables and injects the support chat widget when it was constructed with
392
- * `supportChat: { enabled: false }`. Safe to call multiple times.
393
- */
394
- enableSupportChat(): 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
387
  /**
405
388
  * Initialize third-party integrations
406
389
  */
@@ -414,7 +397,7 @@ declare class Saasco {
414
397
  track(payload: TrackPayload): Promise<DoRequestResponse>;
415
398
  /**
416
399
  * 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"
400
+ * This records the page title and path and names the event using the reserved name "Page View"
418
401
  *
419
402
  * Before implementing this make sure you have disabled the autoPageTracking in the config or you will get duplicate page views
420
403
  */
@@ -465,33 +448,38 @@ declare class Saasco {
465
448
  readyCount: number;
466
449
  };
467
450
  /**
468
- * Lazily injects the support-chat **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.
451
+ * Lazily injects the support **loader** (server-gated). See
452
+ * {@link injectSupportLoader}. Replays identity once the script loads.
473
453
  */
474
- private injectSupportChat;
454
+ private injectSupport;
475
455
  /**
476
456
  * Lazily injects the social-proof loader (server-gated). See
477
457
  * {@link injectSocialProofLoader}.
478
458
  */
479
459
  private injectSocialProof;
480
460
  /**
481
- * Records the latest CRM identity and forwards it to the support-chat widget.
482
- * No-op when support chat isn't enabled.
461
+ * Records the latest CRM identity and forwards it to the support widget.
483
462
  */
484
- private updateSupportChatIdentity;
463
+ private updateSupportIdentity;
485
464
  /**
486
- * Pushes the current identity onto `window.SaascoSupportChat.identify`. The
465
+ * Pushes the current identity onto `window.SaascoSupport.identify`. The
487
466
  * 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.
467
+ * it (same approach as tool registration). `injectSupport` calls this on
468
+ * script load (or immediately when the loader is already present).
490
469
  */
491
- private pushSupportChatIdentity;
470
+ private pushSupportIdentity;
492
471
  }
493
472
 
494
- declare const browserContextSchema: z.ZodObject<{
473
+ /**
474
+ * Browser-collected context attached to track payloads by `getBrowserContext()`.
475
+ *
476
+ * Defined here rather than in `libs/analytics/sdk` because server and worker
477
+ * code validates it too. The SDK re-exports it, so `saasco-sdk`'s public API is
478
+ * unchanged — but a shared module importing the SDK barrel would drag the whole
479
+ * DOM-dependent bundle into every consumer's program, including the Cloudflare
480
+ * Worker, which has no DOM lib.
481
+ */
482
+ declare const BrowserContextSchema: z.ZodObject<{
495
483
  $href: z.ZodString;
496
484
  $locale: z.ZodString;
497
485
  $location: z.ZodString;
@@ -516,11 +504,11 @@ declare const browserContextSchema: z.ZodObject<{
516
504
  $utmSourcePlatform: z.ZodNullable<z.ZodString>;
517
505
  $utmTerm: z.ZodNullable<z.ZodString>;
518
506
  }, z.core.$strip>;
519
- type BrowserContext = z.infer<typeof browserContextSchema>;
507
+ type BrowserContext = z.infer<typeof BrowserContextSchema>;
520
508
  type SuperContext = Record<string, unknown>;
521
509
 
522
510
  declare function getBrowserContext(): BrowserContext;
523
511
 
524
512
  declare const timezones: Record<string, string>;
525
513
 
526
- export { type AnalyticsContext, type BrowserContext, type EventEnvelope, type EventType, type FacebookEventMapping, type FacebookPixelConfig, type FacebookPixelIntegrationConfig, type Integration, type IntegrationConfigBase, type IntegrationEnvironment, IntegrationManager, type IntegrationState, type IntegrationStatus, type IntegrationsConfig, type ManagerConfig, type PinterestEventMapping, type PinterestTagConfig, type PinterestTagIntegrationConfig, Saasco, type SocialProofInit, type StandardFacebookEvent, type StandardPinterestEvent, type StandardTikTokEvent, type SuperContext, type SupportChatInit, type TikTokEventMapping, type TikTokPixelConfig, type TikTokPixelIntegrationConfig, browserContextSchema, createFacebookPixelIntegration, createPinterestTagIntegration, createTikTokPixelIntegration, getBrowserContext, standardFacebookEvents, standardPinterestEvents, standardTikTokEvents, timezones };
514
+ export { type AnalyticsContext, type BrowserContext, BrowserContextSchema, type EventEnvelope, type EventType, type FacebookEventMapping, type FacebookPixelConfig, type FacebookPixelIntegrationConfig, type Integration, type IntegrationConfigBase, type IntegrationEnvironment, IntegrationManager, type IntegrationState, type IntegrationStatus, type IntegrationsConfig, type ManagerConfig, type PinterestEventMapping, type PinterestTagConfig, type PinterestTagIntegrationConfig, Saasco, type SocialProofInit, type StandardFacebookEvent, type StandardPinterestEvent, type StandardTikTokEvent, type SuperContext, type SupportInit, type TikTokEventMapping, type TikTokPixelConfig, type TikTokPixelIntegrationConfig, createFacebookPixelIntegration, createPinterestTagIntegration, createTikTokPixelIntegration, getBrowserContext, standardFacebookEvents, standardPinterestEvents, standardTikTokEvents, timezones };