posthog-js 1.76.0 → 1.77.1

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 (129) hide show
  1. package/dist/array.full.js +2 -2
  2. package/dist/array.full.js.map +1 -1
  3. package/dist/array.js +2 -2
  4. package/dist/array.js.map +1 -1
  5. package/dist/es.js +2 -2
  6. package/dist/es.js.map +1 -1
  7. package/dist/module.d.ts +38 -6
  8. package/dist/module.js +2 -2
  9. package/dist/module.js.map +1 -1
  10. package/lib/package.json +8 -6
  11. package/lib/src/autocapture-utils.d.ts +15 -0
  12. package/lib/src/autocapture-utils.js +303 -0
  13. package/lib/src/autocapture-utils.js.map +1 -0
  14. package/lib/src/autocapture.d.ts +27 -0
  15. package/lib/src/autocapture.js +290 -0
  16. package/lib/src/autocapture.js.map +1 -0
  17. package/lib/src/base-request-queue.d.ts +12 -0
  18. package/lib/src/base-request-queue.js +33 -0
  19. package/lib/src/base-request-queue.js.map +1 -0
  20. package/lib/src/compression.d.ts +3 -0
  21. package/lib/src/compression.js +35 -0
  22. package/lib/src/compression.js.map +1 -0
  23. package/lib/src/config.d.ts +5 -0
  24. package/lib/src/config.js +9 -0
  25. package/lib/src/config.js.map +1 -0
  26. package/lib/src/constants.d.ts +19 -0
  27. package/lib/src/constants.js +41 -0
  28. package/lib/src/constants.js.map +1 -0
  29. package/lib/src/decide.d.ts +8 -0
  30. package/lib/src/decide.js +118 -0
  31. package/lib/src/decide.js.map +1 -0
  32. package/lib/src/extensions/cloud.d.ts +1 -0
  33. package/lib/src/extensions/cloud.js +2 -0
  34. package/lib/src/extensions/cloud.js.map +1 -0
  35. package/lib/src/extensions/exceptions/error-conversion.d.ts +26 -0
  36. package/lib/src/extensions/exceptions/error-conversion.js +204 -0
  37. package/lib/src/extensions/exceptions/error-conversion.js.map +1 -0
  38. package/lib/src/extensions/exceptions/exception-autocapture.d.ts +24 -0
  39. package/lib/src/extensions/exceptions/exception-autocapture.js +164 -0
  40. package/lib/src/extensions/exceptions/exception-autocapture.js.map +1 -0
  41. package/lib/src/extensions/exceptions/stack-trace.d.ts +31 -0
  42. package/lib/src/extensions/exceptions/stack-trace.js +259 -0
  43. package/lib/src/extensions/exceptions/stack-trace.js.map +1 -0
  44. package/lib/src/extensions/exceptions/type-checking.d.ts +10 -0
  45. package/lib/src/extensions/exceptions/type-checking.js +43 -0
  46. package/lib/src/extensions/exceptions/type-checking.js.map +1 -0
  47. package/lib/src/extensions/rageclick.d.ts +10 -0
  48. package/lib/src/extensions/rageclick.js +33 -0
  49. package/lib/src/extensions/rageclick.js.map +1 -0
  50. package/lib/src/extensions/segment-integration.d.ts +44 -0
  51. package/lib/src/extensions/segment-integration.js +34 -0
  52. package/lib/src/extensions/segment-integration.js.map +1 -0
  53. package/lib/src/extensions/sentry-integration.d.ts +30 -0
  54. package/lib/src/extensions/sentry-integration.js +63 -0
  55. package/lib/src/extensions/sentry-integration.js.map +1 -0
  56. package/lib/src/extensions/sessionrecording-utils.d.ts +67 -0
  57. package/lib/src/extensions/sessionrecording-utils.js +192 -0
  58. package/lib/src/extensions/sessionrecording-utils.js.map +1 -0
  59. package/lib/src/extensions/sessionrecording.d.ts +45 -0
  60. package/lib/src/extensions/sessionrecording.js +430 -0
  61. package/lib/src/extensions/sessionrecording.js.map +1 -0
  62. package/lib/src/extensions/toolbar.d.ts +18 -0
  63. package/lib/src/extensions/toolbar.js +151 -0
  64. package/lib/src/extensions/toolbar.js.map +1 -0
  65. package/lib/src/extensions/web-performance.d.ts +20 -0
  66. package/lib/src/extensions/web-performance.js +245 -0
  67. package/lib/src/extensions/web-performance.js.map +1 -0
  68. package/lib/src/gdpr-utils.d.ts +80 -0
  69. package/lib/src/gdpr-utils.js +236 -0
  70. package/lib/src/gdpr-utils.js.map +1 -0
  71. package/lib/src/loader-globals-full.d.ts +1 -0
  72. package/lib/src/loader-globals-full.js +5 -0
  73. package/lib/src/loader-globals-full.js.map +1 -0
  74. package/lib/src/loader-globals.d.ts +1 -0
  75. package/lib/src/loader-globals.js +3 -0
  76. package/lib/src/loader-globals.js.map +1 -0
  77. package/lib/src/loader-module.d.ts +4 -0
  78. package/lib/src/loader-module.js +6 -0
  79. package/lib/src/loader-module.js.map +1 -0
  80. package/lib/src/loader-recorder-v2.d.ts +2 -0
  81. package/lib/src/loader-recorder-v2.js +15 -0
  82. package/lib/src/loader-recorder-v2.js.map +1 -0
  83. package/lib/src/loader-recorder.d.ts +2 -0
  84. package/lib/src/loader-recorder.js +15 -0
  85. package/lib/src/loader-recorder.js.map +1 -0
  86. package/lib/src/page-view.d.ts +38 -0
  87. package/lib/src/page-view.js +127 -0
  88. package/lib/src/page-view.js.map +1 -0
  89. package/lib/src/posthog-core.d.ts +701 -0
  90. package/lib/src/posthog-core.js +1916 -0
  91. package/lib/src/posthog-core.js.map +1 -0
  92. package/lib/src/posthog-featureflags.d.ts +70 -0
  93. package/lib/src/posthog-featureflags.js +438 -0
  94. package/lib/src/posthog-featureflags.js.map +1 -0
  95. package/lib/src/posthog-persistence.d.ts +57 -0
  96. package/lib/src/posthog-persistence.js +256 -0
  97. package/lib/src/posthog-persistence.js.map +1 -0
  98. package/lib/src/posthog-surveys.d.ts +57 -0
  99. package/lib/src/posthog-surveys.js +76 -0
  100. package/lib/src/posthog-surveys.js.map +1 -0
  101. package/lib/src/rate-limiter.d.ts +5 -0
  102. package/lib/src/rate-limiter.js +66 -0
  103. package/lib/src/rate-limiter.js.map +1 -0
  104. package/lib/src/request-queue.d.ts +10 -0
  105. package/lib/src/request-queue.js +146 -0
  106. package/lib/src/request-queue.js.map +1 -0
  107. package/lib/src/retry-queue.d.ts +28 -0
  108. package/lib/src/retry-queue.js +198 -0
  109. package/lib/src/retry-queue.js.map +1 -0
  110. package/lib/src/send-request.d.ts +6 -0
  111. package/lib/src/send-request.js +125 -0
  112. package/lib/src/send-request.js.map +1 -0
  113. package/lib/src/sessionid.d.ts +28 -0
  114. package/lib/src/sessionid.js +205 -0
  115. package/lib/src/sessionid.js.map +1 -0
  116. package/lib/src/storage.d.ts +7 -0
  117. package/lib/src/storage.js +291 -0
  118. package/lib/src/storage.js.map +1 -0
  119. package/lib/src/types.d.ts +294 -0
  120. package/lib/src/types.js +6 -0
  121. package/lib/src/types.js.map +1 -0
  122. package/lib/src/utils.d.ts +89 -0
  123. package/lib/src/utils.js +868 -0
  124. package/lib/src/utils.js.map +1 -0
  125. package/lib/src/uuidv7.d.ts +42 -0
  126. package/lib/src/uuidv7.js +228 -0
  127. package/lib/src/uuidv7.js.map +1 -0
  128. package/package.json +8 -6
  129. package/CHANGELOG.md +0 -1145
