posthog-js 1.232.6 → 1.232.7

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.
Files changed (42) hide show
  1. package/dist/all-external-dependencies.js.map +1 -1
  2. package/dist/array.full.es5.js +1 -1
  3. package/dist/array.full.es5.js.map +1 -1
  4. package/dist/array.full.js +1 -1
  5. package/dist/array.full.js.map +1 -1
  6. package/dist/array.full.no-external.js +1 -1
  7. package/dist/array.full.no-external.js.map +1 -1
  8. package/dist/array.js +1 -1
  9. package/dist/array.js.map +1 -1
  10. package/dist/array.no-external.js +1 -1
  11. package/dist/array.no-external.js.map +1 -1
  12. package/dist/customizations.full.js +1 -1
  13. package/dist/main.js +1 -1
  14. package/dist/main.js.map +1 -1
  15. package/dist/module.d.ts +29 -1
  16. package/dist/module.full.d.ts +29 -1
  17. package/dist/module.full.js +1 -1
  18. package/dist/module.full.js.map +1 -1
  19. package/dist/module.full.no-external.d.ts +29 -1
  20. package/dist/module.full.no-external.js +1 -1
  21. package/dist/module.full.no-external.js.map +1 -1
  22. package/dist/module.js +1 -1
  23. package/dist/module.js.map +1 -1
  24. package/dist/module.no-external.d.ts +29 -1
  25. package/dist/module.no-external.js +1 -1
  26. package/dist/module.no-external.js.map +1 -1
  27. package/dist/src/posthog-core.d.ts +1 -0
  28. package/dist/src/posthog-surveys-types.d.ts +4 -1
  29. package/dist/src/posthog-surveys.d.ts +24 -0
  30. package/dist/surveys-preview.d.ts +29 -1
  31. package/dist/surveys-preview.js.map +1 -1
  32. package/dist/surveys.js.map +1 -1
  33. package/lib/package.json +1 -1
  34. package/lib/src/posthog-core.d.ts +1 -0
  35. package/lib/src/posthog-core.js +17 -0
  36. package/lib/src/posthog-core.js.map +1 -1
  37. package/lib/src/posthog-surveys-types.d.ts +4 -1
  38. package/lib/src/posthog-surveys-types.js.map +1 -1
  39. package/lib/src/posthog-surveys.d.ts +24 -0
  40. package/lib/src/posthog-surveys.js +104 -6
  41. package/lib/src/posthog-surveys.js.map +1 -1
  42. package/package.json +1 -1
