txlemetry-react-native 4.55.1 → 5.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.
Files changed (110) hide show
  1. package/LICENSE +353 -353
  2. package/dist/TxlemetryContext.d.ts +5 -0
  3. package/dist/TxlemetryContext.js +1 -0
  4. package/dist/TxlemetryErrorBoundary.d.ts +27 -0
  5. package/dist/TxlemetryErrorBoundary.js +1 -0
  6. package/dist/{PostHogMaskView.d.ts → TxlemetryMaskView.d.ts} +39 -39
  7. package/dist/TxlemetryMaskView.js +1 -0
  8. package/dist/TxlemetryProvider.d.ts +100 -0
  9. package/dist/TxlemetryProvider.js +1 -0
  10. package/dist/autocapture.d.ts +4 -4
  11. package/dist/autocapture.js +1 -1
  12. package/dist/error-tracking/index.d.ts +98 -98
  13. package/dist/error-tracking/index.js +1 -1
  14. package/dist/error-tracking/utils.d.ts +5 -5
  15. package/dist/frameworks/wix-navigation.d.ts +3 -3
  16. package/dist/frameworks/wix-navigation.js +1 -1
  17. package/dist/hooks/useFeatureFlag.d.ts +5 -5
  18. package/dist/hooks/useFeatureFlag.js +1 -1
  19. package/dist/hooks/useFeatureFlagResult.d.ts +3 -3
  20. package/dist/hooks/useFeatureFlagResult.js +1 -1
  21. package/dist/hooks/useFeatureFlags.d.ts +3 -3
  22. package/dist/hooks/useFeatureFlags.js +1 -1
  23. package/dist/hooks/useNavigationTracker.d.ts +6 -6
  24. package/dist/hooks/useNavigationTracker.js +1 -1
  25. package/dist/hooks/useTxlemetry.d.ts +2 -0
  26. package/dist/hooks/useTxlemetry.js +1 -0
  27. package/dist/hooks/utils.d.ts +14 -14
  28. package/dist/hooks/utils.js +1 -1
  29. package/dist/index.d.ts +14 -14
  30. package/dist/index.js +1 -1
  31. package/dist/index.txlemetry.d.ts +36 -36
  32. package/dist/index.txlemetry.js +21 -21
  33. package/dist/logs-defaults.d.ts +9 -9
  34. package/dist/native-deps.d.ts +4 -4
  35. package/dist/native-deps.js +1 -1
  36. package/dist/optional/OptionalAsyncStorage.d.ts +2 -2
  37. package/dist/optional/OptionalExpoApplication.d.ts +2 -2
  38. package/dist/optional/OptionalExpoDevice.d.ts +2 -2
  39. package/dist/optional/OptionalExpoFileSystem.d.ts +2 -2
  40. package/dist/optional/OptionalExpoFileSystemLegacy.d.ts +2 -2
  41. package/dist/optional/OptionalExpoLocalization.d.ts +2 -2
  42. package/dist/optional/OptionalPlugin.d.ts +20 -20
  43. package/dist/optional/OptionalReactNativeDeviceInfo.d.ts +2 -2
  44. package/dist/optional/OptionalReactNativeLocalize.d.ts +13 -13
  45. package/dist/optional/OptionalReactNativeNavigation.d.ts +2 -2
  46. package/dist/optional/OptionalReactNativeNavigationWix.d.ts +2 -2
  47. package/dist/optional/OptionalReactNativeSafeArea.d.ts +2 -2
  48. package/dist/optional/OptionalReactNativeSvg.d.ts +2 -2
  49. package/dist/storage.d.ts +41 -41
  50. package/dist/storage.js +1 -1
  51. package/dist/surveys/{PostHogSurveyProvider.d.ts → TxlemetrySurveyProvider.d.ts} +23 -23
  52. package/dist/surveys/TxlemetrySurveyProvider.js +1 -0
  53. package/dist/surveys/components/BottomSection.d.ts +9 -9
  54. package/dist/surveys/components/BottomSection.js +1 -1
  55. package/dist/surveys/components/Cancel.d.ts +5 -5
  56. package/dist/surveys/components/Cancel.js +1 -1
  57. package/dist/surveys/components/ConfirmationMessage.d.ts +12 -12
  58. package/dist/surveys/components/ConfirmationMessage.js +1 -1
  59. package/dist/surveys/components/QuestionHeader.d.ts +8 -8
  60. package/dist/surveys/components/QuestionHeader.js +1 -1
  61. package/dist/surveys/components/QuestionTypes.d.ts +26 -26
  62. package/dist/surveys/components/QuestionTypes.js +1 -1
  63. package/dist/surveys/components/SurveyModal.d.ts +11 -11
  64. package/dist/surveys/components/SurveyModal.js +1 -1
  65. package/dist/surveys/components/Surveys.d.ts +16 -16
  66. package/dist/surveys/components/Surveys.js +1 -1
  67. package/dist/surveys/getActiveMatchingSurveys.d.ts +2 -2
  68. package/dist/surveys/icons.d.ts +11 -11
  69. package/dist/surveys/icons.js +1 -1
  70. package/dist/surveys/index.d.ts +6 -6
  71. package/dist/surveys/index.js +1 -1
  72. package/dist/surveys/safeStyleSheet.d.ts +8 -8
  73. package/dist/surveys/survey-translations.d.ts +7 -7
  74. package/dist/surveys/survey-translations.js +1 -1
  75. package/dist/surveys/surveys-utils.d.ts +54 -54
  76. package/dist/surveys/surveys-utils.js +1 -1
  77. package/dist/surveys/useActivatedSurveys.d.ts +3 -3
  78. package/dist/surveys/useActivatedSurveys.js +1 -1
  79. package/dist/surveys/useSurveyStorage.d.ts +8 -8
  80. package/dist/surveys/useSurveyStorage.js +1 -1
  81. package/dist/tooling/expoconfig.d.ts +64 -64
  82. package/dist/tooling/expoconfig.js +1 -1
  83. package/dist/tooling/metroconfig.d.ts +21 -21
  84. package/dist/tooling/metroconfig.js +1 -1
  85. package/dist/tooling/{posthogMetroSerializer.d.ts → txlemetryMetroSerializer.d.ts} +17 -17
  86. package/dist/tooling/txlemetryMetroSerializer.js +1 -0
  87. package/dist/tooling/utils.d.ts +58 -58
  88. package/dist/tooling/vendor/expo/expoconfig.d.ts +23 -23
  89. package/dist/tooling/vendor/metro/countLines.d.ts +2 -2
  90. package/dist/tooling/vendor/metro/utils.d.ts +22 -22
  91. package/dist/{posthog-rn.d.ts → txlemetry-rn.d.ts} +1096 -1096
  92. package/dist/txlemetry-rn.js +1 -0
  93. package/dist/types.d.ts +205 -205
  94. package/dist/utils.d.ts +25 -25
  95. package/dist/version.d.ts +1 -1
  96. package/dist/version.js +1 -1
  97. package/package.json +149 -149
  98. package/tooling/txlemetry-xcode.sh +2 -2
  99. package/dist/PostHogContext.d.ts +0 -5
  100. package/dist/PostHogContext.js +0 -1
  101. package/dist/PostHogErrorBoundary.d.ts +0 -27
  102. package/dist/PostHogErrorBoundary.js +0 -1
  103. package/dist/PostHogMaskView.js +0 -1
  104. package/dist/PostHogProvider.d.ts +0 -100
  105. package/dist/PostHogProvider.js +0 -1
  106. package/dist/hooks/usePostHog.d.ts +0 -2
  107. package/dist/hooks/usePostHog.js +0 -1
  108. package/dist/posthog-rn.js +0 -1
  109. package/dist/surveys/PostHogSurveyProvider.js +0 -1
  110. package/dist/tooling/posthogMetroSerializer.js +0 -1
