posthog-js-lite 3.5.1 → 4.0.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/lib/index.d.ts CHANGED
@@ -50,8 +50,8 @@ type PostHogCoreOptions = {
50
50
  remoteConfigRequestTimeoutMs?: number;
51
51
  /** For Session Analysis how long before we expire a session (defaults to 30 mins) */
52
52
  sessionExpirationTimeSeconds?: number;
53
- /** Whether to post events to PostHog in JSON or compressed format. Defaults to 'json' */
54
- captureMode?: 'json' | 'form';
53
+ /** Whether to disable GZIP compression */
54
+ disableCompression?: boolean;
55
55
  disableGeoip?: boolean;
56
56
  /** Special flag to indicate ingested data is for a historical migration. */
57
57
  historicalMigration?: boolean;
@@ -70,6 +70,7 @@ declare enum PostHogPersistedProperty {
70
70
  Queue = "queue",
71
71
  OptedOut = "opted_out",
72
72
  SessionId = "session_id",
73
+ SessionStartTimestamp = "session_start_timestamp",
73
74
  SessionLastTimestamp = "session_timestamp",
74
75
  PersonProperties = "person_properties",
75
76
  GroupProperties = "group_properties",
@@ -89,7 +90,7 @@ type PostHogFetchOptions = {
89
90
  headers: {
90
91
  [key: string]: string;
91
92
  };
92
- body?: string;
93
+ body?: string | Blob;
93
94
  signal?: AbortSignal;
94
95
  };
95
96
  type PostHogCaptureOptions = {
@@ -105,7 +106,10 @@ type PostHogFetchResponse = {
105
106
  json: () => Promise<any>;
106
107
  };
107
108
  type PostHogEventProperties = {
108
- [key: string]: any;
109
+ [key: string]: JsonType;
110
+ };
111
+ type PostHogGroupProperties = {
112
+ [type: string]: string | number;
109
113
  };
110
114
  type PostHogAutocaptureElement = {
111
115
  $el_text?: string;
@@ -114,13 +118,19 @@ type PostHogAutocaptureElement = {
114
118
  nth_child?: number;
115
119
  nth_of_type?: number;
116
120
  order?: number;
117
- } & {
118
- [key: string]: any;
119
- };
121
+ } & PostHogEventProperties;
122
+ declare enum Compression {
123
+ GZipJS = "gzip-js",
124
+ Base64 = "base64"
125
+ }
120
126
  type PostHogRemoteConfig = {
121
127
  sessionRecording?: boolean | {
122
128
  [key: string]: JsonType;
123
129
  };
130
+ /**
131
+ * Supported compression algorithms
132
+ */
133
+ supportedCompression?: Compression[];
124
134
  /**
125
135
  * Whether surveys are enabled
126
136
  */
@@ -182,7 +192,7 @@ type PartialWithRequired<T, K extends keyof T> = {
182
192
  type PostHogFeatureFlagDetails = PartialWithRequired<PostHogDecideResponse, 'flags' | 'featureFlags' | 'featureFlagPayloads' | 'requestId'>;
183
193
  type JsonType = string | number | boolean | null | {
184
194
  [key: string]: JsonType;
185
- } | Array<JsonType>;
195
+ } | Array<JsonType> | JsonType[];
186
196
  type FeatureFlagDetail = {
187
197
  key: string;
188
198
  enabled: boolean;
@@ -366,8 +376,6 @@ declare enum ActionStepStringMatching {
366
376
  type ActionStepType = {
367
377
  event?: string;
368
378
  selector?: string;
369
- /** @deprecated Only `selector` should be used now. */
370
- tag_name?: string;
371
379
  text?: string;
372
380
  /** @default StringMatching.Exact */
373
381
  text_matching?: ActionStepStringMatching;
@@ -408,11 +416,11 @@ declare abstract class PostHogCoreStateless {
408
416
  private requestTimeout;
409
417
  private featureFlagsRequestTimeoutMs;
410
418
  private remoteConfigRequestTimeoutMs;
411
- private captureMode;
412
419
  private removeDebugCallback?;
413
420
  private disableGeoip;
414
421
  private historicalMigration;
415
422
  protected disabled: boolean;
423
+ protected disableCompression: boolean;
416
424
  private defaultOptIn;
417
425
  private pendingPromises;
418
426
  protected _events: SimpleEventEmitter;
@@ -430,7 +438,7 @@ declare abstract class PostHogCoreStateless {
430
438
  constructor(apiKey: string, options?: PostHogCoreOptions);
431
439
  protected logMsgIfDebug(fn: () => void): void;
432
440
  protected wrap(fn: () => void): void;
433
- protected getCommonEventProperties(): any;
441
+ protected getCommonEventProperties(): PostHogEventProperties;
434
442
  get optedOut(): boolean;
435
443
  optIn(): Promise<void>;
436
444
  optOut(): Promise<void>;
@@ -445,18 +453,10 @@ declare abstract class PostHogCoreStateless {
445
453
  ***/
446
454
  protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
447
455
  protected identifyStatelessImmediate(distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): Promise<void>;
448
- protected captureStateless(distinctId: string, event: string, properties?: {
449
- [key: string]: any;
450
- }, options?: PostHogCaptureOptions): void;
451
- protected captureStatelessImmediate(distinctId: string, event: string, properties?: {
452
- [key: string]: any;
453
- }, options?: PostHogCaptureOptions): Promise<void>;
454
- protected aliasStateless(alias: string, distinctId: string, properties?: {
455
- [key: string]: any;
456
- }, options?: PostHogCaptureOptions): void;
457
- protected aliasStatelessImmediate(alias: string, distinctId: string, properties?: {
458
- [key: string]: any;
459
- }, options?: PostHogCaptureOptions): Promise<void>;
456
+ protected captureStateless(distinctId: string, event: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
457
+ protected captureStatelessImmediate(distinctId: string, event: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): Promise<void>;
458
+ protected aliasStateless(alias: string, distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
459
+ protected aliasStatelessImmediate(alias: string, distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): Promise<void>;
460
460
  /***
461
461
  *** GROUPS
462
462
  ***/
@@ -497,9 +497,7 @@ declare abstract class PostHogCoreStateless {
497
497
  private _props;
498
498
  protected get props(): PostHogEventProperties;
499
499
  protected set props(val: PostHogEventProperties | undefined);
500
- register(properties: {
501
- [key: string]: any;
502
- }): Promise<void>;
500
+ register(properties: PostHogEventProperties): Promise<void>;
503
501
  unregister(property: string): Promise<void>;
504
502
  /***
505
503
  *** QUEUEING AND FLUSHING
@@ -513,7 +511,29 @@ declare abstract class PostHogCoreStateless {
513
511
  * Avoids unnecessary promise errors
514
512
  */
515
513
  private flushBackground;
516
- flush(): Promise<any[]>;
514
+ /**
515
+ * Flushes the queue
516
+ *
517
+ * This function will return a promise that will resolve when the flush is complete,
518
+ * or reject if there was an error (for example if the server or network is down).
519
+ *
520
+ * If there is already a flush in progress, this function will wait for that flush to complete.
521
+ *
522
+ * It's recommended to do error handling in the callback of the promise.
523
+ *
524
+ * @example
525
+ * posthog.flush().then(() => {
526
+ * console.log('Flush complete')
527
+ * }).catch((err) => {
528
+ * console.error('Flush failed', err)
529
+ * })
530
+ *
531
+ *
532
+ * @throws PostHogFetchHttpError
533
+ * @throws PostHogFetchNetworkError
534
+ * @throws Error
535
+ */
536
+ flush(): Promise<void>;
517
537
  protected getCustomHeaders(): {
518
538
  [key: string]: string;
519
539
  };
@@ -532,13 +552,14 @@ declare abstract class PostHogCore extends PostHogCoreStateless {
532
552
  private flagCallReported;
533
553
  protected _decideResponsePromise?: Promise<PostHogDecideResponse | undefined>;
534
554
  protected _sessionExpirationTimeSeconds: number;
555
+ private _sessionMaxLengthSeconds;
535
556
  protected sessionProps: PostHogEventProperties;
536
557
  constructor(apiKey: string, options?: PostHogCoreOptions);
537
558
  protected setupBootstrap(options?: Partial<PostHogCoreOptions>): void;
538
559
  private clearProps;
539
560
  on(event: string, cb: (...args: any[]) => void): () => void;
540
561
  reset(propertiesToKeep?: PostHogPersistedProperty[]): void;
541
- protected getCommonEventProperties(): any;
562
+ protected getCommonEventProperties(): PostHogEventProperties;
542
563
  private enrichProperties;
543
564
  /**
544
565
  * * @returns {string} The stored session ID for the current session. This may be an empty string if the client is not yet fully initialized.
@@ -553,25 +574,19 @@ declare abstract class PostHogCore extends PostHogCoreStateless {
553
574
  * * @returns {string} The stored distinct ID. This may be an empty string if the client is not yet fully initialized.
554
575
  */
555
576
  getDistinctId(): string;
556
- registerForSession(properties: {
557
- [key: string]: any;
558
- }): void;
577
+ registerForSession(properties: PostHogEventProperties): void;
559
578
  unregisterForSession(property: string): void;
560
579
  /***
561
580
  *** TRACKING
562
581
  ***/
563
582
  identify(distinctId?: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
564
- capture(event: string, properties?: {
565
- [key: string]: any;
566
- }, options?: PostHogCaptureOptions): void;
583
+ capture(event: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
567
584
  alias(alias: string): void;
568
585
  autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
569
586
  /***
570
587
  *** GROUPS
571
588
  ***/
572
- groups(groups: {
573
- [type: string]: string | number;
574
- }): void;
589
+ groups(groups: PostHogGroupProperties): void;
575
590
  group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
576
591
  groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
577
592
  /***
@@ -581,18 +596,10 @@ declare abstract class PostHogCore extends PostHogCoreStateless {
581
596
  [type: string]: string;
582
597
  }): void;
583
598
  resetPersonPropertiesForFlags(): void;
584
- /** @deprecated - Renamed to setPersonPropertiesForFlags */
585
- personProperties(properties: {
586
- [type: string]: string;
587
- }): void;
588
599
  setGroupPropertiesForFlags(properties: {
589
600
  [type: string]: Record<string, string>;
590
601
  }): void;
591
602
  resetGroupPropertiesForFlags(): void;
592
- /** @deprecated - Renamed to setGroupPropertiesForFlags */
593
- groupProperties(properties: {
594
- [type: string]: Record<string, string>;
595
- }): void;
596
603
  private remoteConfigAsync;
597
604
  /***
598
605
  *** FEATURE FLAGS
@@ -603,7 +610,7 @@ declare abstract class PostHogCore extends PostHogCoreStateless {
603
610
  private _decideAsync;
604
611
  private setKnownFeatureFlagDetails;
605
612
  private getKnownFeatureFlagDetails;
606
- private getKnownFeatureFlags;
613
+ protected getKnownFeatureFlags(): PostHogDecideResponse['featureFlags'] | undefined;
607
614
  private getKnownFeatureFlagPayloads;
608
615
  private getBootstrappedFeatureFlagDetails;
609
616
  private setBootstrappedFeatureFlagDetails;
@@ -628,9 +635,7 @@ declare abstract class PostHogCore extends PostHogCoreStateless {
628
635
  /***
629
636
  *** ERROR TRACKING
630
637
  ***/
631
- captureException(error: unknown, additionalProperties?: {
632
- [key: string]: any;
633
- }): void;
638
+ captureException(error: unknown, additionalProperties?: PostHogEventProperties): void;
634
639
  /**
635
640
  * Capture written user feedback for a LLM trace. Numeric values are converted to strings.
636
641
  * @param traceId The trace ID to capture feedback for.
@@ -666,7 +671,7 @@ declare class PostHog extends PostHogCore {
666
671
  getLibraryId(): string;
667
672
  getLibraryVersion(): string;
668
673
  getCustomUserAgent(): void;
669
- getCommonEventProperties(): any;
674
+ getCommonEventProperties(): PostHogEventProperties;
670
675
  private setupHistoryEventTracking;
671
676
  private captureNavigationEvent;
672
677
  }