@@ -267,6 +267,7 @@ export declare class PostHog {
267
267
  */
268
268
  on(event: 'eventCaptured', cb: (...args: any[]) => void): () => void;
269
269
  onFeatureFlags(callback: FeatureFlagsCallback): () => void;
270
+ onSurveysLoaded(callback: SurveyCallback): () => void;
270
271
  onSessionId(callback: SessionIdChangedCallback): () => void;
271
272
  /** Get list of all surveys. */
272
273
  getSurveys(callback: SurveyCallback, forceReload?: boolean): void;
@@ -100,7 +100,10 @@ interface SpecificQuestionBranching {
100
100
  export interface SurveyResponse {
101
101
  surveys: Survey[];
102
102
  }
103
- export type SurveyCallback = (surveys: Survey[]) => void;
103
+ export type SurveyCallback = (surveys: Survey[], context?: {
104
+ isLoaded: boolean;
105
+ error?: string;
106
+ }) => void;
104
107
  export type SurveyMatchType = 'regex' | 'not_regex' | 'exact' | 'is_not' | 'icontains' | 'not_icontains';
105
108
  export interface SurveyElement {
106
109
  text?: string;
@@ -12,11 +12,35 @@ export declare class PostHogSurveys {
12
12
  private _surveyManager;
13
13
  private _isFetchingSurveys;
14
14
  private _isInitializingSurveys;
15
+ private _surveyCallbacks;
15
16
  constructor(instance: PostHog);
16
17
  onRemoteConfig(response: RemoteConfig): void;
17
18
  reset(): void;
18
19
  loadIfEnabled(): void;
20
+ /**
21
+ * Register a callback that runs when surveys are initialized.
22
+ * ### Usage:
23
+ *
24
+ * posthog.onSurveysLoaded((surveys) => {
25
+ * // You can work with all surveys
26
+ * console.log('All available surveys:', surveys)
27
+ *
28
+ * // Or get active matching surveys
29
+ * posthog.getActiveMatchingSurveys((activeMatchingSurveys) => {
30
+ * if (activeMatchingSurveys.length > 0) {
31
+ * posthog.renderSurvey(activeMatchingSurveys[0].id, '#survey-container')
32
+ * }
33
+ * })
34
+ * })
35
+ *
36
+ * @param {Function} callback The callback function will be called when surveys are loaded or updated.
37
+ * It receives the array of all surveys and a context object with error status.
38
+ * @returns {Function} A function that can be called to unsubscribe the listener.
39
+ */
40
+ onSurveysLoaded(callback: SurveyCallback): () => void;
19
41
  getSurveys(callback: SurveyCallback, forceReload?: boolean): void;
42
+ /** Helper method to notify all registered callbacks */
43
+ private _notifySurveyCallbacks;
20
44
  private isSurveyFeatureFlagEnabled;
21
45
  getActiveMatchingSurveys(callback: SurveyCallback, forceReload?: boolean): void;
22
46
  checkFlags(survey: Survey): boolean;
@@ -2073,7 +2073,10 @@ interface SpecificQuestionBranching {
2073
2073
  type: SurveyQuestionBranchingType.SpecificQuestion;
2074
2074
  index: number;
2075
2075
  }
2076
- type SurveyCallback = (surveys: Survey[]) => void;
2076
+ type SurveyCallback = (surveys: Survey[], context?: {
2077
+ isLoaded: boolean;
2078
+ error?: string;
2079
+ }) => void;
2077
2080
  type SurveyMatchType = 'regex' | 'not_regex' | 'exact' | 'is_not' | 'icontains' | 'not_icontains';
2078
2081
  declare enum SurveySchedule {
2079
2082
  Once = "once",
@@ -2186,11 +2189,35 @@ declare class PostHogSurveys {
2186
2189
  private _surveyManager;
2187
2190
  private _isFetchingSurveys;
2188
2191
  private _isInitializingSurveys;
2192
+ private _surveyCallbacks;
2189
2193
  constructor(instance: PostHog);
2190
2194
  onRemoteConfig(response: RemoteConfig): void;
2191
2195
  reset(): void;
2192
2196
  loadIfEnabled(): void;
2197
+ /**
2198
+ * Register a callback that runs when surveys are initialized.
2199
+ * ### Usage:
2200
+ *
2201
+ * posthog.onSurveysLoaded((surveys) => {
2202
+ * // You can work with all surveys
2203
+ * console.log('All available surveys:', surveys)
2204
+ *
2205
+ * // Or get active matching surveys
2206
+ * posthog.getActiveMatchingSurveys((activeMatchingSurveys) => {
2207
+ * if (activeMatchingSurveys.length > 0) {
2208
+ * posthog.renderSurvey(activeMatchingSurveys[0].id, '#survey-container')
2209
+ * }
2210
+ * })
2211
+ * })
2212
+ *
2213
+ * @param {Function} callback The callback function will be called when surveys are loaded or updated.
2214
+ * It receives the array of all surveys and a context object with error status.
2215
+ * @returns {Function} A function that can be called to unsubscribe the listener.
2216
+ */
2217
+ onSurveysLoaded(callback: SurveyCallback): () => void;
2193
2218
  getSurveys(callback: SurveyCallback, forceReload?: boolean): void;
2219
+ /** Helper method to notify all registered callbacks */
2220
+ private _notifySurveyCallbacks;
2194
2221
  private isSurveyFeatureFlagEnabled;
2195
2222
  getActiveMatchingSurveys(callback: SurveyCallback, forceReload?: boolean): void;
2196
2223
  checkFlags(survey: Survey): boolean;
@@ -2627,6 +2654,7 @@ declare class PostHog {
2627
2654
  */
2628
2655
  on(event: 'eventCaptured', cb: (...args: any[]) => void): () => void;
2629
2656
  onFeatureFlags(callback: FeatureFlagsCallback): () => void;
2657
+ onSurveysLoaded(callback: SurveyCallback): () => void;
2630
2658
  onSessionId(callback: SessionIdChangedCallback): () => void;
2631
2659
  /** Get list of all surveys. */
2632
2660
  getSurveys(callback: SurveyCallback, forceReload?: boolean): void;