@@ -1,1096 +1,1096 @@
1
- import { CaptureLogOptions, CaptureLogger, JsonType, PostHogCaptureOptions, PostHogCore, PostHogCoreOptions, PostHogEventProperties, PostHogFetchOptions, PostHogFetchResponse, PostHogLogsConfig, PostHogPersistedProperty, PostHogRemoteConfig, SurveyResponse, FeatureFlagResultOptions, ErrorTracking as CoreErrorTracking } from '@txlemetry/core';
2
- import { Properties } from '@txlemetry/types';
3
- import { PostHogAutocaptureOptions, PostHogCustomAppProperties, PostHogCustomStorage, PostHogSessionReplayConfig } from './types';
4
- import { OptionalReactNativePlugin } from './optional/OptionalPlugin';
5
- import { ErrorTrackingOptions } from './error-tracking';
6
- export { PostHogPersistedProperty };
7
- export interface PostHogOptions extends PostHogCoreOptions {
8
- /**
9
- * Allows you to provide the storage type.
10
- * 'file' will try to load the best available storage, the provided 'customStorage', 'customAsyncStorage' or in-memory storage.
11
- *
12
- * @default 'file'
13
- */
14
- persistence?: 'memory' | 'file';
15
- /** Allows you to provide your own implementation of the common information about your App or a function to modify the default App properties generated */
16
- customAppProperties?: PostHogCustomAppProperties | ((properties: PostHogCustomAppProperties) => PostHogCustomAppProperties);
17
- /**
18
- * Allows you to provide a custom asynchronous storage such as async-storage, expo-file-system or a synchronous storage such as mmkv.
19
- * If not provided, PostHog will attempt to use the best available storage via optional peer dependencies (async-storage, expo-file-system).
20
- * If `persistence` is set to 'memory', this option will be ignored.
21
- */
22
- customStorage?: PostHogCustomStorage;
23
- /**
24
- * A list of headers that should be sent with requests to the PostHog API.
25
- */
26
- requestHeaders?: {
27
- [header_name: string]: string;
28
- };
29
- /**
30
- * Captures app lifecycle events such as Application Installed, Application Updated, Application Opened, Application Became Active and Application Backgrounded.
31
- * Application Installed and Application Updated events are not supported with persistence set to 'memory'.
32
- *
33
- * @default true
34
- */
35
- captureAppLifecycleEvents?: boolean;
36
- /**
37
- * Enable Recording of Session Replays for Android and iOS
38
- * Requires Record user sessions to be enabled in the PostHog Project Settings
39
- *
40
- * @default false
41
- */
42
- enableSessionReplay?: boolean;
43
- /**
44
- * Configuration for Session Replay
45
- */
46
- sessionReplayConfig?: PostHogSessionReplayConfig;
47
- /**
48
- * If enabled, the session id ($session_id) will be persisted across app restarts.
49
- * This is an option for back compatibility, so your current data isn't skewed with the new version of the SDK.
50
- * If this is false, the session id will be always reset on app restart.
51
- *
52
- * @default false
53
- */
54
- enablePersistSessionIdAcrossRestart?: boolean;
55
- /**
56
- * Error Tracking Configuration
57
- */
58
- errorTracking?: ErrorTrackingOptions;
59
- /**
60
- * Automatically include common device and app properties in feature flag evaluation.
61
- *
62
- * When enabled, the following properties are sent with every /flags request:
63
- * - $app_version: App version
64
- * - $app_build: App build number
65
- * - $app_namespace: App bundle identifier / namespace
66
- * - $os_name: Operating system name
67
- * - $os_version: Operating system version
68
- * - $device_type: Device type (Mobile, Desktop)
69
- * - $lib: Name of the SDK library
70
- * - $lib_version: Version of the SDK library
71
- *
72
- * This ensures feature flags that rely on these properties work correctly
73
- * without waiting for server-side processing of identify() calls.
74
- *
75
- * @default true
76
- */
77
- setDefaultPersonProperties?: boolean;
78
- /**
79
- * Logs feature configuration. Enables structured log capture via
80
- * `posthog.captureLog(...)` or `posthog.logger.info(...)`. Records ship to
81
- * PostHog's logs product (`/i/v1/logs`) in OTLP format, batched on a timer,
82
- * AppState change, buffer fill, or manual `flushLogs()`.
83
- *
84
- * Capture is **unconditional** — calling the API ships records as long as
85
- * the SDK is initialized and the user hasn't opted out. The only blockers
86
- * are `optedOut`, missing/empty `body`, and missing API key.
87
- *
88
- * All fields below are optional; per-SDK defaults apply (mobile defaults
89
- * are tuned for cellular bandwidth and battery, ~50 logs/sec ceiling).
90
- *
91
- * @example Minimal — just service tagging, defaults for everything else
92
- * ```ts
93
- * new PostHog(key, {
94
- * logs: { serviceName: 'my-app', environment: 'production' }
95
- * })
96
- * ```
97
- *
98
- * @example Tune for higher-volume logging
99
- * ```ts
100
- * new PostHog(key, {
101
- * logs: {
102
- * serviceName: 'my-app',
103
- * rateCap: { maxLogs: 5000, windowMs: 60000 },
104
- * maxBufferSize: 500,
105
- * beforeSend: (r) => r.body.includes('secret') ? null : r,
106
- * }
107
- * })
108
- * ```
109
- */
110
- logs?: PostHogLogsConfig;
111
- /**
112
- * Overrides the language used when rendering translated survey copy.
113
- * When unset, the SDK falls back to the persisted person property `language`
114
- * and then the device locale.
115
- */
116
- overrideDisplayLanguage?: string | null;
117
- }
118
- export declare class PostHog extends PostHogCore {
119
- private _persistence;
120
- private _eventsStorage;
121
- private _logsStorage;
122
- private _appProperties;
123
- private _currentSessionId?;
124
- private _enableSessionReplay?;
125
- private _sessionReplayNativeInitialized;
126
- private _nativeErrorTrackingInitialized;
127
- private _sessionReplayRecordingActive?;
128
- private _sessionReplayEvalChain;
129
- private _sessionReplayOptions?;
130
- private _sessionReplayEventTriggers;
131
- private _disableSurveys;
132
- private _errorTracking;
133
- private _logs;
134
- private _resolvedLogsConfig;
135
- private _currentAppState?;
136
- private _surveysReadyPromise;
137
- private _surveysReady;
138
- private _setDefaultPersonProperties;
139
- private _overrideDisplayLanguage;
140
- private _requestHeaders;
141
- /**
142
- * Creates a new PostHog instance for React Native. You can find all configuration options in the [React Native SDK docs](https://posthog.com/docs/libraries/react-native#configuration-options).
143
- *
144
- * If you prefer not to use the PostHogProvider, you can initialize PostHog in its own file and import the instance from there.
145
- *
146
- * {@label Initialization}
147
- *
148
- * @example
149
- * ```ts
150
- * // posthog.ts
151
- * import PostHog from 'posthog-react-native'
152
- *
153
- * export const posthog = new PostHog('<ph_project_api_key>', {
154
- * host: '<ph_client_api_host>'
155
- * })
156
- *
157
- * // Then you can access PostHog by importing your instance
158
- * // Another file:
159
- * import { posthog } from './posthog'
160
- *
161
- * export function MyApp1() {
162
- * useEffect(async () => {
163
- * posthog.capture('event_name')
164
- * }, [posthog])
165
- *
166
- * return <View>Your app code</View>
167
- * }
168
- * ```
169
- *
170
- * @public
171
- *
172
- * @param apiKey - Your PostHog API key
173
- * @param options - PostHog configuration options
174
- */
175
- constructor(apiKey: string, options?: PostHogOptions);
176
- /**
177
- *
178
- * @internal
179
- *
180
- */
181
- ready(): Promise<void>;
182
- /**
183
- * Called when remote config has been loaded (from either the remote config endpoint or the flags endpoint).
184
- * Gates error tracking autocapture based on the remote config response.
185
- *
186
- * Session replay config (consoleLogRecordingEnabled, sampleRate, capturePerformance.network_timing) is already
187
- * cached via PostHogPersistedProperty.RemoteConfig and applied at startup in startSessionReplay().
188
- *
189
- * @internal
190
- */
191
- protected onRemoteConfig(response: PostHogRemoteConfig): void;
192
- /**
193
- * Resolves the storage instance for a given persisted-property key.
194
- * `LogsQueue` routes to `_logsStorage` (dedicated `.posthog-rn-logs.json`
195
- * file); every other key routes to `_eventsStorage`. Single source of
196
- * truth for routing — extending to new logs-scoped keys is a one-line
197
- * edit here.
198
- */
199
- private _storageForKey;
200
- getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
201
- setPersistedProperty<T>(key: PostHogPersistedProperty, value: T | null): void;
202
- /**
203
- * Waits for any pending storage operations to complete.
204
- * This ensures data has been safely written to async storage before
205
- * considering events as sent, preventing duplicate events on app crash/restart.
206
- */
207
- protected flushStorage(): Promise<void>;
208
- /**
209
- * Drain both pipelines on shutdown. Run in parallel so the logs final
210
- * flush + timer teardown doesn't serialize behind events (and vice-versa).
211
- * `_logs.shutdown()` swallows its own errors — a transient logs failure
212
- * must not break events shutdown.
213
- *
214
- * Logs use the smaller of `terminationFlushBudgetMs` and the caller's
215
- * `shutdownTimeoutMs` so a final flush can never run past the caller's
216
- * shutdown SLA, while still respecting the configured logs-specific
217
- * termination budget when it's tighter.
218
- *
219
- * After the flushes, drain any debounced storage writes that weren't already
220
- * persisted via the queue-advance path — `setPersistedProperty` calls for
221
- * distinctId, sessionId, deviceId, feature flag overrides, etc. only arm a
222
- * debounced write. The drain runs in `finally` so a timed-out flush still
223
- * persists them, and its await is bounded by the time left in the shutdown
224
- * SLA so a hung storage backend can't run past it.
225
- */
226
- _shutdown(shutdownTimeoutMs?: number): Promise<void>;
227
- fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
228
- getLibraryId(): string;
229
- getLibraryVersion(): string;
230
- getCustomUserAgent(): string;
231
- protected getCustomHeaders(): {
232
- [key: string]: string;
233
- };
234
- getCommonEventProperties(): PostHogEventProperties;
235
- getSurveyDisplayLanguageOverride(): string | null;
236
- /**
237
- * Registers super properties that are sent with every event.
238
- *
239
- * Super properties are properties associated with events that are set once and then sent with every capture call.
240
- * They persist across sessions and are stored locally.
241
- *
242
- * {@label Capture}
243
- *
244
- * @example
245
- * ```js
246
- * // register super properties
247
- * posthog.register({
248
- * 'icecream pref': 'vanilla',
249
- * team_id: 22,
250
- * })
251
- * ```
252
- *
253
- * @public
254
- *
255
- * @param properties An associative array of properties to store about the user
256
- */
257
- register(properties: PostHogEventProperties): Promise<void>;
258
- /**
259
- * Removes a super property so it won't be sent with future events.
260
- *
261
- * Super Properties are persisted across sessions so you have to explicitly remove them if they are no longer relevant.
262
- *
263
- * {@label Capture}
264
- *
265
- * @example
266
- * ```js
267
- * // remove a super property
268
- * posthog.unregister('icecream pref')
269
- * ```
270
- *
271
- * @public
272
- *
273
- * @param property The name of the super property to remove
274
- */
275
- unregister(property: string): Promise<void>;
276
- /**
277
- * Resets the user's ID and anonymous ID after logout.
278
- *
279
- * To reset the user's ID and anonymous ID, call reset. Usually you would do this right after the user logs out.
280
- * This also clears all stored super properties and more.
281
- *
282
- * By default (when `propertiesToKeep` is not provided), the app lifecycle properties
283
- * (`InstalledAppBuild` and `InstalledAppVersion`) are automatically preserved to prevent
284
- * duplicate "Application Installed" events on the next app launch.
285
- *
286
- * If you pass `propertiesToKeep` explicitly, only the properties you specify will be preserved.
287
- * To keep the default app lifecycle behavior, include `PostHogPersistedProperty.InstalledAppBuild`
288
- * and `PostHogPersistedProperty.InstalledAppVersion` in your array.
289
- *
290
- * Note: The event queue (`PostHogPersistedProperty.Queue`) and logs queue
291
- * (`PostHogPersistedProperty.LogsQueue`) are always preserved regardless of
292
- * what is passed in `propertiesToKeep`, to ensure in-flight data is not lost.
293
- *
294
- * The project-level remote config (`PostHogPersistedProperty.RemoteConfig`,
295
- * `PostHogPersistedProperty.SessionReplay`, `PostHogPersistedProperty.Surveys`) is also
296
- * always preserved — it is not user data — so session replay and surveys keep working
297
- * after an identity change. The user-specific survey state (`SurveysSeen`,
298
- * `SurveyLastSeenDate`) is still cleared.
299
- *
300
- * {@label Identification}
301
- *
302
- * @example
303
- * ```js
304
- * // reset after logout (preserves app lifecycle properties by default)
305
- * posthog.reset()
306
- * ```
307
- *
308
- * @example
309
- * ```js
310
- * // reset but keep feature flag overrides and app lifecycle properties
311
- * posthog.reset([
312
- * PostHogPersistedProperty.OverrideFeatureFlags,
313
- * PostHogPersistedProperty.InstalledAppBuild,
314
- * PostHogPersistedProperty.InstalledAppVersion,
315
- * ])
316
- * ```
317
- *
318
- * @param propertiesToKeep - Optional array of persisted properties to preserve during reset.
319
- * When not provided, app lifecycle and device bucketing properties are automatically preserved.
320
- * When provided, only the specified properties are preserved.
321
- * The event queue and logs queue are always preserved regardless.
322
- *
323
- * @public
324
- */
325
- reset(propertiesToKeep?: PostHogPersistedProperty[]): void;
326
- /**
327
- * Helper to extract and set default person properties from app properties
328
- *
329
- * @private
330
- *
331
- * @param reloadFeatureFlags Whether to reload feature flags after setting the properties. Defaults to true.
332
- */
333
- private _setDefaultPersonPropertiesForFlags;
334
- /**
335
- * Manually flushes the event queue.
336
- *
337
- * You can set the number of events in the configuration that should queue before flushing.
338
- * Setting this to 1 will send events immediately and will use more battery. This is set to 20 by default.
339
- * You can also manually flush the queue. If a flush is already in progress it returns a promise for the existing flush.
340
- *
341
- * Note: this drains the **events** pipeline only. Logs are flushed via
342
- * {@link flushLogs}, and {@link shutdown} drains both before terminating.
343
- *
344
- * {@label Capture}
345
- *
346
- * @example
347
- * ```js
348
- * // manually flush the queue
349
- * await posthog.flush()
350
- * ```
351
- *
352
- * @see flushLogs
353
- * @public
354
- *
355
- * @returns Promise that resolves when the flush is complete
356
- */
357
- flush(): Promise<void>;
358
- /**
359
- * Captures a structured log record and sends it to PostHog's logs product
360
- * (`/i/v1/logs`). Low-level primitive — most callers will prefer
361
- * `posthog.logger.info(...)` / `.warn(...)` / `.error(...)` etc., which
362
- * wrap this with a level pre-set.
363
- *
364
- * Records are buffered per-session, rate-limited, batched into OTLP
365
- * payloads, and flushed on a timer, on AppState change, or when the
366
- * buffer reaches capacity. Configure flush cadence, rate cap, and a
367
- * `beforeSend` filter via the `logs` option on `new PostHog(...)`.
368
- *
369
- * Note — naming collision: `posthog.captureLog()` (this method) is the
370
- * **logs product** API. There is also a separate, pre-existing
371
- * `sessionReplayConfig.captureLog` boolean that controls whether
372
- * **session replay** records the device's `console.*` output. The two
373
- * are unrelated: this method emits structured records to the logs
374
- * pipeline regardless of whether session replay is on.
375
- *
376
- * {@label Capture}
377
- *
378
- * @example
379
- * ```ts
380
- * posthog.captureLog({
381
- * body: 'checkout completed',
382
- * level: 'info',
383
- * attributes: { order_id: 'ord_789', amount_cents: 4999 },
384
- * })
385
- * ```
386
- *
387
- * @public
388
- *
389
- * @param options Log record. `body` is required; `level` defaults to
390
- * `'info'`. `attributes` are attached as OTLP key-value attributes
391
- * and will override auto-populated ones (distinctId, sessionId) on
392
- * key conflict.
393
- */
394
- captureLog(options: CaptureLogOptions): void;
395
- /**
396
- * Manually flushes the logs queue.
397
- *
398
- * Logs flush automatically on a timer, when the buffer fills, or on
399
- * AppState change — most apps never need to call this. Use it when you
400
- * want a synchronous-style hand-off (e.g. before navigating away from a
401
- * critical screen, in a custom crash handler, or while testing locally).
402
- *
403
- * If a flush is already in progress, both callers join the same in-flight
404
- * promise — no double-send.
405
- *
406
- * Note: this drains the **logs** pipeline only. Events are flushed via
407
- * {@link flush}, and {@link shutdown} drains both before terminating.
408
- *
409
- * {@label Capture}
410
- *
411
- * @example
412
- * ```ts
413
- * await posthog.flushLogs()
414
- * ```
415
- *
416
- * @see flush
417
- * @public
418
- *
419
- * @returns Promise that resolves when the flush is complete.
420
- */
421
- flushLogs(): Promise<void>;
422
- private _captureLogger?;
423
- /**
424
- * Convenience per-level logger. Each method is shorthand for
425
- * `posthog.captureLog({ body, level, attributes })`. Lazily constructed
426
- * on first access, then reused.
427
- *
428
- * {@label Capture}
429
- *
430
- * @example
431
- * ```ts
432
- * posthog.logger.info('checkout completed', { order_id: 'ord_789' })
433
- * posthog.logger.error('payment failed', { code: 'E001' })
434
- * ```
435
- *
436
- * @public
437
- */
438
- get logger(): CaptureLogger;
439
- /**
440
- * Opts the user in to data capture.
441
- *
442
- * By default, PostHog has tracking enabled unless it is forcefully disabled by default using the option { defaultOptIn: false }.
443
- * Once this has been called it is persisted and will be respected until optOut is called again or the reset function is called.
444
- *
445
- * {@label Privacy}
446
- *
447
- * @example
448
- * ```js
449
- * // opt in to tracking
450
- * posthog.optIn()
451
- * ```
452
- *
453
- * @public
454
- */
455
- optIn(): Promise<void>;
456
- /**
457
- * Opts the user out of data capture.
458
- *
459
- * You can completely opt-out users from data capture. Once this has been called it is persisted and will be respected until optIn is called again or the reset function is called.
460
- *
461
- * {@label Privacy}
462
- *
463
- * @example
464
- * ```js
465
- * // opt out of tracking
466
- * posthog.optOut()
467
- * ```
468
- *
469
- * @public
470
- */
471
- optOut(): Promise<void>;
472
- /**
473
- * Checks if a feature flag is enabled for the current user.
474
- *
475
- * Defaults to undefined if not loaded yet or if there was a problem loading.
476
- *
477
- * {@label Feature flags}
478
- *
479
- * @example
480
- * ```js
481
- * // check if feature flag is enabled
482
- * const isEnabled = posthog.isFeatureEnabled('key-for-your-boolean-flag')
483
- * ```
484
- *
485
- * @public
486
- *
487
- * @param key The feature flag key
488
- * @param options Optional per-call settings
489
- * @returns True if enabled, false if disabled, undefined if not loaded
490
- */
491
- isFeatureEnabled(key: string, options?: FeatureFlagResultOptions): boolean | undefined;
492
- /**
493
- * Gets the value of a feature flag for the current user.
494
- *
495
- * Defaults to undefined if not loaded yet or if there was a problem loading.
496
- * Multivariant feature flags are returned as a string.
497
- *
498
- * {@label Feature flags}
499
- *
500
- * @example
501
- * ```js
502
- * // get feature flag value
503
- * const value = posthog.getFeatureFlag('key-for-your-boolean-flag')
504
- * ```
505
- *
506
- * @public
507
- *
508
- * @param key The feature flag key
509
- * @param options Optional per-call settings
510
- * @returns The feature flag value or undefined if not loaded
511
- */
512
- getFeatureFlag(key: string, options?: FeatureFlagResultOptions): boolean | string | undefined;
513
- /**
514
- * Gets the payload of a feature flag for the current user.
515
- *
516
- * Returns JsonType or undefined if not loaded yet or if there was a problem loading.
517
- *
518
- * {@label Feature flags}
519
- *
520
- * @deprecated Use `getFeatureFlagResult()` instead, which returns the flag value and payload from a single evaluation.
521
- *
522
- * @example
523
- * ```js
524
- * // get feature flag payload
525
- * const payload = posthog.getFeatureFlagResult('key-for-your-multivariate-flag')?.payload
526
- * ```
527
- *
528
- * @public
529
- *
530
- * @param key The feature flag key
531
- * @returns The feature flag payload or undefined if not loaded
532
- */
533
- getFeatureFlagPayload(key: string): JsonType | undefined;
534
- /**
535
- * Reloads feature flags from the server.
536
- *
537
- * PostHog loads feature flags when instantiated and refreshes whenever methods are called that affect the flag.
538
- * If you want to manually trigger a refresh, you can call this method.
539
- *
540
- * {@label Feature flags}
541
- *
542
- * @remarks
543
- * When the `disableRemoteFeatureFlags` option is set, this method is a no-op; supply
544
- * flag values via `updateFlags()` instead.
545
- *
546
- * @example
547
- * ```js
548
- * // reload feature flags
549
- * posthog.reloadFeatureFlags()
550
- * ```
551
- *
552
- * @public
553
- */
554
- reloadFeatureFlags(): void;
555
- /**
556
- * Reloads feature flags from the server asynchronously.
557
- *
558
- * PostHog loads feature flags when instantiated and refreshes whenever methods are called that affect the flag.
559
- * If you want to manually trigger a refresh and get the result, you can call this method.
560
- *
561
- * {@label Feature flags}
562
- *
563
- * @example
564
- * ```js
565
- * // reload feature flags and get result
566
- * posthog.reloadFeatureFlagsAsync().then((refreshedFlags) => console.log(refreshedFlags))
567
- * ```
568
- *
569
- * @public
570
- *
571
- * @remarks
572
- * When the `disableRemoteFeatureFlags` option is set, no request is made and the
573
- * promise resolves with the currently stored flags (from `bootstrap` or `updateFlags()`).
574
- *
575
- * @returns Promise that resolves with the refreshed flags
576
- */
577
- reloadFeatureFlagsAsync(): Promise<Record<string, boolean | string> | undefined>;
578
- /**
579
- * Replaces (or merges into) the stored feature flags and payloads with locally supplied
580
- * values, exactly as if they had been returned by the flags endpoint: the values are
581
- * persisted, `getFeatureFlag()`/`getFeatureFlagPayload()` read them back, and
582
- * `onFeatureFlags` listeners fire. Makes no network request.
583
- *
584
- * Intended for apps that evaluate flags outside the SDK (e.g. server-side local
585
- * evaluation) and push the results in at runtime, typically together with the
586
- * `disableRemoteFeatureFlags` option so the SDK never fetches flags itself.
587
- *
588
- * {@label Feature flags}
589
- *
590
- * @remarks
591
- * The values are cleared by `reset()`, so push them again after an identity change.
592
- *
593
- * @example
594
- * ```js
595
- * // replace all stored flags with locally evaluated ones
596
- * posthog.updateFlags({ 'my-flag': true, 'multivariate-flag': 'variant-1' })
597
- * ```
598
- *
599
- * @example
600
- * ```js
601
- * // include payloads
602
- * posthog.updateFlags({ 'my-flag': true }, { 'my-flag': { color: 'blue' } })
603
- * ```
604
- *
605
- * @example
606
- * ```js
607
- * // merge into the stored flags instead of replacing them
608
- * posthog.updateFlags({ 'my-flag': false }, undefined, { merge: true })
609
- * ```
610
- *
611
- * @public
612
- *
613
- * @param flags - Flag keys mapped to their values (boolean, or a variant string)
614
- * @param payloads - Optional flag keys mapped to their JSON payloads
615
- * @param options - Set `merge: true` to merge with the currently stored flags instead of replacing them
616
- */
617
- updateFlags(flags: Record<string, boolean | string>, payloads?: Record<string, JsonType>, options?: {
618
- merge?: boolean;
619
- }): void;
620
- /**
621
- * Associates the current user with a group.
622
- *
623
- * Group analytics allows you to associate the events for that person's session with a group (e.g. teams, organizations, etc.).
624
- * This is a paid feature and is not available on the open-source or free cloud plan.
625
- *
626
- * {@label Group analytics}
627
- *
628
- * @example
629
- * ```js
630
- * // associate with a group
631
- * posthog.group('company', 'company_id_in_your_db')
632
- * ```
633
- *
634
- * @example
635
- * ```js
636
- * // associate with a group and update properties
637
- * posthog.group('company', 'company_id_in_your_db', {
638
- * name: 'Awesome Inc.',
639
- * employees: 11,
640
- * })
641
- * ```
642
- *
643
- * @public
644
- *
645
- * @param groupType The type of group (e.g. 'company', 'team')
646
- * @param groupKey The unique identifier for the group
647
- * @param properties Optional properties to set for the group
648
- */
649
- group(groupType: string, groupKey: string, properties?: PostHogEventProperties): void;
650
- /**
651
- * Assigns an alias to the current user.
652
- *
653
- * Sometimes, you want to assign multiple distinct IDs to a single user. This is helpful when your primary distinct ID is inaccessible.
654
- * For example, if a distinct ID used on the frontend is not available in your backend.
655
- *
656
- * {@label Identification}
657
- *
658
- * @example
659
- * ```js
660
- * // set alias for current user
661
- * posthog.alias('distinct_id')
662
- * ```
663
- *
664
- * @public
665
- *
666
- * @param alias The alias to assign to the current user
667
- */
668
- alias(alias: string): void;
669
- /**
670
- * Gets the current user's distinct ID.
671
- *
672
- * You may find it helpful to get the current user's distinct ID. For example, to check whether you've already called identify for a user or not.
673
- * This returns either the ID automatically generated by PostHog or the ID that has been passed by a call to identify().
674
- *
675
- * {@label Identification}
676
- *
677
- * @example
678
- * ```js
679
- * // get current distinct ID
680
- * const distinctId = posthog.getDistinctId()
681
- * ```
682
- *
683
- * @public
684
- *
685
- * @returns The current user's distinct ID
686
- */
687
- getDistinctId(): string;
688
- /**
689
- * Returns the stable device identifier used for device-level feature flag bucketing.
690
- * This ID persists across identify() and reset() calls, only changing on a fresh
691
- * app install, manual cache clearing, or OS-initiated storage cleanup.
692
- *
693
- * @returns The device ID, or an empty string if not yet initialized
694
- */
695
- getDeviceId(): string;
696
- /**
697
- * Sets person properties for feature flag evaluation.
698
- *
699
- * Sometimes, you might want to evaluate feature flags using properties that haven't been ingested yet, or were set incorrectly earlier.
700
- * You can do so by setting properties the flag depends on with this call. These are set for the entire session.
701
- * Successive calls are additive: all properties you set are combined together and sent for flag evaluation.
702
- *
703
- * {@label Feature flags}
704
- *
705
- * @example
706
- * ```js
707
- * // set person properties for flags
708
- * posthog.setPersonPropertiesForFlags({'property1': 'value', property2: 'value2'})
709
- * ```
710
- *
711
- * @public
712
- *
713
- * @param properties The person properties to set for flag evaluation
714
- * @param reloadFeatureFlags Whether to reload feature flags after setting the properties. Defaults to true.
715
- */
716
- setPersonPropertiesForFlags(properties: Record<string, JsonType>, reloadFeatureFlags?: boolean): void;
717
- /**
718
- * Resets person properties for feature flag evaluation.
719
- *
720
- *
721
- * {@label Feature flags}
722
- *
723
- * @example
724
- * ```js
725
- * // reset person properties for flags
726
- * posthog.resetPersonPropertiesForFlags()
727
- * ```
728
- *
729
- * @public
730
- *
731
- * @param reloadFeatureFlags Whether to reload feature flags after setting the properties. Defaults to true.
732
- */
733
- resetPersonPropertiesForFlags(reloadFeatureFlags?: boolean): void;
734
- /**
735
- * Sets group properties for feature flag evaluation.
736
- *
737
- * These properties are automatically attached to the current group (set via posthog.group()).
738
- * When you change the group, these properties are reset.
739
- *
740
- * {@label Feature flags}
741
- *
742
- * @example
743
- * ```js
744
- * // set group properties for flags
745
- * posthog.setGroupPropertiesForFlags({'company': {'property1': 'value', property2: 'value2'}})
746
- * ```
747
- *
748
- * @public
749
- *
750
- * @param properties The group properties to set for flag evaluation
751
- * @param reloadFeatureFlags Whether to reload feature flags after setting the properties. Defaults to true.
752
- */
753
- setGroupPropertiesForFlags(properties: Record<string, Record<string, JsonType>>, reloadFeatureFlags?: boolean): void;
754
- /**
755
- * Resets group properties for feature flag evaluation.
756
- *
757
- * {@label Feature flags}
758
- *
759
- * @example
760
- * ```js
761
- * // reset group properties for flags
762
- * posthog.resetGroupPropertiesForFlags()
763
- * ```
764
- *
765
- * @public
766
- *
767
- * @param reloadFeatureFlags Whether to reload feature flags after setting the properties. Defaults to true.
768
- */
769
- resetGroupPropertiesForFlags(reloadFeatureFlags?: boolean): void;
770
- /**
771
- * Captures a screen view event.
772
- *
773
- * @remarks
774
- * This function requires a name. You may also pass in an optional properties object.
775
- * Screen name is automatically registered for the session and will be included in subsequent events.
776
- *
777
- * {@label Capture}
778
- *
779
- * @example
780
- * ```js
781
- * // Basic screen capture
782
- * posthog.screen('dashboard')
783
- * ```
784
- *
785
- * @example
786
- * ```js
787
- * // Screen capture with properties
788
- * posthog.screen('dashboard', {
789
- * background: 'blue',
790
- * hero: 'superhog',
791
- * })
792
- * ```
793
- *
794
- * @public
795
- *
796
- * @param name - The name of the screen
797
- * @param properties - Optional properties to include with the screen event
798
- * @param options - Optional capture options
799
- */
800
- screen(name: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): Promise<void>;
801
- _isEnableSessionReplay(): boolean;
802
- _resetSessionId(reactNativeSessionReplay: typeof OptionalReactNativePlugin | undefined, sessionId: string): void;
803
- getSessionId(): string;
804
- resetSessionId(): void;
805
- /**
806
- * Starts session recording.
807
- * This method will have no effect if PostHog is not enabled, or if session replay is disabled in your project settings.
808
- *
809
- * Note: This is only available on iOS and Android. On web/macOS, this is a no-op.
810
- *
811
- * Requires `posthog-react-native-session-replay` version 1.3.0 or higher.
812
- *
813
- * {@label Session Replay}
814
- *
815
- * @example
816
- * ```js
817
- * // Resume the current session recording
818
- * await posthog.startSessionRecording()
819
- * ```
820
- *
821
- * @example
822
- * ```js
823
- * // Start a new session recording
824
- * await posthog.startSessionRecording(false)
825
- * ```
826
- *
827
- * @public
828
- *
829
- * @param resumeCurrent - Whether to resume recording of current session (true) or start a new session (false). Defaults to true.
830
- */
831
- startSessionRecording(resumeCurrent?: boolean): Promise<void>;
832
- private _startSessionRecording;
833
- /**
834
- * Stops the current session recording if one is in progress.
835
- *
836
- * Note: This is only available on iOS and Android. On web/macOS, this is a no-op.
837
- *
838
- * Requires `posthog-react-native-session-replay` version 1.3.0 or higher.
839
- *
840
- * {@label Session Replay}
841
- *
842
- * @example
843
- * ```js
844
- * await posthog.stopSessionRecording()
845
- * ```
846
- * @public
847
- */
848
- stopSessionRecording(): Promise<void>;
849
- private _stopSessionRecording;
850
- /**
851
- * Returns whether session replay is currently active.
852
- *
853
- * Note: This is only available on iOS and Android. On web/macOS, this always returns false.
854
- *
855
- * {@label Session Replay}
856
- *
857
- * @example
858
- * ```js
859
- * const isActive = await posthog.isSessionReplayActive()
860
- * ```
861
- *
862
- * @public
863
- *
864
- * @returns Whether session replay is currently active
865
- */
866
- isSessionReplayActive(): Promise<boolean>;
867
- /**
868
- * Associates events with a specific user. Learn more about [identifying users](https://posthog.com/docs/product-analytics/identify)
869
- *
870
- * {@label Identification}
871
- *
872
- * @example
873
- * ```js
874
- * // Basic identify
875
- * posthog.identify('distinctID', {
876
- * email: 'user@posthog.com',
877
- * name: 'My Name'
878
- * })
879
- * ```
880
- *
881
- * @example
882
- * ```js
883
- * // Using $set and $set_once
884
- * posthog.identify('distinctID', {
885
- * $set: {
886
- * email: 'user@posthog.com',
887
- * name: 'My Name'
888
- * },
889
- * $set_once: {
890
- * date_of_first_log_in: '2024-03-01'
891
- * }
892
- * })
893
- * ```
894
- *
895
- * @public
896
- *
897
- * @param distinctId - A unique identifier for your user. Typically either their email or database ID.
898
- * @param properties - Optional dictionary with key:value pairs to set the person properties
899
- * @param options - Optional capture options
900
- */
901
- identify(distinctId?: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
902
- /**
903
- * Capture a caught exception manually
904
- *
905
- * {@label Error tracking}
906
- *
907
- * @public
908
- *
909
- * @example
910
- * ```js
911
- * // Capture a caught exception
912
- * try {
913
- * // something that might throw
914
- * } catch (error) {
915
- * posthog.captureException(error)
916
- * }
917
- * ```
918
- *
919
- * @example
920
- * ```js
921
- * // With additional properties
922
- * posthog.captureException(error, {
923
- * customProperty: 'value',
924
- * anotherProperty: ['I', 'can be a list'],
925
- * ...
926
- * })
927
- * ```
928
- *
929
- * @param {Error} error The error to capture
930
- * @param {Object} [additionalProperties] Any additional properties to add to the error event
931
- * @returns {void}
932
- */
933
- captureException(error: Error | unknown, additionalProperties?: PostHogEventProperties, hint?: CoreErrorTracking.EventHint): void;
934
- /**
935
- * Records a breadcrumb-style exception step. Steps accumulate in a rolling, byte-bounded buffer
936
- * and are attached to every captured `$exception` as `$exception_steps`, giving the error tracking
937
- * UI a timeline of recent activity before each error.
938
- *
939
- * The `$timestamp` is captured at call time. The reserved keys `$message` and `$timestamp` are
940
- * stripped from `properties` — the SDK sets the canonical values. This method never throws.
941
- *
942
- * @example
943
- * ```js
944
- * posthog.addExceptionStep('User tapped Checkout', { screen: 'cart' })
945
- * ```
946
- *
947
- * @param {string} message A non-empty description of the step
948
- * @param {Object} [properties] Optional additional context to attach to the step
949
- * @returns {void}
950
- */
951
- addExceptionStep(message: string, properties?: Properties): void;
952
- protected createErrorPropertiesBuilder(): CoreErrorTracking.ErrorPropertiesBuilder;
953
- initReactNativeNavigation(options: PostHogAutocaptureOptions): boolean;
954
- /**
955
- * Creates a person profile for the current user, if they don't already have one.
956
- *
957
- * This is useful when using `personProfiles: 'identified_only'` mode and you want to
958
- * explicitly create a profile for an anonymous user before they identify.
959
- *
960
- * If `personProfiles` is 'identified_only' and no profile exists, this will create one.
961
- * If `personProfiles` is 'never', this will log an error and do nothing.
962
- * If `personProfiles` is 'always' or a profile already exists, this is a no-op.
963
- *
964
- * {@label Identification}
965
- *
966
- * @example
967
- * ```js
968
- * // Create a person profile for an anonymous user
969
- * posthog.createPersonProfile()
970
- * ```
971
- *
972
- * @public
973
- */
974
- createPersonProfile(): void;
975
- /**
976
- * Sets properties on the person profile associated with the current `distinct_id`.
977
- * Learn more about [identifying users](https://posthog.com/docs/product-analytics/identify)
978
- *
979
- * {@label Identification}
980
- *
981
- * @remarks
982
- * Updates user properties that are stored with the person profile in PostHog.
983
- * If `personProfiles` is set to `identified_only` and no profile exists, this will create one.
984
- *
985
- * @example
986
- * ```js
987
- * // set user properties
988
- * posthog.setPersonProperties({
989
- * email: 'user@example.com',
990
- * plan: 'premium'
991
- * })
992
- * ```
993
- *
994
- * @example
995
- * ```js
996
- * // set properties with $set_once
997
- * posthog.setPersonProperties(
998
- * { name: 'Max Hedgehog' }, // $set properties
999
- * { initial_url: '/blog' } // $set_once properties
1000
- * )
1001
- * ```
1002
- *
1003
- * @example
1004
- * ```js
1005
- * // set properties without reloading feature flags
1006
- * posthog.setPersonProperties({ plan: 'premium' }, undefined, false)
1007
- * ```
1008
- *
1009
- * @public
1010
- *
1011
- * @param userPropertiesToSet - Optional: An object of properties to store about the user.
1012
- * These properties will overwrite any existing values for the same keys.
1013
- * @param userPropertiesToSetOnce - Optional: An object of properties to store about the user.
1014
- * If a property is previously set, this does not override that value.
1015
- * @param reloadFeatureFlags - Whether to reload feature flags after setting the properties. Defaults to true.
1016
- */
1017
- setPersonProperties(userPropertiesToSet?: {
1018
- [key: string]: JsonType;
1019
- }, userPropertiesToSetOnce?: {
1020
- [key: string]: JsonType;
1021
- }, reloadFeatureFlags?: boolean): void;
1022
- /**
1023
- * Removes properties from the person profile associated with the current `distinct_id`.
1024
- * Learn more about [identifying users](https://posthog.com/docs/product-analytics/identify)
1025
- *
1026
- * {@label Identification}
1027
- *
1028
- * @public
1029
- *
1030
- * @param propertyNames - The name (or names) of the person properties to remove.
1031
- * @param reloadFeatureFlags - Whether to reload feature flags after removing the properties. Defaults to true.
1032
- */
1033
- unsetPersonProperties(propertyNames: string | string[], reloadFeatureFlags?: boolean): void;
1034
- getSurveys(): Promise<SurveyResponse['surveys']>;
1035
- /**
1036
- * Returns a promise that resolves when surveys are ready to be loaded.
1037
- * If surveys are already loaded and ready to go, returns a resolved promise instead.
1038
- * @internal
1039
- */
1040
- _onSurveysReady(): Promise<void>;
1041
- private _surveysReadyResolve;
1042
- /**
1043
- * Helper function to cache surveys to storage with consistent logging
1044
- */
1045
- private _cacheSurveys;
1046
- /**
1047
- * Internal method to notify that surveys are ready
1048
- */
1049
- private _notifySurveysReady;
1050
- /**
1051
- * Handle surveys from remote config response
1052
- */
1053
- private _handleSurveysFromRemoteConfig;
1054
- private _isAutocaptureNativeErrors;
1055
- private _isNativePluginInitialized;
1056
- /**
1057
- * Initializes the native session replay SDK if not already initialized.
1058
- * This is called automatically by startSessionReplay() or lazily by startSessionRecording().
1059
- *
1060
- * @returns true if the native SDK is ready (initialized or already was), false otherwise
1061
- */
1062
- private initializeSessionReplayNative;
1063
- private initializeNativePlugin;
1064
- private startSessionReplay;
1065
- /**
1066
- * Decides whether session replay should be recording (replay enabled AND the linked
1067
- * flag, if any, on for the current user) and arms or pauses the native recorder to match.
1068
- *
1069
- * Runs at startup and on every feature flags load/reload (identify(), reset(),
1070
- * reloadFeatureFlags()), so recording starts, resumes, or pauses on identity changes
1071
- * without an app restart. `_sessionReplayRecordingActive` dedups repeated answers, and
1072
- * the init guards prevent double-starts. When replay is off, the native plugin is still
1073
- * initialized for native error tracking (both share one native instance).
1074
- *
1075
- * Pausing requires a real "flag off": core keeps the previous flag values across
1076
- * quota-limited/failed reloads, so a transient error never pauses a recording. Right
1077
- * after reset() the flags are genuinely unknown and pausing is the intended outcome.
1078
- *
1079
- * Evaluations are serialized so concurrent flags reloads run one at a time.
1080
- */
1081
- private _evaluateAndStartSessionReplay;
1082
- private _evaluateAndStartSessionReplayInternal;
1083
- /**
1084
- * Capture chokepoint for session-replay event triggers. Every captured event (capture, $screen,
1085
- * autocapture, lifecycle) passes through here. Chains to super first so `before_send` still runs;
1086
- * when a surviving event's name matches an armed trigger and the session hasn't activated yet, it
1087
- * activates replay for the session and kicks a re-evaluation that starts native recording. The
1088
- * trigger check never drops an event or throws into the capture path.
1089
- */
1090
- protected processBeforeEnqueue(message: PostHogEventProperties): PostHogEventProperties | null;
1091
- private _maybeActivateEventTrigger;
1092
- private _parseEventTriggers;
1093
- private _isEventTriggerActivatedForSession;
1094
- private captureAppLifecycleEvents;
1095
- private persistAppVersion;
1096
- }
1
+ import { CaptureLogOptions, CaptureLogger, JsonType, TxlemetryCaptureOptions, TxlemetryCore, TxlemetryCoreOptions, TxlemetryEventProperties, TxlemetryFetchOptions, TxlemetryFetchResponse, TxlemetryLogsConfig, TxlemetryPersistedProperty, TxlemetryRemoteConfig, SurveyResponse, FeatureFlagResultOptions, ErrorTracking as CoreErrorTracking } from '@txlemetry/core';
2
+ import { Properties } from '@txlemetry/types';
3
+ import { TxlemetryAutocaptureOptions, TxlemetryCustomAppProperties, TxlemetryCustomStorage, TxlemetrySessionReplayConfig } from './types';
4
+ import { OptionalReactNativePlugin } from './optional/OptionalPlugin';
5
+ import { ErrorTrackingOptions } from './error-tracking';
6
+ export { TxlemetryPersistedProperty };
7
+ export interface TxlemetryOptions extends TxlemetryCoreOptions {
8
+ /**
9
+ * Allows you to provide the storage type.
10
+ * 'file' will try to load the best available storage, the provided 'customStorage', 'customAsyncStorage' or in-memory storage.
11
+ *
12
+ * @default 'file'
13
+ */
14
+ persistence?: 'memory' | 'file';
15
+ /** Allows you to provide your own implementation of the common information about your App or a function to modify the default App properties generated */
16
+ customAppProperties?: TxlemetryCustomAppProperties | ((properties: TxlemetryCustomAppProperties) => TxlemetryCustomAppProperties);
17
+ /**
18
+ * Allows you to provide a custom asynchronous storage such as async-storage, expo-file-system or a synchronous storage such as mmkv.
19
+ * If not provided, Txlemetry will attempt to use the best available storage via optional peer dependencies (async-storage, expo-file-system).
20
+ * If `persistence` is set to 'memory', this option will be ignored.
21
+ */
22
+ customStorage?: TxlemetryCustomStorage;
23
+ /**
24
+ * A list of headers that should be sent with requests to the Txlemetry API.
25
+ */
26
+ requestHeaders?: {
27
+ [header_name: string]: string;
28
+ };
29
+ /**
30
+ * Captures app lifecycle events such as Application Installed, Application Updated, Application Opened, Application Became Active and Application Backgrounded.
31
+ * Application Installed and Application Updated events are not supported with persistence set to 'memory'.
32
+ *
33
+ * @default true
34
+ */
35
+ captureAppLifecycleEvents?: boolean;
36
+ /**
37
+ * Enable Recording of Session Replays for Android and iOS
38
+ * Requires Record user sessions to be enabled in the Txlemetry Project Settings
39
+ *
40
+ * @default false
41
+ */
42
+ enableSessionReplay?: boolean;
43
+ /**
44
+ * Configuration for Session Replay
45
+ */
46
+ sessionReplayConfig?: TxlemetrySessionReplayConfig;
47
+ /**
48
+ * If enabled, the session id ($session_id) will be persisted across app restarts.
49
+ * This is an option for back compatibility, so your current data isn't skewed with the new version of the SDK.
50
+ * If this is false, the session id will be always reset on app restart.
51
+ *
52
+ * @default false
53
+ */
54
+ enablePersistSessionIdAcrossRestart?: boolean;
55
+ /**
56
+ * Error Tracking Configuration
57
+ */
58
+ errorTracking?: ErrorTrackingOptions;
59
+ /**
60
+ * Automatically include common device and app properties in feature flag evaluation.
61
+ *
62
+ * When enabled, the following properties are sent with every /flags request:
63
+ * - $app_version: App version
64
+ * - $app_build: App build number
65
+ * - $app_namespace: App bundle identifier / namespace
66
+ * - $os_name: Operating system name
67
+ * - $os_version: Operating system version
68
+ * - $device_type: Device type (Mobile, Desktop)
69
+ * - $lib: Name of the SDK library
70
+ * - $lib_version: Version of the SDK library
71
+ *
72
+ * This ensures feature flags that rely on these properties work correctly
73
+ * without waiting for server-side processing of identify() calls.
74
+ *
75
+ * @default true
76
+ */
77
+ setDefaultPersonProperties?: boolean;
78
+ /**
79
+ * Logs feature configuration. Enables structured log capture via
80
+ * `txlemetry.captureLog(...)` or `txlemetry.logger.info(...)`. Records ship to
81
+ * Txlemetry's logs product (`/i/v1/logs`) in OTLP format, batched on a timer,
82
+ * AppState change, buffer fill, or manual `flushLogs()`.
83
+ *
84
+ * Capture is **unconditional** — calling the API ships records as long as
85
+ * the SDK is initialized and the user hasn't opted out. The only blockers
86
+ * are `optedOut`, missing/empty `body`, and missing API key.
87
+ *
88
+ * All fields below are optional; per-SDK defaults apply (mobile defaults
89
+ * are tuned for cellular bandwidth and battery, ~50 logs/sec ceiling).
90
+ *
91
+ * @example Minimal — just service tagging, defaults for everything else
92
+ * ```ts
93
+ * new Txlemetry(key, {
94
+ * logs: { serviceName: 'my-app', environment: 'production' }
95
+ * })
96
+ * ```
97
+ *
98
+ * @example Tune for higher-volume logging
99
+ * ```ts
100
+ * new Txlemetry(key, {
101
+ * logs: {
102
+ * serviceName: 'my-app',
103
+ * rateCap: { maxLogs: 5000, windowMs: 60000 },
104
+ * maxBufferSize: 500,
105
+ * beforeSend: (r) => r.body.includes('secret') ? null : r,
106
+ * }
107
+ * })
108
+ * ```
109
+ */
110
+ logs?: TxlemetryLogsConfig;
111
+ /**
112
+ * Overrides the language used when rendering translated survey copy.
113
+ * When unset, the SDK falls back to the persisted person property `language`
114
+ * and then the device locale.
115
+ */
116
+ overrideDisplayLanguage?: string | null;
117
+ }
118
+ export declare class Txlemetry extends TxlemetryCore {
119
+ private _persistence;
120
+ private _eventsStorage;
121
+ private _logsStorage;
122
+ private _appProperties;
123
+ private _currentSessionId?;
124
+ private _enableSessionReplay?;
125
+ private _sessionReplayNativeInitialized;
126
+ private _nativeErrorTrackingInitialized;
127
+ private _sessionReplayRecordingActive?;
128
+ private _sessionReplayEvalChain;
129
+ private _sessionReplayOptions?;
130
+ private _sessionReplayEventTriggers;
131
+ private _disableSurveys;
132
+ private _errorTracking;
133
+ private _logs;
134
+ private _resolvedLogsConfig;
135
+ private _currentAppState?;
136
+ private _surveysReadyPromise;
137
+ private _surveysReady;
138
+ private _setDefaultPersonProperties;
139
+ private _overrideDisplayLanguage;
140
+ private _requestHeaders;
141
+ /**
142
+ * Creates a new Txlemetry instance for React Native. You can find all configuration options in the [React Native SDK docs](https://txlemetry.com/docs/libraries/react-native#configuration-options).
143
+ *
144
+ * If you prefer not to use the TxlemetryProvider, you can initialize Txlemetry in its own file and import the instance from there.
145
+ *
146
+ * {@label Initialization}
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * // txlemetry.ts
151
+ * import Txlemetry from 'txlemetry-react-native'
152
+ *
153
+ * export const txlemetry = new Txlemetry('<ph_project_api_key>', {
154
+ * host: '<ph_client_api_host>'
155
+ * })
156
+ *
157
+ * // Then you can access Txlemetry by importing your instance
158
+ * // Another file:
159
+ * import { txlemetry } from './txlemetry'
160
+ *
161
+ * export function MyApp1() {
162
+ * useEffect(async () => {
163
+ * txlemetry.capture('event_name')
164
+ * }, [txlemetry])
165
+ *
166
+ * return <View>Your app code</View>
167
+ * }
168
+ * ```
169
+ *
170
+ * @public
171
+ *
172
+ * @param apiKey - Your Txlemetry API key
173
+ * @param options - Txlemetry configuration options
174
+ */
175
+ constructor(apiKey: string, options?: TxlemetryOptions);
176
+ /**
177
+ *
178
+ * @internal
179
+ *
180
+ */
181
+ ready(): Promise<void>;
182
+ /**
183
+ * Called when remote config has been loaded (from either the remote config endpoint or the flags endpoint).
184
+ * Gates error tracking autocapture based on the remote config response.
185
+ *
186
+ * Session replay config (consoleLogRecordingEnabled, sampleRate, capturePerformance.network_timing) is already
187
+ * cached via TxlemetryPersistedProperty.RemoteConfig and applied at startup in startSessionReplay().
188
+ *
189
+ * @internal
190
+ */
191
+ protected onRemoteConfig(response: TxlemetryRemoteConfig): void;
192
+ /**
193
+ * Resolves the storage instance for a given persisted-property key.
194
+ * `LogsQueue` routes to `_logsStorage` (dedicated `.txlemetry-rn-logs.json`
195
+ * file); every other key routes to `_eventsStorage`. Single source of
196
+ * truth for routing — extending to new logs-scoped keys is a one-line
197
+ * edit here.
198
+ */
199
+ private _storageForKey;
200
+ getPersistedProperty<T>(key: TxlemetryPersistedProperty): T | undefined;
201
+ setPersistedProperty<T>(key: TxlemetryPersistedProperty, value: T | null): void;
202
+ /**
203
+ * Waits for any pending storage operations to complete.
204
+ * This ensures data has been safely written to async storage before
205
+ * considering events as sent, preventing duplicate events on app crash/restart.
206
+ */
207
+ protected flushStorage(): Promise<void>;
208
+ /**
209
+ * Drain both pipelines on shutdown. Run in parallel so the logs final
210
+ * flush + timer teardown doesn't serialize behind events (and vice-versa).
211
+ * `_logs.shutdown()` swallows its own errors — a transient logs failure
212
+ * must not break events shutdown.
213
+ *
214
+ * Logs use the smaller of `terminationFlushBudgetMs` and the caller's
215
+ * `shutdownTimeoutMs` so a final flush can never run past the caller's
216
+ * shutdown SLA, while still respecting the configured logs-specific
217
+ * termination budget when it's tighter.
218
+ *
219
+ * After the flushes, drain any debounced storage writes that weren't already
220
+ * persisted via the queue-advance path — `setPersistedProperty` calls for
221
+ * distinctId, sessionId, deviceId, feature flag overrides, etc. only arm a
222
+ * debounced write. The drain runs in `finally` so a timed-out flush still
223
+ * persists them, and its await is bounded by the time left in the shutdown
224
+ * SLA so a hung storage backend can't run past it.
225
+ */
226
+ _shutdown(shutdownTimeoutMs?: number): Promise<void>;
227
+ fetch(url: string, options: TxlemetryFetchOptions): Promise<TxlemetryFetchResponse>;
228
+ getLibraryId(): string;
229
+ getLibraryVersion(): string;
230
+ getCustomUserAgent(): string;
231
+ protected getCustomHeaders(): {
232
+ [key: string]: string;
233
+ };
234
+ getCommonEventProperties(): TxlemetryEventProperties;
235
+ getSurveyDisplayLanguageOverride(): string | null;
236
+ /**
237
+ * Registers super properties that are sent with every event.
238
+ *
239
+ * Super properties are properties associated with events that are set once and then sent with every capture call.
240
+ * They persist across sessions and are stored locally.
241
+ *
242
+ * {@label Capture}
243
+ *
244
+ * @example
245
+ * ```js
246
+ * // register super properties
247
+ * txlemetry.register({
248
+ * 'icecream pref': 'vanilla',
249
+ * team_id: 22,
250
+ * })
251
+ * ```
252
+ *
253
+ * @public
254
+ *
255
+ * @param properties An associative array of properties to store about the user
256
+ */
257
+ register(properties: TxlemetryEventProperties): Promise<void>;
258
+ /**
259
+ * Removes a super property so it won't be sent with future events.
260
+ *
261
+ * Super Properties are persisted across sessions so you have to explicitly remove them if they are no longer relevant.
262
+ *
263
+ * {@label Capture}
264
+ *
265
+ * @example
266
+ * ```js
267
+ * // remove a super property
268
+ * txlemetry.unregister('icecream pref')
269
+ * ```
270
+ *
271
+ * @public
272
+ *
273
+ * @param property The name of the super property to remove
274
+ */
275
+ unregister(property: string): Promise<void>;
276
+ /**
277
+ * Resets the user's ID and anonymous ID after logout.
278
+ *
279
+ * To reset the user's ID and anonymous ID, call reset. Usually you would do this right after the user logs out.
280
+ * This also clears all stored super properties and more.
281
+ *
282
+ * By default (when `propertiesToKeep` is not provided), the app lifecycle properties
283
+ * (`InstalledAppBuild` and `InstalledAppVersion`) are automatically preserved to prevent
284
+ * duplicate "Application Installed" events on the next app launch.
285
+ *
286
+ * If you pass `propertiesToKeep` explicitly, only the properties you specify will be preserved.
287
+ * To keep the default app lifecycle behavior, include `TxlemetryPersistedProperty.InstalledAppBuild`
288
+ * and `TxlemetryPersistedProperty.InstalledAppVersion` in your array.
289
+ *
290
+ * Note: The event queue (`TxlemetryPersistedProperty.Queue`) and logs queue
291
+ * (`TxlemetryPersistedProperty.LogsQueue`) are always preserved regardless of
292
+ * what is passed in `propertiesToKeep`, to ensure in-flight data is not lost.
293
+ *
294
+ * The project-level remote config (`TxlemetryPersistedProperty.RemoteConfig`,
295
+ * `TxlemetryPersistedProperty.SessionReplay`, `TxlemetryPersistedProperty.Surveys`) is also
296
+ * always preserved — it is not user data — so session replay and surveys keep working
297
+ * after an identity change. The user-specific survey state (`SurveysSeen`,
298
+ * `SurveyLastSeenDate`) is still cleared.
299
+ *
300
+ * {@label Identification}
301
+ *
302
+ * @example
303
+ * ```js
304
+ * // reset after logout (preserves app lifecycle properties by default)
305
+ * txlemetry.reset()
306
+ * ```
307
+ *
308
+ * @example
309
+ * ```js
310
+ * // reset but keep feature flag overrides and app lifecycle properties
311
+ * txlemetry.reset([
312
+ * TxlemetryPersistedProperty.OverrideFeatureFlags,
313
+ * TxlemetryPersistedProperty.InstalledAppBuild,
314
+ * TxlemetryPersistedProperty.InstalledAppVersion,
315
+ * ])
316
+ * ```
317
+ *
318
+ * @param propertiesToKeep - Optional array of persisted properties to preserve during reset.
319
+ * When not provided, app lifecycle and device bucketing properties are automatically preserved.
320
+ * When provided, only the specified properties are preserved.
321
+ * The event queue and logs queue are always preserved regardless.
322
+ *
323
+ * @public
324
+ */
325
+ reset(propertiesToKeep?: TxlemetryPersistedProperty[]): void;
326
+ /**
327
+ * Helper to extract and set default person properties from app properties
328
+ *
329
+ * @private
330
+ *
331
+ * @param reloadFeatureFlags Whether to reload feature flags after setting the properties. Defaults to true.
332
+ */
333
+ private _setDefaultPersonPropertiesForFlags;
334
+ /**
335
+ * Manually flushes the event queue.
336
+ *
337
+ * You can set the number of events in the configuration that should queue before flushing.
338
+ * Setting this to 1 will send events immediately and will use more battery. This is set to 20 by default.
339
+ * You can also manually flush the queue. If a flush is already in progress it returns a promise for the existing flush.
340
+ *
341
+ * Note: this drains the **events** pipeline only. Logs are flushed via
342
+ * {@link flushLogs}, and {@link shutdown} drains both before terminating.
343
+ *
344
+ * {@label Capture}
345
+ *
346
+ * @example
347
+ * ```js
348
+ * // manually flush the queue
349
+ * await txlemetry.flush()
350
+ * ```
351
+ *
352
+ * @see flushLogs
353
+ * @public
354
+ *
355
+ * @returns Promise that resolves when the flush is complete
356
+ */
357
+ flush(): Promise<void>;
358
+ /**
359
+ * Captures a structured log record and sends it to Txlemetry's logs product
360
+ * (`/i/v1/logs`). Low-level primitive — most callers will prefer
361
+ * `txlemetry.logger.info(...)` / `.warn(...)` / `.error(...)` etc., which
362
+ * wrap this with a level pre-set.
363
+ *
364
+ * Records are buffered per-session, rate-limited, batched into OTLP
365
+ * payloads, and flushed on a timer, on AppState change, or when the
366
+ * buffer reaches capacity. Configure flush cadence, rate cap, and a
367
+ * `beforeSend` filter via the `logs` option on `new Txlemetry(...)`.
368
+ *
369
+ * Note — naming collision: `txlemetry.captureLog()` (this method) is the
370
+ * **logs product** API. There is also a separate, pre-existing
371
+ * `sessionReplayConfig.captureLog` boolean that controls whether
372
+ * **session replay** records the device's `console.*` output. The two
373
+ * are unrelated: this method emits structured records to the logs
374
+ * pipeline regardless of whether session replay is on.
375
+ *
376
+ * {@label Capture}
377
+ *
378
+ * @example
379
+ * ```ts
380
+ * txlemetry.captureLog({
381
+ * body: 'checkout completed',
382
+ * level: 'info',
383
+ * attributes: { order_id: 'ord_789', amount_cents: 4999 },
384
+ * })
385
+ * ```
386
+ *
387
+ * @public
388
+ *
389
+ * @param options Log record. `body` is required; `level` defaults to
390
+ * `'info'`. `attributes` are attached as OTLP key-value attributes
391
+ * and will override auto-populated ones (distinctId, sessionId) on
392
+ * key conflict.
393
+ */
394
+ captureLog(options: CaptureLogOptions): void;
395
+ /**
396
+ * Manually flushes the logs queue.
397
+ *
398
+ * Logs flush automatically on a timer, when the buffer fills, or on
399
+ * AppState change — most apps never need to call this. Use it when you
400
+ * want a synchronous-style hand-off (e.g. before navigating away from a
401
+ * critical screen, in a custom crash handler, or while testing locally).
402
+ *
403
+ * If a flush is already in progress, both callers join the same in-flight
404
+ * promise — no double-send.
405
+ *
406
+ * Note: this drains the **logs** pipeline only. Events are flushed via
407
+ * {@link flush}, and {@link shutdown} drains both before terminating.
408
+ *
409
+ * {@label Capture}
410
+ *
411
+ * @example
412
+ * ```ts
413
+ * await txlemetry.flushLogs()
414
+ * ```
415
+ *
416
+ * @see flush
417
+ * @public
418
+ *
419
+ * @returns Promise that resolves when the flush is complete.
420
+ */
421
+ flushLogs(): Promise<void>;
422
+ private _captureLogger?;
423
+ /**
424
+ * Convenience per-level logger. Each method is shorthand for
425
+ * `txlemetry.captureLog({ body, level, attributes })`. Lazily constructed
426
+ * on first access, then reused.
427
+ *
428
+ * {@label Capture}
429
+ *
430
+ * @example
431
+ * ```ts
432
+ * txlemetry.logger.info('checkout completed', { order_id: 'ord_789' })
433
+ * txlemetry.logger.error('payment failed', { code: 'E001' })
434
+ * ```
435
+ *
436
+ * @public
437
+ */
438
+ get logger(): CaptureLogger;
439
+ /**
440
+ * Opts the user in to data capture.
441
+ *
442
+ * By default, Txlemetry has tracking enabled unless it is forcefully disabled by default using the option { defaultOptIn: false }.
443
+ * Once this has been called it is persisted and will be respected until optOut is called again or the reset function is called.
444
+ *
445
+ * {@label Privacy}
446
+ *
447
+ * @example
448
+ * ```js
449
+ * // opt in to tracking
450
+ * txlemetry.optIn()
451
+ * ```
452
+ *
453
+ * @public
454
+ */
455
+ optIn(): Promise<void>;
456
+ /**
457
+ * Opts the user out of data capture.
458
+ *
459
+ * You can completely opt-out users from data capture. Once this has been called it is persisted and will be respected until optIn is called again or the reset function is called.
460
+ *
461
+ * {@label Privacy}
462
+ *
463
+ * @example
464
+ * ```js
465
+ * // opt out of tracking
466
+ * txlemetry.optOut()
467
+ * ```
468
+ *
469
+ * @public
470
+ */
471
+ optOut(): Promise<void>;
472
+ /**
473
+ * Checks if a feature flag is enabled for the current user.
474
+ *
475
+ * Defaults to undefined if not loaded yet or if there was a problem loading.
476
+ *
477
+ * {@label Feature flags}
478
+ *
479
+ * @example
480
+ * ```js
481
+ * // check if feature flag is enabled
482
+ * const isEnabled = txlemetry.isFeatureEnabled('key-for-your-boolean-flag')
483
+ * ```
484
+ *
485
+ * @public
486
+ *
487
+ * @param key The feature flag key
488
+ * @param options Optional per-call settings
489
+ * @returns True if enabled, false if disabled, undefined if not loaded
490
+ */
491
+ isFeatureEnabled(key: string, options?: FeatureFlagResultOptions): boolean | undefined;
492
+ /**
493
+ * Gets the value of a feature flag for the current user.
494
+ *
495
+ * Defaults to undefined if not loaded yet or if there was a problem loading.
496
+ * Multivariant feature flags are returned as a string.
497
+ *
498
+ * {@label Feature flags}
499
+ *
500
+ * @example
501
+ * ```js
502
+ * // get feature flag value
503
+ * const value = txlemetry.getFeatureFlag('key-for-your-boolean-flag')
504
+ * ```
505
+ *
506
+ * @public
507
+ *
508
+ * @param key The feature flag key
509
+ * @param options Optional per-call settings
510
+ * @returns The feature flag value or undefined if not loaded
511
+ */
512
+ getFeatureFlag(key: string, options?: FeatureFlagResultOptions): boolean | string | undefined;
513
+ /**
514
+ * Gets the payload of a feature flag for the current user.
515
+ *
516
+ * Returns JsonType or undefined if not loaded yet or if there was a problem loading.
517
+ *
518
+ * {@label Feature flags}
519
+ *
520
+ * @deprecated Use `getFeatureFlagResult()` instead, which returns the flag value and payload from a single evaluation.
521
+ *
522
+ * @example
523
+ * ```js
524
+ * // get feature flag payload
525
+ * const payload = txlemetry.getFeatureFlagResult('key-for-your-multivariate-flag')?.payload
526
+ * ```
527
+ *
528
+ * @public
529
+ *
530
+ * @param key The feature flag key
531
+ * @returns The feature flag payload or undefined if not loaded
532
+ */
533
+ getFeatureFlagPayload(key: string): JsonType | undefined;
534
+ /**
535
+ * Reloads feature flags from the server.
536
+ *
537
+ * Txlemetry loads feature flags when instantiated and refreshes whenever methods are called that affect the flag.
538
+ * If you want to manually trigger a refresh, you can call this method.
539
+ *
540
+ * {@label Feature flags}
541
+ *
542
+ * @remarks
543
+ * When the `disableRemoteFeatureFlags` option is set, this method is a no-op; supply
544
+ * flag values via `updateFlags()` instead.
545
+ *
546
+ * @example
547
+ * ```js
548
+ * // reload feature flags
549
+ * txlemetry.reloadFeatureFlags()
550
+ * ```
551
+ *
552
+ * @public
553
+ */
554
+ reloadFeatureFlags(): void;
555
+ /**
556
+ * Reloads feature flags from the server asynchronously.
557
+ *
558
+ * Txlemetry loads feature flags when instantiated and refreshes whenever methods are called that affect the flag.
559
+ * If you want to manually trigger a refresh and get the result, you can call this method.
560
+ *
561
+ * {@label Feature flags}
562
+ *
563
+ * @example
564
+ * ```js
565
+ * // reload feature flags and get result
566
+ * txlemetry.reloadFeatureFlagsAsync().then((refreshedFlags) => console.log(refreshedFlags))
567
+ * ```
568
+ *
569
+ * @public
570
+ *
571
+ * @remarks
572
+ * When the `disableRemoteFeatureFlags` option is set, no request is made and the
573
+ * promise resolves with the currently stored flags (from `bootstrap` or `updateFlags()`).
574
+ *
575
+ * @returns Promise that resolves with the refreshed flags
576
+ */
577
+ reloadFeatureFlagsAsync(): Promise<Record<string, boolean | string> | undefined>;
578
+ /**
579
+ * Replaces (or merges into) the stored feature flags and payloads with locally supplied
580
+ * values, exactly as if they had been returned by the flags endpoint: the values are
581
+ * persisted, `getFeatureFlag()`/`getFeatureFlagPayload()` read them back, and
582
+ * `onFeatureFlags` listeners fire. Makes no network request.
583
+ *
584
+ * Intended for apps that evaluate flags outside the SDK (e.g. server-side local
585
+ * evaluation) and push the results in at runtime, typically together with the
586
+ * `disableRemoteFeatureFlags` option so the SDK never fetches flags itself.
587
+ *
588
+ * {@label Feature flags}
589
+ *
590
+ * @remarks
591
+ * The values are cleared by `reset()`, so push them again after an identity change.
592
+ *
593
+ * @example
594
+ * ```js
595
+ * // replace all stored flags with locally evaluated ones
596
+ * txlemetry.updateFlags({ 'my-flag': true, 'multivariate-flag': 'variant-1' })
597
+ * ```
598
+ *
599
+ * @example
600
+ * ```js
601
+ * // include payloads
602
+ * txlemetry.updateFlags({ 'my-flag': true }, { 'my-flag': { color: 'blue' } })
603
+ * ```
604
+ *
605
+ * @example
606
+ * ```js
607
+ * // merge into the stored flags instead of replacing them
608
+ * txlemetry.updateFlags({ 'my-flag': false }, undefined, { merge: true })
609
+ * ```
610
+ *
611
+ * @public
612
+ *
613
+ * @param flags - Flag keys mapped to their values (boolean, or a variant string)
614
+ * @param payloads - Optional flag keys mapped to their JSON payloads
615
+ * @param options - Set `merge: true` to merge with the currently stored flags instead of replacing them
616
+ */
617
+ updateFlags(flags: Record<string, boolean | string>, payloads?: Record<string, JsonType>, options?: {
618
+ merge?: boolean;
619
+ }): void;
620
+ /**
621
+ * Associates the current user with a group.
622
+ *
623
+ * Group analytics allows you to associate the events for that person's session with a group (e.g. teams, organizations, etc.).
624
+ * This is a paid feature and is not available on the open-source or free cloud plan.
625
+ *
626
+ * {@label Group analytics}
627
+ *
628
+ * @example
629
+ * ```js
630
+ * // associate with a group
631
+ * txlemetry.group('company', 'company_id_in_your_db')
632
+ * ```
633
+ *
634
+ * @example
635
+ * ```js
636
+ * // associate with a group and update properties
637
+ * txlemetry.group('company', 'company_id_in_your_db', {
638
+ * name: 'Awesome Inc.',
639
+ * employees: 11,
640
+ * })
641
+ * ```
642
+ *
643
+ * @public
644
+ *
645
+ * @param groupType The type of group (e.g. 'company', 'team')
646
+ * @param groupKey The unique identifier for the group
647
+ * @param properties Optional properties to set for the group
648
+ */
649
+ group(groupType: string, groupKey: string, properties?: TxlemetryEventProperties): void;
650
+ /**
651
+ * Assigns an alias to the current user.
652
+ *
653
+ * Sometimes, you want to assign multiple distinct IDs to a single user. This is helpful when your primary distinct ID is inaccessible.
654
+ * For example, if a distinct ID used on the frontend is not available in your backend.
655
+ *
656
+ * {@label Identification}
657
+ *
658
+ * @example
659
+ * ```js
660
+ * // set alias for current user
661
+ * txlemetry.alias('distinct_id')
662
+ * ```
663
+ *
664
+ * @public
665
+ *
666
+ * @param alias The alias to assign to the current user
667
+ */
668
+ alias(alias: string): void;
669
+ /**
670
+ * Gets the current user's distinct ID.
671
+ *
672
+ * You may find it helpful to get the current user's distinct ID. For example, to check whether you've already called identify for a user or not.
673
+ * This returns either the ID automatically generated by Txlemetry or the ID that has been passed by a call to identify().
674
+ *
675
+ * {@label Identification}
676
+ *
677
+ * @example
678
+ * ```js
679
+ * // get current distinct ID
680
+ * const distinctId = txlemetry.getDistinctId()
681
+ * ```
682
+ *
683
+ * @public
684
+ *
685
+ * @returns The current user's distinct ID
686
+ */
687
+ getDistinctId(): string;
688
+ /**
689
+ * Returns the stable device identifier used for device-level feature flag bucketing.
690
+ * This ID persists across identify() and reset() calls, only changing on a fresh
691
+ * app install, manual cache clearing, or OS-initiated storage cleanup.
692
+ *
693
+ * @returns The device ID, or an empty string if not yet initialized
694
+ */
695
+ getDeviceId(): string;
696
+ /**
697
+ * Sets person properties for feature flag evaluation.
698
+ *
699
+ * Sometimes, you might want to evaluate feature flags using properties that haven't been ingested yet, or were set incorrectly earlier.
700
+ * You can do so by setting properties the flag depends on with this call. These are set for the entire session.
701
+ * Successive calls are additive: all properties you set are combined together and sent for flag evaluation.
702
+ *
703
+ * {@label Feature flags}
704
+ *
705
+ * @example
706
+ * ```js
707
+ * // set person properties for flags
708
+ * txlemetry.setPersonPropertiesForFlags({'property1': 'value', property2: 'value2'})
709
+ * ```
710
+ *
711
+ * @public
712
+ *
713
+ * @param properties The person properties to set for flag evaluation
714
+ * @param reloadFeatureFlags Whether to reload feature flags after setting the properties. Defaults to true.
715
+ */
716
+ setPersonPropertiesForFlags(properties: Record<string, JsonType>, reloadFeatureFlags?: boolean): void;
717
+ /**
718
+ * Resets person properties for feature flag evaluation.
719
+ *
720
+ *
721
+ * {@label Feature flags}
722
+ *
723
+ * @example
724
+ * ```js
725
+ * // reset person properties for flags
726
+ * txlemetry.resetPersonPropertiesForFlags()
727
+ * ```
728
+ *
729
+ * @public
730
+ *
731
+ * @param reloadFeatureFlags Whether to reload feature flags after setting the properties. Defaults to true.
732
+ */
733
+ resetPersonPropertiesForFlags(reloadFeatureFlags?: boolean): void;
734
+ /**
735
+ * Sets group properties for feature flag evaluation.
736
+ *
737
+ * These properties are automatically attached to the current group (set via txlemetry.group()).
738
+ * When you change the group, these properties are reset.
739
+ *
740
+ * {@label Feature flags}
741
+ *
742
+ * @example
743
+ * ```js
744
+ * // set group properties for flags
745
+ * txlemetry.setGroupPropertiesForFlags({'company': {'property1': 'value', property2: 'value2'}})
746
+ * ```
747
+ *
748
+ * @public
749
+ *
750
+ * @param properties The group properties to set for flag evaluation
751
+ * @param reloadFeatureFlags Whether to reload feature flags after setting the properties. Defaults to true.
752
+ */
753
+ setGroupPropertiesForFlags(properties: Record<string, Record<string, JsonType>>, reloadFeatureFlags?: boolean): void;
754
+ /**
755
+ * Resets group properties for feature flag evaluation.
756
+ *
757
+ * {@label Feature flags}
758
+ *
759
+ * @example
760
+ * ```js
761
+ * // reset group properties for flags
762
+ * txlemetry.resetGroupPropertiesForFlags()
763
+ * ```
764
+ *
765
+ * @public
766
+ *
767
+ * @param reloadFeatureFlags Whether to reload feature flags after setting the properties. Defaults to true.
768
+ */
769
+ resetGroupPropertiesForFlags(reloadFeatureFlags?: boolean): void;
770
+ /**
771
+ * Captures a screen view event.
772
+ *
773
+ * @remarks
774
+ * This function requires a name. You may also pass in an optional properties object.
775
+ * Screen name is automatically registered for the session and will be included in subsequent events.
776
+ *
777
+ * {@label Capture}
778
+ *
779
+ * @example
780
+ * ```js
781
+ * // Basic screen capture
782
+ * txlemetry.screen('dashboard')
783
+ * ```
784
+ *
785
+ * @example
786
+ * ```js
787
+ * // Screen capture with properties
788
+ * txlemetry.screen('dashboard', {
789
+ * background: 'blue',
790
+ * hero: 'superhog',
791
+ * })
792
+ * ```
793
+ *
794
+ * @public
795
+ *
796
+ * @param name - The name of the screen
797
+ * @param properties - Optional properties to include with the screen event
798
+ * @param options - Optional capture options
799
+ */
800
+ screen(name: string, properties?: TxlemetryEventProperties, options?: TxlemetryCaptureOptions): Promise<void>;
801
+ _isEnableSessionReplay(): boolean;
802
+ _resetSessionId(reactNativeSessionReplay: typeof OptionalReactNativePlugin | undefined, sessionId: string): void;
803
+ getSessionId(): string;
804
+ resetSessionId(): void;
805
+ /**
806
+ * Starts session recording.
807
+ * This method will have no effect if Txlemetry is not enabled, or if session replay is disabled in your project settings.
808
+ *
809
+ * Note: This is only available on iOS and Android. On web/macOS, this is a no-op.
810
+ *
811
+ * Requires `txlemetry-react-native-session-replay` version 1.3.0 or higher.
812
+ *
813
+ * {@label Session Replay}
814
+ *
815
+ * @example
816
+ * ```js
817
+ * // Resume the current session recording
818
+ * await txlemetry.startSessionRecording()
819
+ * ```
820
+ *
821
+ * @example
822
+ * ```js
823
+ * // Start a new session recording
824
+ * await txlemetry.startSessionRecording(false)
825
+ * ```
826
+ *
827
+ * @public
828
+ *
829
+ * @param resumeCurrent - Whether to resume recording of current session (true) or start a new session (false). Defaults to true.
830
+ */
831
+ startSessionRecording(resumeCurrent?: boolean): Promise<void>;
832
+ private _startSessionRecording;
833
+ /**
834
+ * Stops the current session recording if one is in progress.
835
+ *
836
+ * Note: This is only available on iOS and Android. On web/macOS, this is a no-op.
837
+ *
838
+ * Requires `txlemetry-react-native-session-replay` version 1.3.0 or higher.
839
+ *
840
+ * {@label Session Replay}
841
+ *
842
+ * @example
843
+ * ```js
844
+ * await txlemetry.stopSessionRecording()
845
+ * ```
846
+ * @public
847
+ */
848
+ stopSessionRecording(): Promise<void>;
849
+ private _stopSessionRecording;
850
+ /**
851
+ * Returns whether session replay is currently active.
852
+ *
853
+ * Note: This is only available on iOS and Android. On web/macOS, this always returns false.
854
+ *
855
+ * {@label Session Replay}
856
+ *
857
+ * @example
858
+ * ```js
859
+ * const isActive = await txlemetry.isSessionReplayActive()
860
+ * ```
861
+ *
862
+ * @public
863
+ *
864
+ * @returns Whether session replay is currently active
865
+ */
866
+ isSessionReplayActive(): Promise<boolean>;
867
+ /**
868
+ * Associates events with a specific user. Learn more about [identifying users](https://txlemetry.com/docs/product-analytics/identify)
869
+ *
870
+ * {@label Identification}
871
+ *
872
+ * @example
873
+ * ```js
874
+ * // Basic identify
875
+ * txlemetry.identify('distinctID', {
876
+ * email: 'user@txlemetry.com',
877
+ * name: 'My Name'
878
+ * })
879
+ * ```
880
+ *
881
+ * @example
882
+ * ```js
883
+ * // Using $set and $set_once
884
+ * txlemetry.identify('distinctID', {
885
+ * $set: {
886
+ * email: 'user@txlemetry.com',
887
+ * name: 'My Name'
888
+ * },
889
+ * $set_once: {
890
+ * date_of_first_log_in: '2024-03-01'
891
+ * }
892
+ * })
893
+ * ```
894
+ *
895
+ * @public
896
+ *
897
+ * @param distinctId - A unique identifier for your user. Typically either their email or database ID.
898
+ * @param properties - Optional dictionary with key:value pairs to set the person properties
899
+ * @param options - Optional capture options
900
+ */
901
+ identify(distinctId?: string, properties?: TxlemetryEventProperties, options?: TxlemetryCaptureOptions): void;
902
+ /**
903
+ * Capture a caught exception manually
904
+ *
905
+ * {@label Error tracking}
906
+ *
907
+ * @public
908
+ *
909
+ * @example
910
+ * ```js
911
+ * // Capture a caught exception
912
+ * try {
913
+ * // something that might throw
914
+ * } catch (error) {
915
+ * txlemetry.captureException(error)
916
+ * }
917
+ * ```
918
+ *
919
+ * @example
920
+ * ```js
921
+ * // With additional properties
922
+ * txlemetry.captureException(error, {
923
+ * customProperty: 'value',
924
+ * anotherProperty: ['I', 'can be a list'],
925
+ * ...
926
+ * })
927
+ * ```
928
+ *
929
+ * @param {Error} error The error to capture
930
+ * @param {Object} [additionalProperties] Any additional properties to add to the error event
931
+ * @returns {void}
932
+ */
933
+ captureException(error: Error | unknown, additionalProperties?: TxlemetryEventProperties, hint?: CoreErrorTracking.EventHint): void;
934
+ /**
935
+ * Records a breadcrumb-style exception step. Steps accumulate in a rolling, byte-bounded buffer
936
+ * and are attached to every captured `$exception` as `$exception_steps`, giving the error tracking
937
+ * UI a timeline of recent activity before each error.
938
+ *
939
+ * The `$timestamp` is captured at call time. The reserved keys `$message` and `$timestamp` are
940
+ * stripped from `properties` — the SDK sets the canonical values. This method never throws.
941
+ *
942
+ * @example
943
+ * ```js
944
+ * txlemetry.addExceptionStep('User tapped Checkout', { screen: 'cart' })
945
+ * ```
946
+ *
947
+ * @param {string} message A non-empty description of the step
948
+ * @param {Object} [properties] Optional additional context to attach to the step
949
+ * @returns {void}
950
+ */
951
+ addExceptionStep(message: string, properties?: Properties): void;
952
+ protected createErrorPropertiesBuilder(): CoreErrorTracking.ErrorPropertiesBuilder;
953
+ initReactNativeNavigation(options: TxlemetryAutocaptureOptions): boolean;
954
+ /**
955
+ * Creates a person profile for the current user, if they don't already have one.
956
+ *
957
+ * This is useful when using `personProfiles: 'identified_only'` mode and you want to
958
+ * explicitly create a profile for an anonymous user before they identify.
959
+ *
960
+ * If `personProfiles` is 'identified_only' and no profile exists, this will create one.
961
+ * If `personProfiles` is 'never', this will log an error and do nothing.
962
+ * If `personProfiles` is 'always' or a profile already exists, this is a no-op.
963
+ *
964
+ * {@label Identification}
965
+ *
966
+ * @example
967
+ * ```js
968
+ * // Create a person profile for an anonymous user
969
+ * txlemetry.createPersonProfile()
970
+ * ```
971
+ *
972
+ * @public
973
+ */
974
+ createPersonProfile(): void;
975
+ /**
976
+ * Sets properties on the person profile associated with the current `distinct_id`.
977
+ * Learn more about [identifying users](https://txlemetry.com/docs/product-analytics/identify)
978
+ *
979
+ * {@label Identification}
980
+ *
981
+ * @remarks
982
+ * Updates user properties that are stored with the person profile in Txlemetry.
983
+ * If `personProfiles` is set to `identified_only` and no profile exists, this will create one.
984
+ *
985
+ * @example
986
+ * ```js
987
+ * // set user properties
988
+ * txlemetry.setPersonProperties({
989
+ * email: 'user@example.com',
990
+ * plan: 'premium'
991
+ * })
992
+ * ```
993
+ *
994
+ * @example
995
+ * ```js
996
+ * // set properties with $set_once
997
+ * txlemetry.setPersonProperties(
998
+ * { name: 'Max Hedgehog' }, // $set properties
999
+ * { initial_url: '/blog' } // $set_once properties
1000
+ * )
1001
+ * ```
1002
+ *
1003
+ * @example
1004
+ * ```js
1005
+ * // set properties without reloading feature flags
1006
+ * txlemetry.setPersonProperties({ plan: 'premium' }, undefined, false)
1007
+ * ```
1008
+ *
1009
+ * @public
1010
+ *
1011
+ * @param userPropertiesToSet - Optional: An object of properties to store about the user.
1012
+ * These properties will overwrite any existing values for the same keys.
1013
+ * @param userPropertiesToSetOnce - Optional: An object of properties to store about the user.
1014
+ * If a property is previously set, this does not override that value.
1015
+ * @param reloadFeatureFlags - Whether to reload feature flags after setting the properties. Defaults to true.
1016
+ */
1017
+ setPersonProperties(userPropertiesToSet?: {
1018
+ [key: string]: JsonType;
1019
+ }, userPropertiesToSetOnce?: {
1020
+ [key: string]: JsonType;
1021
+ }, reloadFeatureFlags?: boolean): void;
1022
+ /**
1023
+ * Removes properties from the person profile associated with the current `distinct_id`.
1024
+ * Learn more about [identifying users](https://txlemetry.com/docs/product-analytics/identify)
1025
+ *
1026
+ * {@label Identification}
1027
+ *
1028
+ * @public
1029
+ *
1030
+ * @param propertyNames - The name (or names) of the person properties to remove.
1031
+ * @param reloadFeatureFlags - Whether to reload feature flags after removing the properties. Defaults to true.
1032
+ */
1033
+ unsetPersonProperties(propertyNames: string | string[], reloadFeatureFlags?: boolean): void;
1034
+ getSurveys(): Promise<SurveyResponse['surveys']>;
1035
+ /**
1036
+ * Returns a promise that resolves when surveys are ready to be loaded.
1037
+ * If surveys are already loaded and ready to go, returns a resolved promise instead.
1038
+ * @internal
1039
+ */
1040
+ _onSurveysReady(): Promise<void>;
1041
+ private _surveysReadyResolve;
1042
+ /**
1043
+ * Helper function to cache surveys to storage with consistent logging
1044
+ */
1045
+ private _cacheSurveys;
1046
+ /**
1047
+ * Internal method to notify that surveys are ready
1048
+ */
1049
+ private _notifySurveysReady;
1050
+ /**
1051
+ * Handle surveys from remote config response
1052
+ */
1053
+ private _handleSurveysFromRemoteConfig;
1054
+ private _isAutocaptureNativeErrors;
1055
+ private _isNativePluginInitialized;
1056
+ /**
1057
+ * Initializes the native session replay SDK if not already initialized.
1058
+ * This is called automatically by startSessionReplay() or lazily by startSessionRecording().
1059
+ *
1060
+ * @returns true if the native SDK is ready (initialized or already was), false otherwise
1061
+ */
1062
+ private initializeSessionReplayNative;
1063
+ private initializeNativePlugin;
1064
+ private startSessionReplay;
1065
+ /**
1066
+ * Decides whether session replay should be recording (replay enabled AND the linked
1067
+ * flag, if any, on for the current user) and arms or pauses the native recorder to match.
1068
+ *
1069
+ * Runs at startup and on every feature flags load/reload (identify(), reset(),
1070
+ * reloadFeatureFlags()), so recording starts, resumes, or pauses on identity changes
1071
+ * without an app restart. `_sessionReplayRecordingActive` dedups repeated answers, and
1072
+ * the init guards prevent double-starts. When replay is off, the native plugin is still
1073
+ * initialized for native error tracking (both share one native instance).
1074
+ *
1075
+ * Pausing requires a real "flag off": core keeps the previous flag values across
1076
+ * quota-limited/failed reloads, so a transient error never pauses a recording. Right
1077
+ * after reset() the flags are genuinely unknown and pausing is the intended outcome.
1078
+ *
1079
+ * Evaluations are serialized so concurrent flags reloads run one at a time.
1080
+ */
1081
+ private _evaluateAndStartSessionReplay;
1082
+ private _evaluateAndStartSessionReplayInternal;
1083
+ /**
1084
+ * Capture chokepoint for session-replay event triggers. Every captured event (capture, $screen,
1085
+ * autocapture, lifecycle) passes through here. Chains to super first so `before_send` still runs;
1086
+ * when a surviving event's name matches an armed trigger and the session hasn't activated yet, it
1087
+ * activates replay for the session and kicks a re-evaluation that starts native recording. The
1088
+ * trigger check never drops an event or throws into the capture path.
1089
+ */
1090
+ protected processBeforeEnqueue(message: TxlemetryEventProperties): TxlemetryEventProperties | null;
1091
+ private _maybeActivateEventTrigger;
1092
+ private _parseEventTriggers;
1093
+ private _isEventTriggerActivatedForSession;
1094
+ private captureAppLifecycleEvents;
1095
+ private persistAppVersion;
1096
+ }