@@ -0,0 +1,294 @@
1
+ import type { MaskInputOptions, SlimDOMOptions } from 'rrweb-snapshot';
2
+ import { PostHog } from './posthog-core';
3
+ import { RetryQueue } from './retry-queue';
4
+ export declare type Property = any;
5
+ export declare type Properties = Record<string, Property>;
6
+ export interface CaptureResult {
7
+ uuid: string;
8
+ event: string;
9
+ properties: Properties;
10
+ $set?: Properties;
11
+ $set_once?: Properties;
12
+ timestamp?: Date;
13
+ }
14
+ export declare type CaptureCallback = (response: any, data: any) => void;
15
+ export declare type AutocaptureCompatibleElement = 'a' | 'button' | 'form' | 'input' | 'select' | 'textarea' | 'label';
16
+ export declare type DomAutocaptureEvents = 'click' | 'change' | 'submit';
17
+ /**
18
+ * If an array is passed for an allowlist, autocapture events will only be sent for elements matching
19
+ * at least one of the elements in the array. Multiple allowlists can be used
20
+ */
21
+ export interface AutocaptureConfig {
22
+ /**
23
+ * List of URLs to allow autocapture on, can be strings to match
24
+ * or regexes e.g. ['https://example.com', 'test.com/.*']
25
+ */
26
+ url_allowlist?: (string | RegExp)[];
27
+ /**
28
+ * List of DOM events to allow autocapture on e.g. ['click', 'change', 'submit']
29
+ */
30
+ dom_event_allowlist?: DomAutocaptureEvents[];
31
+ /**
32
+ * List of DOM elements to allow autocapture on
33
+ * e.g. ['a', 'button', 'form', 'input', 'select', 'textarea', 'label']
34
+ */
35
+ element_allowlist?: AutocaptureCompatibleElement[];
36
+ /**
37
+ * List of CSS selectors to allow autocapture on
38
+ * e.g. ['[ph-capture]']
39
+ */
40
+ css_selector_allowlist?: string[];
41
+ }
42
+ export declare type UUIDVersion = 'og' | 'v7';
43
+ export interface PostHogConfig {
44
+ api_host: string;
45
+ api_method: string;
46
+ api_transport: string;
47
+ ui_host: string | null;
48
+ token: string;
49
+ autocapture: boolean | AutocaptureConfig;
50
+ rageclick: boolean;
51
+ cross_subdomain_cookie: boolean;
52
+ persistence: 'localStorage' | 'cookie' | 'memory' | 'localStorage+cookie' | 'sessionStorage';
53
+ persistence_name: string;
54
+ cookie_name: string;
55
+ loaded: (posthog_instance: PostHog) => void;
56
+ store_google: boolean;
57
+ custom_campaign_params: string[];
58
+ save_referrer: boolean;
59
+ test: boolean;
60
+ verbose: boolean;
61
+ capture_pageview: boolean;
62
+ capture_pageleave: boolean;
63
+ debug: boolean;
64
+ cookie_expiration: number;
65
+ upgrade: boolean;
66
+ disable_session_recording: boolean;
67
+ disable_persistence: boolean;
68
+ disable_cookie: boolean;
69
+ enable_recording_console_log?: boolean;
70
+ secure_cookie: boolean;
71
+ ip: boolean;
72
+ opt_out_capturing_by_default: boolean;
73
+ opt_out_persistence_by_default: boolean;
74
+ opt_out_capturing_persistence_type: 'localStorage' | 'cookie';
75
+ opt_out_capturing_cookie_prefix: string | null;
76
+ opt_in_site_apps: boolean;
77
+ respect_dnt: boolean;
78
+ property_blacklist: string[];
79
+ xhr_headers: {
80
+ [header_name: string]: string;
81
+ };
82
+ on_xhr_error: (failedRequest: XMLHttpRequest) => void;
83
+ inapp_protocol: string;
84
+ inapp_link_new_window: boolean;
85
+ request_batching: boolean;
86
+ sanitize_properties: ((properties: Properties, event_name: string) => Properties) | null;
87
+ properties_string_max_length: number;
88
+ session_recording: SessionRecordingOptions;
89
+ session_idle_timeout_seconds: number;
90
+ mask_all_element_attributes: boolean;
91
+ mask_all_text: boolean;
92
+ advanced_disable_decide: boolean;
93
+ advanced_disable_feature_flags: boolean;
94
+ advanced_disable_feature_flags_on_first_load: boolean;
95
+ advanced_disable_toolbar_metrics: boolean;
96
+ get_device_id: (uuid: string) => string;
97
+ name: string;
98
+ callback_fn: string;
99
+ _onCapture: (eventName: string, eventData: CaptureResult) => void;
100
+ capture_performance?: boolean;
101
+ disable_compression: boolean;
102
+ bootstrap: {
103
+ distinctID?: string;
104
+ isIdentifiedID?: boolean;
105
+ featureFlags?: Record<string, boolean | string>;
106
+ featureFlagPayloads?: Record<string, JsonType>;
107
+ };
108
+ segment?: any;
109
+ __preview_measure_pageview_stats?: boolean;
110
+ }
111
+ export interface OptInOutCapturingOptions {
112
+ capture: (event: string, properties: Properties, options: CaptureOptions) => void;
113
+ capture_event_name: string;
114
+ capture_properties: Properties;
115
+ enable_persistence: boolean;
116
+ clear_persistence: boolean;
117
+ persistence_type: 'cookie' | 'localStorage' | 'localStorage+cookie';
118
+ cookie_prefix: string;
119
+ cookie_expiration: number;
120
+ cross_subdomain_cookie: boolean;
121
+ secure_cookie: boolean;
122
+ }
123
+ export interface isFeatureEnabledOptions {
124
+ send_event: boolean;
125
+ }
126
+ export interface SessionRecordingOptions {
127
+ blockClass?: string | RegExp;
128
+ blockSelector?: string | null;
129
+ ignoreClass?: string;
130
+ maskTextClass?: string | RegExp;
131
+ maskTextSelector?: string | null;
132
+ maskTextFn?: ((text: string) => string) | null;
133
+ maskAllInputs?: boolean;
134
+ maskInputOptions?: MaskInputOptions;
135
+ maskInputFn?: ((text: string, element?: HTMLElement) => string) | null;
136
+ /** Modify the network request before it is captured. Returning null stops it being captured */
137
+ maskNetworkRequestFn?: ((url: NetworkRequest) => NetworkRequest | null | undefined) | null;
138
+ slimDOMOptions?: SlimDOMOptions | 'all' | true;
139
+ collectFonts?: boolean;
140
+ inlineStylesheet?: boolean;
141
+ recorderVersion?: 'v1' | 'v2';
142
+ recordCrossOriginIframes?: boolean;
143
+ }
144
+ export declare type SessionIdChangedCallback = (sessionId: string, windowId: string | null | undefined) => void;
145
+ export declare enum Compression {
146
+ GZipJS = "gzip-js",
147
+ Base64 = "base64"
148
+ }
149
+ export interface XHROptions {
150
+ transport?: 'XHR' | 'sendBeacon';
151
+ method?: 'POST' | 'GET';
152
+ urlQueryArgs?: {
153
+ compression: Compression;
154
+ };
155
+ verbose?: boolean;
156
+ blob?: boolean;
157
+ sendBeacon?: boolean;
158
+ }
159
+ export interface CaptureOptions extends XHROptions {
160
+ $set?: Properties; /** used with $identify */
161
+ $set_once?: Properties; /** used with $identify */
162
+ _batchKey?: string; /** key of queue, e.g. 'sessionRecording' vs 'event' */
163
+ _metrics?: Properties;
164
+ _noTruncate?: boolean; /** if set, overrides and disables config.properties_string_max_length */
165
+ endpoint?: string; /** defaults to '/e/' */
166
+ send_instantly?: boolean; /** if set skips the batched queue */
167
+ timestamp?: Date;
168
+ }
169
+ export interface RetryQueueElement {
170
+ retryAt: Date;
171
+ requestData: QueuedRequestData;
172
+ }
173
+ export interface QueuedRequestData {
174
+ url: string;
175
+ data: Properties;
176
+ options: CaptureOptions;
177
+ headers?: Properties;
178
+ callback?: RequestCallback;
179
+ retriesPerformedSoFar?: number;
180
+ }
181
+ export interface XHRParams extends QueuedRequestData {
182
+ retryQueue: RetryQueue;
183
+ onXHRError: (req: XMLHttpRequest) => void;
184
+ timeout?: number;
185
+ onRateLimited?: (req: XMLHttpRequest) => void;
186
+ }
187
+ export interface DecideResponse {
188
+ status: number;
189
+ supportedCompression: Compression[];
190
+ config: {
191
+ enable_collect_everything: boolean;
192
+ };
193
+ custom_properties: AutoCaptureCustomProperty[];
194
+ featureFlags: Record<string, string | boolean>;
195
+ featureFlagPayloads: Record<string, JsonType>;
196
+ errorsWhileComputingFlags: boolean;
197
+ autocapture_opt_out?: boolean;
198
+ capturePerformance?: boolean;
199
+ autocaptureExceptions?: boolean | {
200
+ endpoint?: string;
201
+ errors_to_ignore: string[];
202
+ };
203
+ sessionRecording?: {
204
+ endpoint?: string;
205
+ consoleLogRecordingEnabled?: boolean;
206
+ recorderVersion?: 'v1' | 'v2';
207
+ };
208
+ toolbarParams: ToolbarParams;
209
+ editorParams?: ToolbarParams; /** @deprecated, renamed to toolbarParams, still present on older API responses */
210
+ toolbarVersion: 'toolbar'; /** @deprecated, moved to toolbarParams */
211
+ isAuthenticated: boolean;
212
+ siteApps: {
213
+ id: number;
214
+ url: string;
215
+ }[];
216
+ }
217
+ export declare type FeatureFlagsCallback = (flags: string[], variants: Record<string, string | boolean>) => void;
218
+ export interface AutoCaptureCustomProperty {
219
+ name: string;
220
+ css_selector: string;
221
+ event_selectors: string[];
222
+ }
223
+ export interface CompressionData {
224
+ data: string;
225
+ compression?: Compression;
226
+ }
227
+ export interface GDPROptions {
228
+ capture?: (event: string, properties: Properties, options: CaptureOptions) => void; /** function used for capturing a PostHog event to record the opt-in action */
229
+ captureEventName?: string; /** event name to be used for capturing the opt-in action */
230
+ captureProperties?: Properties; /** set of properties to be captured along with the opt-in action */
231
+ /** persistence mechanism used */
232
+ persistenceType?: 'cookie' | 'localStorage' | 'localStorage+cookie';
233
+ persistencePrefix?: string; /** [__ph_opt_in_out] - custom prefix to be used in the cookie/localstorage name */
234
+ cookieExpiration?: number; /** number of days until the opt-in cookie expires */
235
+ crossSubdomainCookie?: boolean; /** whether the opt-in cookie is set as cross-subdomain or not */
236
+ secureCookie?: boolean; /** whether the opt-in cookie is set as secure or not */
237
+ respectDnt?: boolean;
238
+ window?: Window;
239
+ }
240
+ export declare type RequestCallback = (response: Record<string, any>, data?: Properties) => void;
241
+ export interface PersistentStore {
242
+ is_supported: () => boolean;
243
+ error: (error: any) => void;
244
+ parse: (name: string) => any;
245
+ get: (name: string) => any;
246
+ set: (name: string, value: any, expire_days?: number | null, cross_subdomain?: boolean, secure?: boolean) => void;
247
+ remove: (name: string, cross_subdomain?: boolean) => void;
248
+ }
249
+ export declare type Breaker = {};
250
+ export declare type EventHandler = (event: Event) => boolean | void;
251
+ export declare type ToolbarUserIntent = 'add-action' | 'edit-action';
252
+ export declare type ToolbarSource = 'url' | 'localstorage';
253
+ export declare type ToolbarVersion = 'toolbar';
254
+ export interface ToolbarParams {
255
+ token?: string; /** public posthog-js token */
256
+ temporaryToken?: string; /** private temporary user token */
257
+ actionId?: number;
258
+ userIntent?: ToolbarUserIntent;
259
+ source?: ToolbarSource;
260
+ toolbarVersion?: ToolbarVersion;
261
+ instrument?: boolean;
262
+ distinctId?: string;
263
+ userEmail?: string;
264
+ dataAttributes?: string[];
265
+ featureFlags?: Record<string, string | boolean>;
266
+ }
267
+ export interface PostData {
268
+ buffer?: BlobPart;
269
+ compression?: Compression;
270
+ data?: string;
271
+ }
272
+ export interface JSC {
273
+ (): void;
274
+ [key: string]: (response: any) => void;
275
+ }
276
+ export declare type SnippetArrayItem = [method: string, ...args: any[]];
277
+ export declare type JsonType = string | number | boolean | null | {
278
+ [key: string]: JsonType;
279
+ } | Array<JsonType>;
280
+ /** A feature that isn't publicly available yet.*/
281
+ export interface EarlyAccessFeature {
282
+ name: string;
283
+ description: string;
284
+ stage: 'concept' | 'alpha' | 'beta';
285
+ documentationUrl: string | null;
286
+ flagKey: string | null;
287
+ }
288
+ export declare type EarlyAccessFeatureCallback = (earlyAccessFeatures: EarlyAccessFeature[]) => void;
289
+ export interface EarlyAccessFeatureResponse {
290
+ earlyAccessFeatures: EarlyAccessFeature[];
291
+ }
292
+ export declare type NetworkRequest = {
293
+ url: string;
294
+ };
@@ -0,0 +1,6 @@
1
+ export var Compression;
2
+ (function (Compression) {
3
+ Compression["GZipJS"] = "gzip-js";
4
+ Compression["Base64"] = "base64";
5
+ })(Compression || (Compression = {}));
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AA4JA,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACnB,iCAAkB,CAAA;IAClB,gCAAiB,CAAA;AACrB,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB","sourcesContent":["import type { MaskInputOptions, SlimDOMOptions } from 'rrweb-snapshot'\nimport { PostHog } from './posthog-core'\nimport { RetryQueue } from './retry-queue'\n\nexport type Property = any\nexport type Properties = Record<string, Property>\nexport interface CaptureResult {\n uuid: string\n event: string\n properties: Properties\n $set?: Properties\n $set_once?: Properties\n timestamp?: Date\n}\nexport type CaptureCallback = (response: any, data: any) => void\n\nexport type AutocaptureCompatibleElement = 'a' | 'button' | 'form' | 'input' | 'select' | 'textarea' | 'label'\nexport type DomAutocaptureEvents = 'click' | 'change' | 'submit'\n\n/**\n * If an array is passed for an allowlist, autocapture events will only be sent for elements matching\n * at least one of the elements in the array. Multiple allowlists can be used\n */\nexport interface AutocaptureConfig {\n /**\n * List of URLs to allow autocapture on, can be strings to match\n * or regexes e.g. ['https://example.com', 'test.com/.*']\n */\n url_allowlist?: (string | RegExp)[]\n\n /**\n * List of DOM events to allow autocapture on e.g. ['click', 'change', 'submit']\n */\n dom_event_allowlist?: DomAutocaptureEvents[]\n\n /**\n * List of DOM elements to allow autocapture on\n * e.g. ['a', 'button', 'form', 'input', 'select', 'textarea', 'label']\n */\n element_allowlist?: AutocaptureCompatibleElement[]\n\n /**\n * List of CSS selectors to allow autocapture on\n * e.g. ['[ph-capture]']\n */\n css_selector_allowlist?: string[]\n}\n\nexport type UUIDVersion = 'og' | 'v7'\n\nexport interface PostHogConfig {\n api_host: string\n api_method: string\n api_transport: string\n ui_host: string | null\n token: string\n autocapture: boolean | AutocaptureConfig\n rageclick: boolean\n cross_subdomain_cookie: boolean\n persistence: 'localStorage' | 'cookie' | 'memory' | 'localStorage+cookie' | 'sessionStorage'\n persistence_name: string\n cookie_name: string\n loaded: (posthog_instance: PostHog) => void\n store_google: boolean\n custom_campaign_params: string[]\n save_referrer: boolean\n test: boolean\n verbose: boolean\n capture_pageview: boolean\n capture_pageleave: boolean\n debug: boolean\n cookie_expiration: number\n upgrade: boolean\n disable_session_recording: boolean\n disable_persistence: boolean\n disable_cookie: boolean\n enable_recording_console_log?: boolean\n secure_cookie: boolean\n ip: boolean\n opt_out_capturing_by_default: boolean\n opt_out_persistence_by_default: boolean\n opt_out_capturing_persistence_type: 'localStorage' | 'cookie'\n opt_out_capturing_cookie_prefix: string | null\n opt_in_site_apps: boolean\n respect_dnt: boolean\n property_blacklist: string[]\n xhr_headers: { [header_name: string]: string }\n on_xhr_error: (failedRequest: XMLHttpRequest) => void\n inapp_protocol: string\n inapp_link_new_window: boolean\n request_batching: boolean\n sanitize_properties: ((properties: Properties, event_name: string) => Properties) | null\n properties_string_max_length: number\n session_recording: SessionRecordingOptions\n session_idle_timeout_seconds: number\n mask_all_element_attributes: boolean\n mask_all_text: boolean\n advanced_disable_decide: boolean\n advanced_disable_feature_flags: boolean\n advanced_disable_feature_flags_on_first_load: boolean\n advanced_disable_toolbar_metrics: boolean\n get_device_id: (uuid: string) => string\n name: string\n callback_fn: string\n _onCapture: (eventName: string, eventData: CaptureResult) => void\n capture_performance?: boolean\n // Should only be used for testing. Could negatively impact performance.\n disable_compression: boolean\n bootstrap: {\n distinctID?: string\n isIdentifiedID?: boolean\n featureFlags?: Record<string, boolean | string>\n featureFlagPayloads?: Record<string, JsonType>\n }\n segment?: any\n __preview_measure_pageview_stats?: boolean\n}\n\nexport interface OptInOutCapturingOptions {\n capture: (event: string, properties: Properties, options: CaptureOptions) => void\n capture_event_name: string\n capture_properties: Properties\n enable_persistence: boolean\n clear_persistence: boolean\n persistence_type: 'cookie' | 'localStorage' | 'localStorage+cookie'\n cookie_prefix: string\n cookie_expiration: number\n cross_subdomain_cookie: boolean\n secure_cookie: boolean\n}\n\nexport interface isFeatureEnabledOptions {\n send_event: boolean\n}\n\nexport interface SessionRecordingOptions {\n blockClass?: string | RegExp\n blockSelector?: string | null\n ignoreClass?: string\n maskTextClass?: string | RegExp\n maskTextSelector?: string | null\n maskTextFn?: ((text: string) => string) | null\n maskAllInputs?: boolean\n maskInputOptions?: MaskInputOptions\n maskInputFn?: ((text: string, element?: HTMLElement) => string) | null\n /** Modify the network request before it is captured. Returning null stops it being captured */\n maskNetworkRequestFn?: ((url: NetworkRequest) => NetworkRequest | null | undefined) | null\n slimDOMOptions?: SlimDOMOptions | 'all' | true\n collectFonts?: boolean\n inlineStylesheet?: boolean\n recorderVersion?: 'v1' | 'v2'\n recordCrossOriginIframes?: boolean\n}\n\nexport type SessionIdChangedCallback = (sessionId: string, windowId: string | null | undefined) => void\n\nexport enum Compression {\n GZipJS = 'gzip-js',\n Base64 = 'base64',\n}\n\nexport interface XHROptions {\n transport?: 'XHR' | 'sendBeacon'\n method?: 'POST' | 'GET'\n urlQueryArgs?: { compression: Compression }\n verbose?: boolean\n blob?: boolean\n sendBeacon?: boolean\n}\n\nexport interface CaptureOptions extends XHROptions {\n $set?: Properties /** used with $identify */\n $set_once?: Properties /** used with $identify */\n _batchKey?: string /** key of queue, e.g. 'sessionRecording' vs 'event' */\n _metrics?: Properties\n _noTruncate?: boolean /** if set, overrides and disables config.properties_string_max_length */\n endpoint?: string /** defaults to '/e/' */\n send_instantly?: boolean /** if set skips the batched queue */\n timestamp?: Date\n}\n\nexport interface RetryQueueElement {\n retryAt: Date\n requestData: QueuedRequestData\n}\nexport interface QueuedRequestData {\n url: string\n data: Properties\n options: CaptureOptions\n headers?: Properties\n callback?: RequestCallback\n retriesPerformedSoFar?: number\n}\n\nexport interface XHRParams extends QueuedRequestData {\n retryQueue: RetryQueue\n onXHRError: (req: XMLHttpRequest) => void\n timeout?: number\n onRateLimited?: (req: XMLHttpRequest) => void\n}\n\nexport interface DecideResponse {\n status: number\n supportedCompression: Compression[]\n config: {\n enable_collect_everything: boolean\n }\n custom_properties: AutoCaptureCustomProperty[] // TODO: delete, not sent\n featureFlags: Record<string, string | boolean>\n featureFlagPayloads: Record<string, JsonType>\n errorsWhileComputingFlags: boolean\n autocapture_opt_out?: boolean\n capturePerformance?: boolean\n // this is currently in development and may have breaking changes without a major version bump\n autocaptureExceptions?:\n | boolean\n | {\n endpoint?: string\n errors_to_ignore: string[]\n }\n sessionRecording?: {\n endpoint?: string\n consoleLogRecordingEnabled?: boolean\n recorderVersion?: 'v1' | 'v2'\n }\n toolbarParams: ToolbarParams\n editorParams?: ToolbarParams /** @deprecated, renamed to toolbarParams, still present on older API responses */\n toolbarVersion: 'toolbar' /** @deprecated, moved to toolbarParams */\n isAuthenticated: boolean\n siteApps: { id: number; url: string }[]\n}\n\nexport type FeatureFlagsCallback = (flags: string[], variants: Record<string, string | boolean>) => void\n\n// TODO: delete custom_properties after changeless typescript refactor\nexport interface AutoCaptureCustomProperty {\n name: string\n css_selector: string\n event_selectors: string[]\n}\n\nexport interface CompressionData {\n data: string\n compression?: Compression\n}\n\nexport interface GDPROptions {\n capture?: (\n event: string,\n properties: Properties,\n options: CaptureOptions\n ) => void /** function used for capturing a PostHog event to record the opt-in action */\n captureEventName?: string /** event name to be used for capturing the opt-in action */\n captureProperties?: Properties /** set of properties to be captured along with the opt-in action */\n /** persistence mechanism used */\n persistenceType?: 'cookie' | 'localStorage' | 'localStorage+cookie'\n persistencePrefix?: string /** [__ph_opt_in_out] - custom prefix to be used in the cookie/localstorage name */\n cookieExpiration?: number /** number of days until the opt-in cookie expires */\n crossSubdomainCookie?: boolean /** whether the opt-in cookie is set as cross-subdomain or not */\n secureCookie?: boolean /** whether the opt-in cookie is set as secure or not */\n respectDnt?: boolean\n window?: Window\n}\n\nexport type RequestCallback = (response: Record<string, any>, data?: Properties) => void\n\nexport interface PersistentStore {\n is_supported: () => boolean\n error: (error: any) => void\n parse: (name: string) => any\n get: (name: string) => any\n set: (name: string, value: any, expire_days?: number | null, cross_subdomain?: boolean, secure?: boolean) => void\n remove: (name: string, cross_subdomain?: boolean) => void\n}\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport type Breaker = {}\nexport type EventHandler = (event: Event) => boolean | void\n\nexport type ToolbarUserIntent = 'add-action' | 'edit-action'\nexport type ToolbarSource = 'url' | 'localstorage'\nexport type ToolbarVersion = 'toolbar'\n\n/* sync with posthog */\nexport interface ToolbarParams {\n token?: string /** public posthog-js token */\n temporaryToken?: string /** private temporary user token */\n actionId?: number\n userIntent?: ToolbarUserIntent\n source?: ToolbarSource\n toolbarVersion?: ToolbarVersion\n instrument?: boolean\n distinctId?: string\n userEmail?: string\n dataAttributes?: string[]\n featureFlags?: Record<string, string | boolean>\n}\n\nexport interface PostData {\n buffer?: BlobPart\n compression?: Compression\n data?: string\n}\n\nexport interface JSC {\n (): void\n [key: string]: (response: any) => void\n}\n\nexport type SnippetArrayItem = [method: string, ...args: any[]]\n\nexport type JsonType = string | number | boolean | null | { [key: string]: JsonType } | Array<JsonType>\n\n/** A feature that isn't publicly available yet.*/\nexport interface EarlyAccessFeature {\n // Sync this with the backend's EarlyAccessFeatureSerializer!\n name: string\n description: string\n stage: 'concept' | 'alpha' | 'beta'\n documentationUrl: string | null\n flagKey: string | null\n}\n\nexport type EarlyAccessFeatureCallback = (earlyAccessFeatures: EarlyAccessFeature[]) => void\n\nexport interface EarlyAccessFeatureResponse {\n earlyAccessFeatures: EarlyAccessFeature[]\n}\n\nexport type NetworkRequest = {\n url: string\n}\n"]}
@@ -0,0 +1,89 @@
1
+ import { Breaker, EventHandler, Properties } from './types';
2
+ declare const win: Window & typeof globalThis;
3
+ declare const document: Document;
4
+ declare const userAgent: string;
5
+ declare const logger: {
6
+ /** @type {function(...*)} */
7
+ log: (...args: any[]) => void;
8
+ /** @type {function(...*)} */
9
+ error: (..._args: any[]) => void;
10
+ /** @type {function(...*)} */
11
+ critical: (..._args: any[]) => void;
12
+ };
13
+ export declare const _trim: (str: string) => string;
14
+ export declare const _bind_instance_methods: (obj: Record<string, any>) => void;
15
+ export declare function _eachArray<E = any>(obj: E[] | null | undefined, iterator: (value: E, key: number) => void | Breaker, thisArg?: any): void;
16
+ /**
17
+ * @param {*=} obj
18
+ * @param {function(...*)=} iterator
19
+ * @param {Object=} thisArg
20
+ */
21
+ export declare function _each(obj: any, iterator: (value: any, key: any) => void | Breaker, thisArg?: any): void;
22
+ export declare const _extend: (obj: Record<string, any>, ...args: Record<string, any>[]) => Record<string, any>;
23
+ export declare const _isArray: (arg: any) => arg is any[];
24
+ export declare const _isFunction: (f: any) => f is (...args: any[]) => any;
25
+ export declare const _include: (obj: null | string | Array<any> | Record<string, any>, target: any) => boolean | Breaker;
26
+ export declare function _includes<T = any>(str: T[] | string, needle: T): boolean;
27
+ /**
28
+ * Object.entries() polyfill
29
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
30
+ */
31
+ export declare function _entries<T = any>(obj: Record<string, T>): [string, T][];
32
+ export declare const _isObject: (obj: any) => obj is Record<string, any>;
33
+ export declare const _isEmptyObject: (obj: any) => obj is Record<string, any>;
34
+ export declare const _isUndefined: (obj: any) => obj is undefined;
35
+ export declare const _isString: (obj: any) => obj is string;
36
+ export declare const _isDate: (obj: any) => obj is Date;
37
+ export declare const _isNumber: (obj: any) => obj is number;
38
+ export declare const _encodeDates: (obj: Properties) => Properties;
39
+ export declare const _timestamp: () => number;
40
+ export declare const _formatDate: (d: Date) => string;
41
+ export declare const _safewrap: <F extends (...args: any[]) => any = (...args: any[]) => any>(f: F) => F;
42
+ export declare const _safewrap_class: (klass: Function, functions: string[]) => void;
43
+ export declare const _safewrap_instance_methods: (obj: Record<string, any>) => void;
44
+ export declare const _strip_empty_properties: (p: Properties) => Properties;
45
+ export declare function _copyAndTruncateStrings<T extends Record<string, any> = Record<string, any>>(object: T, maxStringLength: number | null): T;
46
+ export declare function _base64Encode(data: null): null;
47
+ export declare function _base64Encode(data: undefined): undefined;
48
+ export declare function _base64Encode(data: string): string;
49
+ export declare const _utf8Encode: (string: string) => string;
50
+ export declare const _isBlockedUA: (ua: string) => boolean;
51
+ /**
52
+ * @param {Object=} formdata
53
+ * @param {string=} arg_separator
54
+ */
55
+ export declare const _HTTPBuildQuery: (formdata: Record<string, any>, arg_separator?: string) => string;
56
+ export declare const _getQueryParam: (url: string, param: string) => string;
57
+ export declare const _getHashParam: (hash: string, param: string) => string | null;
58
+ export declare const _register_event: (element: Element | Window | Document | Node, type: string, handler: EventHandler, oldSchool?: boolean, useCapture?: boolean) => void;
59
+ export declare const isLocalhost: () => boolean;
60
+ export declare function loadScript(scriptUrlToLoad: string, callback: (error?: string | Event, event?: Event) => void): void;
61
+ export declare const _info: {
62
+ campaignParams: (customParams?: string[]) => Record<string, any>;
63
+ searchEngine: () => string | null;
64
+ searchInfo: () => Record<string, any>;
65
+ /**
66
+ * This function detects which browser is running this script.
67
+ * The order of the checks are important since many user agents
68
+ * include key words used in later checks.
69
+ */
70
+ browser: (user_agent: string, vendor: string, opera?: any) => string;
71
+ /**
72
+ * This function detects which browser version is running this script,
73
+ * parsing major and minor version (e.g., 42.1). User agent strings from:
74
+ * http://www.useragentstring.com/pages/useragentstring.php
75
+ */
76
+ browserVersion: (userAgent: string, vendor: string, opera: string) => number | null;
77
+ browserLanguage: () => string;
78
+ os: (user_agent: string) => {
79
+ os_name: string;
80
+ os_version: string;
81
+ };
82
+ device: (user_agent: string) => string;
83
+ deviceType: (user_agent: string) => string;
84
+ referrer: () => string;
85
+ referringDomain: () => string;
86
+ properties: () => Properties;
87
+ people_properties: () => Properties;
88
+ };
89
+ export { win as window, userAgent, logger, document };