swetrix 3.7.2 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,6 +14,11 @@ export interface LibOptions {
14
14
  respectDNT?: boolean;
15
15
  /** Set a custom URL of the API server (for selfhosted variants of Swetrix). */
16
16
  apiURL?: string;
17
+ /**
18
+ * Optional profile ID for long-term user tracking.
19
+ * If set, it will be used for all pageviews and events unless overridden per-call.
20
+ */
21
+ profileId?: string;
17
22
  }
18
23
  export interface TrackEventOptions {
19
24
  /** The custom event name. */
@@ -24,6 +29,8 @@ export interface TrackEventOptions {
24
29
  meta?: {
25
30
  [key: string]: string | number | boolean | null | undefined;
26
31
  };
32
+ /** Optional profile ID for long-term user tracking. Overrides the global profileId if set. */
33
+ profileId?: string;
27
34
  }
28
35
  export interface IPageViewPayload {
29
36
  lc?: string;
@@ -39,6 +46,8 @@ export interface IPageViewPayload {
39
46
  meta?: {
40
47
  [key: string]: string | number | boolean | null | undefined;
41
48
  };
49
+ /** Optional profile ID for long-term user tracking. Overrides the global profileId if set. */
50
+ profileId?: string;
42
51
  }
43
52
  export interface IErrorEventPayload {
44
53
  name: string;
@@ -66,6 +75,28 @@ interface IPerfPayload {
66
75
  page_load: number;
67
76
  ttfb: number;
68
77
  }
78
+ /**
79
+ * Options for evaluating feature flags.
80
+ */
81
+ export interface FeatureFlagsOptions {
82
+ /**
83
+ * Optional profile ID for long-term user tracking.
84
+ * If not provided, an anonymous profile ID will be generated server-side based on IP and user agent.
85
+ * Overrides the global profileId if set.
86
+ */
87
+ profileId?: string;
88
+ }
89
+ /**
90
+ * Options for evaluating experiments.
91
+ */
92
+ export interface ExperimentOptions {
93
+ /**
94
+ * Optional profile ID for long-term user tracking.
95
+ * If not provided, an anonymous profile ID will be generated server-side based on IP and user agent.
96
+ * Overrides the global profileId if set.
97
+ */
98
+ profileId?: string;
99
+ }
69
100
  /**
70
101
  * The object returned by `trackPageViews()`, used to stop tracking pages.
71
102
  */
@@ -141,6 +172,7 @@ export declare class Lib {
141
172
  private perfStatsCollected;
142
173
  private activePage;
143
174
  private errorListenerExists;
175
+ private cachedData;
144
176
  constructor(projectID: string, options?: LibOptions | undefined);
145
177
  captureError(event: ErrorEvent): void;
146
178
  trackErrors(options?: ErrorOptions): ErrorActions;
@@ -148,6 +180,122 @@ export declare class Lib {
148
180
  track(event: TrackEventOptions): Promise<void>;
149
181
  trackPageViews(options?: PageViewsOptions): PageActions;
150
182
  getPerformanceStats(): IPerfPayload | {};
183
+ /**
184
+ * Fetches all feature flags and experiments for the project.
185
+ * Results are cached for 5 minutes by default.
186
+ *
187
+ * @param options - Options for evaluating feature flags.
188
+ * @param forceRefresh - If true, bypasses the cache and fetches fresh data.
189
+ * @returns A promise that resolves to a record of flag keys to boolean values.
190
+ */
191
+ getFeatureFlags(options?: FeatureFlagsOptions, forceRefresh?: boolean): Promise<Record<string, boolean>>;
192
+ /**
193
+ * Internal method to fetch both feature flags and experiments from the API.
194
+ */
195
+ private fetchFlagsAndExperiments;
196
+ /**
197
+ * Gets the value of a single feature flag.
198
+ *
199
+ * @param key - The feature flag key.
200
+ * @param options - Options for evaluating the feature flag.
201
+ * @param defaultValue - Default value to return if the flag is not found. Defaults to false.
202
+ * @returns A promise that resolves to the boolean value of the flag.
203
+ */
204
+ getFeatureFlag(key: string, options?: FeatureFlagsOptions, defaultValue?: boolean): Promise<boolean>;
205
+ /**
206
+ * Clears the cached feature flags and experiments, forcing a fresh fetch on the next call.
207
+ */
208
+ clearFeatureFlagsCache(): void;
209
+ /**
210
+ * Fetches all A/B test experiments for the project.
211
+ * Results are cached for 5 minutes by default (shared cache with feature flags).
212
+ *
213
+ * @param options - Options for evaluating experiments.
214
+ * @param forceRefresh - If true, bypasses the cache and fetches fresh data.
215
+ * @returns A promise that resolves to a record of experiment IDs to variant keys.
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * const experiments = await getExperiments()
220
+ * // experiments = { 'exp-123': 'variant-a', 'exp-456': 'control' }
221
+ * ```
222
+ */
223
+ getExperiments(options?: ExperimentOptions, forceRefresh?: boolean): Promise<Record<string, string>>;
224
+ /**
225
+ * Gets the variant key for a specific A/B test experiment.
226
+ *
227
+ * @param experimentId - The experiment ID.
228
+ * @param options - Options for evaluating the experiment.
229
+ * @param defaultVariant - Default variant key to return if the experiment is not found. Defaults to null.
230
+ * @returns A promise that resolves to the variant key assigned to this user, or defaultVariant if not found.
231
+ *
232
+ * @example
233
+ * ```typescript
234
+ * const variant = await getExperiment('checkout-redesign')
235
+ *
236
+ * if (variant === 'new-checkout') {
237
+ * // Show new checkout flow
238
+ * } else {
239
+ * // Show control (original) checkout
240
+ * }
241
+ * ```
242
+ */
243
+ getExperiment(experimentId: string, options?: ExperimentOptions, defaultVariant?: string | null): Promise<string | null>;
244
+ /**
245
+ * Clears the cached experiments (alias for clearFeatureFlagsCache since they share the same cache).
246
+ */
247
+ clearExperimentsCache(): void;
248
+ /**
249
+ * Gets the anonymous profile ID for the current visitor.
250
+ * If profileId was set via init options, returns that.
251
+ * Otherwise, requests server to generate one from IP/UA hash.
252
+ *
253
+ * This ID can be used for revenue attribution with payment providers.
254
+ *
255
+ * @returns A promise that resolves to the profile ID string, or null on error.
256
+ *
257
+ * @example
258
+ * ```typescript
259
+ * const profileId = await swetrix.getProfileId()
260
+ *
261
+ * // Pass to Paddle Checkout for revenue attribution
262
+ * Paddle.Checkout.open({
263
+ * items: [{ priceId: 'pri_01234567890', quantity: 1 }],
264
+ * customData: {
265
+ * swetrix_profile_id: profileId,
266
+ * swetrix_session_id: await swetrix.getSessionId()
267
+ * }
268
+ * })
269
+ * ```
270
+ */
271
+ getProfileId(): Promise<string | null>;
272
+ /**
273
+ * Gets the current session ID for the visitor.
274
+ * Session IDs are generated server-side based on IP and user agent.
275
+ *
276
+ * This ID can be used for revenue attribution with payment providers.
277
+ *
278
+ * @returns A promise that resolves to the session ID string, or null on error.
279
+ *
280
+ * @example
281
+ * ```typescript
282
+ * const sessionId = await swetrix.getSessionId()
283
+ *
284
+ * // Pass to Paddle Checkout for revenue attribution
285
+ * Paddle.Checkout.open({
286
+ * items: [{ priceId: 'pri_01234567890', quantity: 1 }],
287
+ * customData: {
288
+ * swetrix_profile_id: await swetrix.getProfileId(),
289
+ * swetrix_session_id: sessionId
290
+ * }
291
+ * })
292
+ * ```
293
+ */
294
+ getSessionId(): Promise<string | null>;
295
+ /**
296
+ * Gets the API base URL (without /log suffix).
297
+ */
298
+ private getApiBase;
151
299
  private heartbeat;
152
300
  private trackPathChange;
153
301
  private trackPage;
@@ -3,6 +3,9 @@ export const defaultActions = {
3
3
  stop() { },
4
4
  };
5
5
  const DEFAULT_API_HOST = 'https://api.swetrix.com/log';
6
+ const DEFAULT_API_BASE = 'https://api.swetrix.com';
7
+ // Default cache duration: 5 minutes
8
+ const DEFAULT_CACHE_DURATION = 5 * 60 * 1000;
6
9
  export class Lib {
7
10
  constructor(projectID, options) {
8
11
  this.projectID = projectID;
@@ -13,6 +16,7 @@ export class Lib {
13
16
  this.perfStatsCollected = false;
14
17
  this.activePage = null;
15
18
  this.errorListenerExists = false;
19
+ this.cachedData = null;
16
20
  this.trackPathChange = this.trackPathChange.bind(this);
17
21
  this.heartbeat = this.heartbeat.bind(this);
18
22
  this.captureError = this.captureError.bind(this);
@@ -98,6 +102,7 @@ export class Lib {
98
102
  ca: getUTMCampaign(),
99
103
  te: getUTMTerm(),
100
104
  co: getUTMContent(),
105
+ profileId: event.profileId ?? this.options?.profileId,
101
106
  };
102
107
  await this.sendRequest('custom', data);
103
108
  }
@@ -156,6 +161,259 @@ export class Lib {
156
161
  ttfb: perf.responseStart - perf.requestStart,
157
162
  };
158
163
  }
164
+ /**
165
+ * Fetches all feature flags and experiments for the project.
166
+ * Results are cached for 5 minutes by default.
167
+ *
168
+ * @param options - Options for evaluating feature flags.
169
+ * @param forceRefresh - If true, bypasses the cache and fetches fresh data.
170
+ * @returns A promise that resolves to a record of flag keys to boolean values.
171
+ */
172
+ async getFeatureFlags(options, forceRefresh) {
173
+ if (!isInBrowser()) {
174
+ return {};
175
+ }
176
+ const requestedProfileId = options?.profileId ?? this.options?.profileId;
177
+ // Check cache first - must match profileId and not be expired
178
+ if (!forceRefresh && this.cachedData) {
179
+ const now = Date.now();
180
+ const isSameProfile = this.cachedData.profileId === requestedProfileId;
181
+ if (isSameProfile && now - this.cachedData.timestamp < DEFAULT_CACHE_DURATION) {
182
+ return this.cachedData.flags;
183
+ }
184
+ }
185
+ try {
186
+ await this.fetchFlagsAndExperiments(options);
187
+ return this.cachedData?.flags || {};
188
+ }
189
+ catch (error) {
190
+ console.warn('[Swetrix] Error fetching feature flags:', error);
191
+ return this.cachedData?.flags || {};
192
+ }
193
+ }
194
+ /**
195
+ * Internal method to fetch both feature flags and experiments from the API.
196
+ */
197
+ async fetchFlagsAndExperiments(options) {
198
+ const apiBase = this.getApiBase();
199
+ const body = {
200
+ pid: this.projectID,
201
+ };
202
+ // Use profileId from options, or fall back to global profileId
203
+ const profileId = options?.profileId ?? this.options?.profileId;
204
+ if (profileId) {
205
+ body.profileId = profileId;
206
+ }
207
+ const response = await fetch(`${apiBase}/feature-flag/evaluate`, {
208
+ method: 'POST',
209
+ headers: {
210
+ 'Content-Type': 'application/json',
211
+ },
212
+ body: JSON.stringify(body),
213
+ });
214
+ if (!response.ok) {
215
+ console.warn('[Swetrix] Failed to fetch feature flags and experiments:', response.status);
216
+ return;
217
+ }
218
+ const data = (await response.json());
219
+ // Use profileId from options, or fall back to global profileId
220
+ const cachedProfileId = options?.profileId ?? this.options?.profileId;
221
+ // Update cache with both flags and experiments
222
+ this.cachedData = {
223
+ flags: data.flags || {},
224
+ experiments: data.experiments || {},
225
+ timestamp: Date.now(),
226
+ profileId: cachedProfileId,
227
+ };
228
+ }
229
+ /**
230
+ * Gets the value of a single feature flag.
231
+ *
232
+ * @param key - The feature flag key.
233
+ * @param options - Options for evaluating the feature flag.
234
+ * @param defaultValue - Default value to return if the flag is not found. Defaults to false.
235
+ * @returns A promise that resolves to the boolean value of the flag.
236
+ */
237
+ async getFeatureFlag(key, options, defaultValue = false) {
238
+ const flags = await this.getFeatureFlags(options);
239
+ return flags[key] ?? defaultValue;
240
+ }
241
+ /**
242
+ * Clears the cached feature flags and experiments, forcing a fresh fetch on the next call.
243
+ */
244
+ clearFeatureFlagsCache() {
245
+ this.cachedData = null;
246
+ }
247
+ /**
248
+ * Fetches all A/B test experiments for the project.
249
+ * Results are cached for 5 minutes by default (shared cache with feature flags).
250
+ *
251
+ * @param options - Options for evaluating experiments.
252
+ * @param forceRefresh - If true, bypasses the cache and fetches fresh data.
253
+ * @returns A promise that resolves to a record of experiment IDs to variant keys.
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * const experiments = await getExperiments()
258
+ * // experiments = { 'exp-123': 'variant-a', 'exp-456': 'control' }
259
+ * ```
260
+ */
261
+ async getExperiments(options, forceRefresh) {
262
+ if (!isInBrowser()) {
263
+ return {};
264
+ }
265
+ const requestedProfileId = options?.profileId ?? this.options?.profileId;
266
+ // Check cache first - must match profileId and not be expired
267
+ if (!forceRefresh && this.cachedData) {
268
+ const now = Date.now();
269
+ const isSameProfile = this.cachedData.profileId === requestedProfileId;
270
+ if (isSameProfile && now - this.cachedData.timestamp < DEFAULT_CACHE_DURATION) {
271
+ return this.cachedData.experiments;
272
+ }
273
+ }
274
+ try {
275
+ await this.fetchFlagsAndExperiments(options);
276
+ return this.cachedData?.experiments || {};
277
+ }
278
+ catch (error) {
279
+ console.warn('[Swetrix] Error fetching experiments:', error);
280
+ return this.cachedData?.experiments || {};
281
+ }
282
+ }
283
+ /**
284
+ * Gets the variant key for a specific A/B test experiment.
285
+ *
286
+ * @param experimentId - The experiment ID.
287
+ * @param options - Options for evaluating the experiment.
288
+ * @param defaultVariant - Default variant key to return if the experiment is not found. Defaults to null.
289
+ * @returns A promise that resolves to the variant key assigned to this user, or defaultVariant if not found.
290
+ *
291
+ * @example
292
+ * ```typescript
293
+ * const variant = await getExperiment('checkout-redesign')
294
+ *
295
+ * if (variant === 'new-checkout') {
296
+ * // Show new checkout flow
297
+ * } else {
298
+ * // Show control (original) checkout
299
+ * }
300
+ * ```
301
+ */
302
+ async getExperiment(experimentId, options, defaultVariant = null) {
303
+ const experiments = await this.getExperiments(options);
304
+ return experiments[experimentId] ?? defaultVariant;
305
+ }
306
+ /**
307
+ * Clears the cached experiments (alias for clearFeatureFlagsCache since they share the same cache).
308
+ */
309
+ clearExperimentsCache() {
310
+ this.cachedData = null;
311
+ }
312
+ /**
313
+ * Gets the anonymous profile ID for the current visitor.
314
+ * If profileId was set via init options, returns that.
315
+ * Otherwise, requests server to generate one from IP/UA hash.
316
+ *
317
+ * This ID can be used for revenue attribution with payment providers.
318
+ *
319
+ * @returns A promise that resolves to the profile ID string, or null on error.
320
+ *
321
+ * @example
322
+ * ```typescript
323
+ * const profileId = await swetrix.getProfileId()
324
+ *
325
+ * // Pass to Paddle Checkout for revenue attribution
326
+ * Paddle.Checkout.open({
327
+ * items: [{ priceId: 'pri_01234567890', quantity: 1 }],
328
+ * customData: {
329
+ * swetrix_profile_id: profileId,
330
+ * swetrix_session_id: await swetrix.getSessionId()
331
+ * }
332
+ * })
333
+ * ```
334
+ */
335
+ async getProfileId() {
336
+ // If profileId is already set in options, return it
337
+ if (this.options?.profileId) {
338
+ return this.options.profileId;
339
+ }
340
+ if (!isInBrowser()) {
341
+ return null;
342
+ }
343
+ try {
344
+ const apiBase = this.getApiBase();
345
+ const response = await fetch(`${apiBase}/log/profile-id`, {
346
+ method: 'POST',
347
+ headers: {
348
+ 'Content-Type': 'application/json',
349
+ },
350
+ body: JSON.stringify({ pid: this.projectID }),
351
+ });
352
+ if (!response.ok) {
353
+ return null;
354
+ }
355
+ const data = (await response.json());
356
+ return data.profileId;
357
+ }
358
+ catch {
359
+ return null;
360
+ }
361
+ }
362
+ /**
363
+ * Gets the current session ID for the visitor.
364
+ * Session IDs are generated server-side based on IP and user agent.
365
+ *
366
+ * This ID can be used for revenue attribution with payment providers.
367
+ *
368
+ * @returns A promise that resolves to the session ID string, or null on error.
369
+ *
370
+ * @example
371
+ * ```typescript
372
+ * const sessionId = await swetrix.getSessionId()
373
+ *
374
+ * // Pass to Paddle Checkout for revenue attribution
375
+ * Paddle.Checkout.open({
376
+ * items: [{ priceId: 'pri_01234567890', quantity: 1 }],
377
+ * customData: {
378
+ * swetrix_profile_id: await swetrix.getProfileId(),
379
+ * swetrix_session_id: sessionId
380
+ * }
381
+ * })
382
+ * ```
383
+ */
384
+ async getSessionId() {
385
+ if (!isInBrowser()) {
386
+ return null;
387
+ }
388
+ try {
389
+ const apiBase = this.getApiBase();
390
+ const response = await fetch(`${apiBase}/log/session-id`, {
391
+ method: 'POST',
392
+ headers: {
393
+ 'Content-Type': 'application/json',
394
+ },
395
+ body: JSON.stringify({ pid: this.projectID }),
396
+ });
397
+ if (!response.ok) {
398
+ return null;
399
+ }
400
+ const data = (await response.json());
401
+ return data.sessionId;
402
+ }
403
+ catch {
404
+ return null;
405
+ }
406
+ }
407
+ /**
408
+ * Gets the API base URL (without /log suffix).
409
+ */
410
+ getApiBase() {
411
+ if (this.options?.apiURL) {
412
+ // Remove trailing /log if present
413
+ return this.options.apiURL.replace(/\/log\/?$/, '');
414
+ }
415
+ return DEFAULT_API_BASE;
416
+ }
159
417
  heartbeat() {
160
418
  if (!this.pageViewsOptions?.heartbeatOnBackground && document.visibilityState === 'hidden') {
161
419
  return;
@@ -163,6 +421,9 @@ export class Lib {
163
421
  const data = {
164
422
  pid: this.projectID,
165
423
  };
424
+ if (this.options?.profileId) {
425
+ data.profileId = this.options.profileId;
426
+ }
166
427
  this.sendRequest('hb', data);
167
428
  }
168
429
  // Tracking path changes. If path changes -> calling this.trackPage method
@@ -201,6 +462,7 @@ export class Lib {
201
462
  ca: getUTMCampaign(),
202
463
  te: getUTMTerm(),
203
464
  co: getUTMContent(),
465
+ profileId: this.options?.profileId,
204
466
  ...payload,
205
467
  };
206
468
  if (evokeCallback && this.pageViewsOptions?.callback)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;QACH,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;QAErC,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,SAAS,CAAC,CAAA;IACjC,CAAC;IAEO,QAAQ;QACd,IACE,IAAI,CAAC,OAAO,EAAE,QAAQ;YACtB,CAAC,WAAW,EAAE;YACd,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,IAAI,MAAM,CAAC,SAAS,EAAE,UAAU,KAAK,GAAG,CAAC;YAClE,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,CAAC;YACzC,WAAW,EAAE,EACb,CAAC;YACD,OAAO,KAAK,CAAA;QACd,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,IAAY,EAAE,IAAY;QAClD,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,IAAI,gBAAgB,CAAA;QACrD,MAAM,KAAK,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,EAAE;YAC7B,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -1,4 +1,4 @@
1
- import { Lib, LibOptions, TrackEventOptions, PageViewsOptions, ErrorOptions, PageActions, ErrorActions, IErrorEventPayload, IPageViewPayload } from './Lib.js';
1
+ import { Lib, LibOptions, TrackEventOptions, PageViewsOptions, ErrorOptions, PageActions, ErrorActions, IErrorEventPayload, IPageViewPayload, FeatureFlagsOptions, ExperimentOptions } from './Lib.js';
2
2
  export declare let LIB_INSTANCE: Lib | null;
3
3
  /**
4
4
  * Initialise the tracking library instance (other methods won't work if the library is not initialised).
@@ -54,4 +54,148 @@ export interface IPageviewOptions {
54
54
  unique?: boolean;
55
55
  }
56
56
  export declare function pageview(options: IPageviewOptions): void;
57
- export { LibOptions, TrackEventOptions, PageViewsOptions, ErrorOptions, PageActions, ErrorActions, IErrorEventPayload, IPageViewPayload, };
57
+ /**
58
+ * Fetches all feature flags for the project.
59
+ * Results are cached for 5 minutes by default.
60
+ *
61
+ * @param options - Options for evaluating feature flags (visitorId, attributes).
62
+ * @param forceRefresh - If true, bypasses the cache and fetches fresh flags.
63
+ * @returns A promise that resolves to a record of flag keys to boolean values.
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const flags = await getFeatureFlags({
68
+ * visitorId: 'user-123',
69
+ * attributes: { cc: 'US', dv: 'desktop' }
70
+ * })
71
+ *
72
+ * if (flags['new-checkout']) {
73
+ * // Show new checkout flow
74
+ * }
75
+ * ```
76
+ */
77
+ export declare function getFeatureFlags(options?: FeatureFlagsOptions, forceRefresh?: boolean): Promise<Record<string, boolean>>;
78
+ /**
79
+ * Gets the value of a single feature flag.
80
+ *
81
+ * @param key - The feature flag key.
82
+ * @param options - Options for evaluating the feature flag (visitorId, attributes).
83
+ * @param defaultValue - Default value to return if the flag is not found. Defaults to false.
84
+ * @returns A promise that resolves to the boolean value of the flag.
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const isEnabled = await getFeatureFlag('dark-mode', { visitorId: 'user-123' })
89
+ *
90
+ * if (isEnabled) {
91
+ * // Enable dark mode
92
+ * }
93
+ * ```
94
+ */
95
+ export declare function getFeatureFlag(key: string, options?: FeatureFlagsOptions, defaultValue?: boolean): Promise<boolean>;
96
+ /**
97
+ * Clears the cached feature flags, forcing a fresh fetch on the next call.
98
+ * Useful when you know the user's context has changed significantly.
99
+ */
100
+ export declare function clearFeatureFlagsCache(): void;
101
+ /**
102
+ * Fetches all A/B test experiments for the project.
103
+ * Results are cached for 5 minutes by default (shared cache with feature flags).
104
+ *
105
+ * @param options - Options for evaluating experiments.
106
+ * @param forceRefresh - If true, bypasses the cache and fetches fresh data.
107
+ * @returns A promise that resolves to a record of experiment IDs to variant keys.
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * const experiments = await getExperiments()
112
+ * // experiments = { 'exp-123': 'variant-a', 'exp-456': 'control' }
113
+ *
114
+ * // Use the assigned variant
115
+ * const checkoutVariant = experiments['checkout-experiment-id']
116
+ * if (checkoutVariant === 'new-checkout') {
117
+ * showNewCheckout()
118
+ * } else {
119
+ * showOriginalCheckout()
120
+ * }
121
+ * ```
122
+ */
123
+ export declare function getExperiments(options?: ExperimentOptions, forceRefresh?: boolean): Promise<Record<string, string>>;
124
+ /**
125
+ * Gets the variant key for a specific A/B test experiment.
126
+ *
127
+ * @param experimentId - The experiment ID.
128
+ * @param options - Options for evaluating the experiment.
129
+ * @param defaultVariant - Default variant key to return if the experiment is not found. Defaults to null.
130
+ * @returns A promise that resolves to the variant key assigned to this user, or defaultVariant if not found.
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * const variant = await getExperiment('checkout-redesign-experiment-id')
135
+ *
136
+ * if (variant === 'new-checkout') {
137
+ * // Show new checkout flow
138
+ * showNewCheckout()
139
+ * } else if (variant === 'control') {
140
+ * // Show original checkout (control group)
141
+ * showOriginalCheckout()
142
+ * } else {
143
+ * // Experiment not running or user not included
144
+ * showOriginalCheckout()
145
+ * }
146
+ * ```
147
+ */
148
+ export declare function getExperiment(experimentId: string, options?: ExperimentOptions, defaultVariant?: string | null): Promise<string | null>;
149
+ /**
150
+ * Clears the cached experiments, forcing a fresh fetch on the next call.
151
+ * This is an alias for clearFeatureFlagsCache since experiments and flags share the same cache.
152
+ */
153
+ export declare function clearExperimentsCache(): void;
154
+ /**
155
+ * Gets the anonymous profile ID for the current visitor.
156
+ * If profileId was set via init options, returns that.
157
+ * Otherwise, requests server to generate one from IP/UA hash.
158
+ *
159
+ * This ID can be used for revenue attribution with payment providers like Paddle.
160
+ *
161
+ * @returns A promise that resolves to the profile ID string, or null on error.
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * const profileId = await getProfileId()
166
+ *
167
+ * // Pass to Paddle Checkout for revenue attribution
168
+ * Paddle.Checkout.open({
169
+ * items: [{ priceId: 'pri_01234567890', quantity: 1 }],
170
+ * customData: {
171
+ * swetrix_profile_id: profileId,
172
+ * swetrix_session_id: await getSessionId()
173
+ * }
174
+ * })
175
+ * ```
176
+ */
177
+ export declare function getProfileId(): Promise<string | null>;
178
+ /**
179
+ * Gets the current session ID for the visitor.
180
+ * Session IDs are generated server-side based on IP and user agent.
181
+ *
182
+ * This ID can be used for revenue attribution with payment providers like Paddle.
183
+ *
184
+ * @returns A promise that resolves to the session ID string, or null on error.
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * const sessionId = await getSessionId()
189
+ *
190
+ * // Pass to Paddle Checkout for revenue attribution
191
+ * Paddle.Checkout.open({
192
+ * items: [{ priceId: 'pri_01234567890', quantity: 1 }],
193
+ * customData: {
194
+ * swetrix_profile_id: await getProfileId(),
195
+ * swetrix_session_id: sessionId
196
+ * }
197
+ * })
198
+ * ```
199
+ */
200
+ export declare function getSessionId(): Promise<string | null>;
201
+ export { LibOptions, TrackEventOptions, PageViewsOptions, ErrorOptions, PageActions, ErrorActions, IErrorEventPayload, IPageViewPayload, FeatureFlagsOptions, ExperimentOptions, };