@rudderstack/analytics-js 3.6.0 → 3.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1024 @@
1
+ type LoggerProvider$1 = Record<Exclude<Lowercase<LogLevel>, Lowercase<'NONE'>>, (...data: any[]) => void>;
2
+ interface ILogger {
3
+ minLogLevel: number;
4
+ scope?: string;
5
+ logProvider: LoggerProvider$1;
6
+ log(...data: any[]): void;
7
+ info(...data: any[]): void;
8
+ debug(...data: any[]): void;
9
+ warn(...data: any[]): void;
10
+ error(...data: any[]): void;
11
+ setScope(scopeVal: string): void;
12
+ setMinLogLevel(logLevel: LogLevel): void;
13
+ }
14
+ type LogLevel = 'LOG' | 'INFO' | 'DEBUG' | 'WARN' | 'ERROR' | 'NONE';
15
+
16
+ type LoggerProvider = Record<Exclude<Lowercase<LogLevel>, Lowercase<'NONE'>>, (...data: any[]) => void>;
17
+
18
+ /**
19
+ * Service to log messages/data to output provider, default is console
20
+ */
21
+ declare class Logger implements ILogger {
22
+ minLogLevel: number;
23
+ scope?: string;
24
+ logProvider: LoggerProvider;
25
+ constructor(minLogLevel?: LogLevel, scope?: string, logProvider?: Console);
26
+ log(...data: any[]): void;
27
+ info(...data: any[]): void;
28
+ debug(...data: any[]): void;
29
+ warn(...data: any[]): void;
30
+ error(...data: any[]): void;
31
+ outputLog(logMethod: LogLevel, data: any[]): void;
32
+ setScope(scopeVal: string): void;
33
+ setMinLogLevel(logLevel: LogLevel): void;
34
+ /**
35
+ * Formats the console message using `scope` and styles
36
+ */
37
+ formatLogData(data: any[]): any[];
38
+ }//# sourceMappingURL=Logger.d.ts.map
39
+
40
+ type Nullable<T> = T | null;
41
+
42
+ /**
43
+ * Represents a generic object in the APIs
44
+ * Use for parameters like properties, traits etc.
45
+ */
46
+ type ApiObject = {
47
+ [index: string]: string | number | boolean | ApiObject | null | Date | (string | number | boolean | null | ApiObject)[] | undefined;
48
+ };
49
+
50
+ type DestinationIntgConfig = boolean | undefined | ApiObject;
51
+ /**
52
+ * Represents the integration options object
53
+ * Example usages:
54
+ * integrationOptions { All: false, "Google Analytics": true, "Braze": true}
55
+ * integrationOptions { All: true, "Chartbeat": false, "Customer.io": false}
56
+ * integrationOptions { All: true, "GA4": { "clientId": "1234" }, "Google Analytics": false }
57
+ */
58
+ type IntegrationOpts = {
59
+ All?: boolean;
60
+ [index: string]: DestinationIntgConfig;
61
+ };
62
+
63
+ type ApiCallback = (data?: any) => void;
64
+ /**
65
+ * Represents the options parameter in the APIs
66
+ */
67
+ type ApiOptions = {
68
+ integrations?: IntegrationOpts;
69
+ anonymousId?: string;
70
+ originalTimestamp?: string;
71
+ [index: string]: string | number | boolean | ApiObject | null | Date | (string | number | boolean | ApiObject)[] | undefined;
72
+ };
73
+ type APIEvent = {
74
+ type: RudderEventType;
75
+ category?: string;
76
+ name?: string;
77
+ properties?: Nullable<ApiObject>;
78
+ options?: Nullable<ApiOptions>;
79
+ callback?: () => void;
80
+ userId?: Nullable<string>;
81
+ traits?: Nullable<ApiObject>;
82
+ to?: Nullable<string>;
83
+ from?: string;
84
+ groupId?: Nullable<string>;
85
+ };
86
+ type RudderEventType = 'page' | 'track' | 'identify' | 'alias' | 'group';
87
+
88
+ interface ExtensionPoint {
89
+ [lifeCycleName: string]: (...args: any[]) => unknown;
90
+ }
91
+ /**
92
+ * ExtensionPoint can be nested, e.g. 'sdk.initialize.phase1'
93
+ * When index signature is provided, every key have to match the type, the types
94
+ * for 'name', 'deps', and 'initialize' is added as index signature.
95
+ */
96
+ interface ExtensionPlugin {
97
+ name: string;
98
+ initialize?: (state?: any) => void;
99
+ deps?: string[];
100
+ [key: string]: string | (() => void) | ExtensionPoint | ((...args: any[]) => unknown | void) | string[] | undefined;
101
+ }
102
+ type PluginEngineConfig = {
103
+ throws?: boolean | RegExp;
104
+ };
105
+ interface IPluginEngine {
106
+ plugins: ExtensionPlugin[];
107
+ byName: Record<string, ExtensionPlugin>;
108
+ cache: Record<string, ExtensionPlugin[]>;
109
+ config: PluginEngineConfig;
110
+ register: (plugin: ExtensionPlugin, state?: Record<string, any>) => void;
111
+ unregister: (name: string) => void;
112
+ getPlugin: (name: string) => ExtensionPlugin | undefined;
113
+ getPlugins: (extPoint?: string) => ExtensionPlugin[];
114
+ invoke: <T = any>(extPoint?: string, allowMultiple?: boolean, ...args: any[]) => Nullable<T>[];
115
+ invokeSingle: <T = any>(extPoint?: string, ...args: any[]) => Nullable<T>;
116
+ invokeMultiple: <T = any>(extPoint?: string, ...args: any[]) => Nullable<T>[];
117
+ }
118
+
119
+ interface IPluginsManager {
120
+ engine: IPluginEngine;
121
+ init(): void;
122
+ attachEffects(): void;
123
+ setActivePlugins(): void;
124
+ invokeMultiple<T = any>(extPoint?: string, ...args: any[]): Nullable<T>[];
125
+ invokeSingle<T = any>(extPoint?: string, ...args: any[]): Nullable<T>;
126
+ register(plugins: ExtensionPlugin[]): void;
127
+ }
128
+ type PluginName = 'BeaconQueue' | 'Bugsnag' | 'CustomConsentManager' | 'DeviceModeDestinations' | 'DeviceModeTransformation' | 'ErrorReporting' | 'ExternalAnonymousId' | 'GoogleLinker' | 'KetchConsentManager' | 'NativeDestinationQueue' | 'OneTrustConsentManager' | 'StorageEncryption' | 'StorageEncryptionLegacy' | 'StorageMigrator' | 'XhrQueue';
129
+
130
+ type ConsentManagementProvider = 'oneTrust' | 'ketch' | 'custom';
131
+ type Consents = string[];
132
+ type ConsentManagementOptions = {
133
+ enabled?: boolean;
134
+ provider?: ConsentManagementProvider;
135
+ allowedConsentIds?: Consents;
136
+ deniedConsentIds?: Consents;
137
+ };
138
+
139
+ type UserSessionKey = 'userId' | 'userTraits' | 'anonymousId' | 'groupId' | 'groupTraits' | 'initialReferrer' | 'initialReferringDomain' | 'sessionInfo' | 'authToken';
140
+
141
+ type StorageEncryptionVersion = 'legacy' | 'v3';
142
+ type StorageType = 'cookieStorage' | 'localStorage' | 'memoryStorage' | 'sessionStorage' | 'none';
143
+ type StorageEncryption = {
144
+ version: StorageEncryptionVersion;
145
+ };
146
+ type LoadOptionStorageEntry = {
147
+ type: StorageType;
148
+ };
149
+ type StorageOpts = {
150
+ encryption?: StorageEncryption;
151
+ migrate?: boolean;
152
+ type?: StorageType;
153
+ cookie?: CookieOptions;
154
+ entries?: {
155
+ [key in UserSessionKey]?: LoadOptionStorageEntry;
156
+ };
157
+ };
158
+ type CookieOptions = {
159
+ maxage?: number;
160
+ expires?: Date;
161
+ path?: string;
162
+ domain?: string;
163
+ samesite?: string;
164
+ secure?: boolean;
165
+ };
166
+ type CookieSameSite = 'Strict' | 'Lax' | 'None';
167
+
168
+ type UaChTrackLevel = 'none' | 'default' | 'full';
169
+ /**
170
+ * Represents the options parameter for anonymousId
171
+ */
172
+ type AnonymousIdOptions = {
173
+ autoCapture?: {
174
+ enabled?: boolean;
175
+ source?: string;
176
+ };
177
+ };
178
+ type SessionOpts = {
179
+ autoTrack?: boolean;
180
+ timeout?: number;
181
+ };
182
+ /**
183
+ * Represents the beacon queue options parameter in loadOptions type
184
+ */
185
+ type BeaconQueueOpts = {
186
+ maxItems?: number;
187
+ flushQueueInterval?: number;
188
+ };
189
+ type EventsTransportMode = 'xhr' | 'beacon';
190
+ type BatchOpts = {
191
+ enabled: boolean;
192
+ maxItems?: number;
193
+ maxSize?: number;
194
+ flushInterval?: number;
195
+ };
196
+ /**
197
+ * Represents the queue options parameter in loadOptions type
198
+ */
199
+ type QueueOpts = {
200
+ maxRetryDelay?: number;
201
+ minRetryDelay?: number;
202
+ backoffFactor?: number;
203
+ backoffJitter?: number;
204
+ maxAttempts?: number;
205
+ maxItems?: number;
206
+ batch?: BatchOpts;
207
+ timerScaleFactor?: number;
208
+ };
209
+ /**
210
+ * Represents the destinations queue options parameter in loadOptions type
211
+ */
212
+ type DestinationsQueueOpts = {
213
+ maxItems?: number;
214
+ };
215
+ type OnLoadedCallback = (analytics: any) => void;
216
+ type DeliveryType = 'immediate' | 'buffer';
217
+ type StorageStrategy = 'none' | 'session' | 'anonymousId';
218
+ type PreConsentStorageOptions = {
219
+ strategy: StorageStrategy;
220
+ };
221
+ type PreConsentEventsOptions = {
222
+ delivery: DeliveryType;
223
+ };
224
+ type PreConsentOptions = {
225
+ enabled: boolean;
226
+ storage?: PreConsentStorageOptions;
227
+ events?: PreConsentEventsOptions;
228
+ };
229
+ /**
230
+ * Represents the options parameter in the load API
231
+ */
232
+ type LoadOptions = {
233
+ logLevel?: LogLevel;
234
+ integrations?: IntegrationOpts;
235
+ configUrl?: string;
236
+ queueOptions?: QueueOpts;
237
+ loadIntegration?: boolean;
238
+ sessions?: SessionOpts;
239
+ secureCookie?: boolean;
240
+ destSDKBaseURL?: string;
241
+ pluginsSDKBaseURL?: string;
242
+ useBeacon?: boolean;
243
+ beaconQueueOptions?: BeaconQueueOpts;
244
+ destinationsQueueOptions?: DestinationsQueueOpts;
245
+ anonymousIdOptions?: AnonymousIdOptions;
246
+ setCookieDomain?: string;
247
+ sameSiteCookie?: CookieSameSite;
248
+ lockIntegrationsVersion?: boolean;
249
+ lockPluginsVersion?: boolean;
250
+ polyfillIfRequired?: boolean;
251
+ onLoaded?: OnLoadedCallback;
252
+ uaChTrackLevel?: UaChTrackLevel;
253
+ getSourceConfig?: () => string | ApiObject | Promise<ApiObject> | Promise<string>;
254
+ sendAdblockPage?: boolean;
255
+ sendAdblockPageOptions?: ApiOptions;
256
+ plugins?: Nullable<PluginName[]>;
257
+ polyfillURL?: string;
258
+ useGlobalIntegrationsConfigInEvents?: boolean;
259
+ bufferDataPlaneEventsUntilReady?: boolean;
260
+ dataPlaneEventsBufferTimeout?: number;
261
+ storage?: StorageOpts;
262
+ preConsent?: PreConsentOptions;
263
+ transportMode?: EventsTransportMode;
264
+ consentManagement?: ConsentManagementOptions;
265
+ sameDomainCookiesOnly?: boolean;
266
+ externalAnonymousIdCookieName?: string;
267
+ useServerSideCookies?: boolean;
268
+ dataServiceEndpoint?: string;
269
+ };
270
+ type ConsentOptions = {
271
+ storage?: StorageOpts;
272
+ consentManagement?: ConsentManagementOptions;
273
+ integrations?: IntegrationOpts;
274
+ discardPreConsentEvents?: boolean;
275
+ sendPageEvent?: boolean;
276
+ trackConsent?: boolean;
277
+ };
278
+
279
+ type Address = {
280
+ city?: string;
281
+ City?: string;
282
+ country?: string;
283
+ Country?: string;
284
+ postalCode?: string;
285
+ state?: string;
286
+ State?: string;
287
+ street?: string;
288
+ };
289
+ type Company = {
290
+ name?: string;
291
+ id?: string;
292
+ industry?: string;
293
+ employee_count?: string;
294
+ plan?: string;
295
+ };
296
+ /**
297
+ * Represents a traits object in the Identify API
298
+ */
299
+ type IdentifyTraits = {
300
+ id?: string;
301
+ userId?: string;
302
+ firstName?: string;
303
+ firstname?: string;
304
+ first_name?: string;
305
+ lastName?: string;
306
+ lastname?: string;
307
+ last_name?: string;
308
+ name?: string;
309
+ Name?: string;
310
+ age?: number;
311
+ email?: string;
312
+ Email?: string;
313
+ 'E-mail'?: string;
314
+ phone?: string;
315
+ address?: string | Address;
316
+ birthday?: string;
317
+ company?: Company;
318
+ createdAt?: string;
319
+ description?: string;
320
+ gender?: string;
321
+ title?: string;
322
+ username?: string;
323
+ website?: string;
324
+ avatar?: string;
325
+ zip?: string | number;
326
+ state?: string;
327
+ State?: string;
328
+ dob?: string;
329
+ employed?: string | boolean;
330
+ education?: string;
331
+ married?: string | boolean;
332
+ customerType?: string | number;
333
+ euConsent?: string;
334
+ euConsentMessage?: string;
335
+ newEmail?: string;
336
+ tags?: string | string[];
337
+ removeTags?: string | string[];
338
+ prospect?: string | boolean;
339
+ doubleOptin?: string | boolean;
340
+ event_id?: string;
341
+ constructor?: Record<string, string>;
342
+ organization?: string;
343
+ region?: string;
344
+ anonymous?: string | boolean;
345
+ country?: string;
346
+ custom?: string;
347
+ ip?: string;
348
+ privateAttributeNames?: any;
349
+ secondary?: any;
350
+ customPageId?: string;
351
+ isRudderEvents?: boolean;
352
+ optOutType?: boolean | string | number;
353
+ groupType?: string | number;
354
+ anonymousId?: string | number;
355
+ ip_address?: string;
356
+ number?: string | number;
357
+ [index: string]: string | number | boolean | ApiObject | null | (string | number | boolean | null | ApiObject)[] | undefined;
358
+ };
359
+
360
+ type AnalyticsIdentifyMethod = {
361
+ (userId?: string, traits?: Nullable<IdentifyTraits>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
362
+ (userId: string, traits: Nullable<IdentifyTraits>, callback: ApiCallback): void;
363
+ (userId: string, callback: ApiCallback): void;
364
+ (traits: Nullable<IdentifyTraits>, options: Nullable<ApiOptions>, callback?: ApiCallback): void;
365
+ (traits: Nullable<IdentifyTraits>, callback?: ApiCallback): void;
366
+ };
367
+ type AnalyticsPageMethod = {
368
+ (category?: string, name?: string, properties?: Nullable<ApiObject>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
369
+ (category: string, name: string, properties: Nullable<ApiObject>, callback: ApiCallback): void;
370
+ (name: string, properties?: Nullable<ApiObject>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
371
+ (category: string, name: string, callback: ApiCallback): void;
372
+ (name: string, properties: Nullable<ApiObject>, callback: ApiCallback): void;
373
+ (name: string, callback: ApiCallback): void;
374
+ (properties: Nullable<ApiObject>, options: Nullable<ApiOptions>, callback?: ApiCallback): void;
375
+ (properties: Nullable<ApiObject>, callback?: ApiCallback): void;
376
+ };
377
+ type AnalyticsTrackMethod = {
378
+ (event: string, properties?: Nullable<ApiObject>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
379
+ (event: string, properties: Nullable<ApiObject>, callback: ApiCallback): void;
380
+ (event: string, callback: ApiCallback): void;
381
+ };
382
+ type AnalyticsGroupMethod = {
383
+ (groupId: string | number, traits?: Nullable<ApiObject>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
384
+ (groupId: string | number, traits: Nullable<ApiObject>, callback: ApiCallback): void;
385
+ (groupId: string | number, callback: ApiCallback): void;
386
+ (traits: Nullable<ApiObject>, options: Nullable<ApiOptions>, callback?: ApiCallback): void;
387
+ (traits: Nullable<ApiObject>, callback?: ApiCallback): void;
388
+ };
389
+ type AnalyticsAliasMethod = {
390
+ (to: Nullable<string>, from?: string, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
391
+ (to: Nullable<string>, from: string, callback: ApiCallback): void;
392
+ (to: Nullable<string>, options: Nullable<ApiOptions>, callback?: ApiCallback): void;
393
+ (to: Nullable<string>, callback: ApiCallback): void;
394
+ (to: ApiCallback): void;
395
+ (): void;
396
+ };
397
+ interface IRudderAnalytics<T = any> {
398
+ analyticsInstances: Record<string, T>;
399
+ defaultAnalyticsKey: string;
400
+ logger: ILogger;
401
+ /**
402
+ * Set the writeKey of the analytics instance that should be default
403
+ */
404
+ setDefaultInstanceKey(writeKey: string, autoSet: boolean): void;
405
+ /**
406
+ * Get the instance of Analytics that is set as default
407
+ */
408
+ getAnalyticsInstance(writeKey?: string): T;
409
+ /**
410
+ * Trigger load event in buffer queue if exists
411
+ */
412
+ triggerBufferedLoadEvent(): void;
413
+ /**
414
+ * Call control pane to get client configs
415
+ */
416
+ load(writeKey: string, dataPlaneUrl: string, loadOptions?: Partial<LoadOptions>): void;
417
+ /**
418
+ * To register a callback for SDK ready state
419
+ */
420
+ ready(callback: ApiCallback): void;
421
+ /**
422
+ * To record a page view event
423
+ */
424
+ page: AnalyticsPageMethod;
425
+ /**
426
+ * To record a user track event
427
+ */
428
+ track: AnalyticsTrackMethod;
429
+ /**
430
+ * To record a user identification event
431
+ */
432
+ identify: AnalyticsIdentifyMethod;
433
+ /**
434
+ * To record a user alias event
435
+ */
436
+ alias: AnalyticsAliasMethod;
437
+ /**
438
+ * To record a user group event
439
+ */
440
+ group: AnalyticsGroupMethod;
441
+ /**
442
+ * Clear user information
443
+ *
444
+ * @param resetAnonymousId optionally clears anonymousId as well
445
+ */
446
+ reset(resetAnonymousId?: boolean): void;
447
+ /**
448
+ * To get anonymousId set in the SDK
449
+ *
450
+ * @param options options for anonymousId
451
+ */
452
+ getAnonymousId(options?: AnonymousIdOptions): string | undefined;
453
+ /**
454
+ * To set anonymousId
455
+ *
456
+ * @param anonymousId custom anonymousId value
457
+ * @param rudderAmpLinkerParam AMP Linker ID string
458
+ */
459
+ setAnonymousId(anonymousId?: string, rudderAmpLinkerParam?: string): void;
460
+ /**
461
+ * To get userId set in the SDK
462
+ */
463
+ getUserId(): Nullable<string> | undefined;
464
+ /**
465
+ * To get user traits set in the SDK
466
+ */
467
+ getUserTraits(): Nullable<ApiObject> | undefined;
468
+ /**
469
+ * To get groupId set in the SDK
470
+ */
471
+ getGroupId(): Nullable<string> | undefined;
472
+ /**
473
+ * To get group traits set in the SDK
474
+ */
475
+ getGroupTraits(): Nullable<ApiObject> | undefined;
476
+ /**
477
+ * To manually start user session in the SDK
478
+ */
479
+ startSession(sessionId?: number): void;
480
+ /**
481
+ * To manually end user session in the SDK
482
+ */
483
+ endSession(): void;
484
+ /**
485
+ * To set authorization token
486
+ * @param token token value
487
+ */
488
+ setAuthToken(token: string): void;
489
+ /**
490
+ * To fetch the current sessionId
491
+ */
492
+ getSessionId(): Nullable<number>;
493
+ /**
494
+ * To provide consent
495
+ * @param options Consent API options
496
+ */
497
+ consent(options?: ConsentOptions): void;
498
+ }
499
+
500
+ interface IExternalSourceLoadConfig {
501
+ url: string;
502
+ id: string;
503
+ callback?(id?: string): unknown;
504
+ async?: boolean;
505
+ timeout?: number;
506
+ extraAttributes?: Record<string, string>;
507
+ }
508
+ interface IExternalSrcLoader {
509
+ errorHandler?: {
510
+ onError(error: unknown, context?: string, customMessage?: string, shouldAlwaysThrow?: boolean): void;
511
+ leaveBreadcrumb(breadcrumb: string): void;
512
+ notifyError(error: Error): void;
513
+ };
514
+ logger?: ILogger;
515
+ timeout: number;
516
+ loadJSFile(config: IExternalSourceLoadConfig): void;
517
+ }
518
+
519
+ /**
520
+ * A buffer queue to serve as a store for any type of data
521
+ */
522
+ declare class BufferQueue<T = any> {
523
+ items: T[];
524
+ constructor();
525
+ enqueue(item: T): void;
526
+ dequeue(): Nullable<T> | undefined;
527
+ isEmpty(): boolean;
528
+ size(): number;
529
+ clear(): void;
530
+ }
531
+ //# sourceMappingURL=BufferQueue.d.ts.map
532
+
533
+ type SDKError = unknown | Error | ErrorEvent | Event | PromiseRejectionEvent;
534
+ interface IErrorHandler {
535
+ logger?: ILogger;
536
+ pluginEngine?: IPluginEngine;
537
+ errorBuffer: BufferQueue<PreLoadErrorData>;
538
+ init(externalSrcLoader: IExternalSrcLoader): void;
539
+ onError(error: SDKError, context?: string, customMessage?: string, shouldAlwaysThrow?: boolean, errorType?: string): void;
540
+ leaveBreadcrumb(breadcrumb: string): void;
541
+ notifyError(error: Error): void;
542
+ attachErrorListeners(): void;
543
+ }
544
+ type ErrorState = {
545
+ severity: string;
546
+ unhandled: boolean;
547
+ severityReason: {
548
+ type: string;
549
+ };
550
+ };
551
+ type PreLoadErrorData = {
552
+ error: SDKError;
553
+ errorState: ErrorState;
554
+ };
555
+
556
+ interface IRequestConfig {
557
+ url: string;
558
+ options?: Partial<IXHRRequestOptions>;
559
+ isRawResponse?: boolean;
560
+ timeout?: number;
561
+ }
562
+ type ResponseDetails = {
563
+ response: string;
564
+ error?: Error;
565
+ xhr?: XMLHttpRequest;
566
+ options: IXHRRequestOptions;
567
+ };
568
+ type AsyncRequestCallback<T> = (data?: T | string | undefined, details?: ResponseDetails) => void;
569
+ interface IAsyncRequestConfig<T> extends IRequestConfig {
570
+ callback?: AsyncRequestCallback<T>;
571
+ }
572
+ interface IXHRRequestOptions {
573
+ method: HTTPClientMethod;
574
+ url: string;
575
+ headers: Record<string, string | undefined>;
576
+ data?: XMLHttpRequestBodyInit;
577
+ sendRawData?: boolean;
578
+ withCredentials?: boolean;
579
+ }
580
+ type HTTPClientMethod = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
581
+ interface IHttpClient {
582
+ errorHandler?: IErrorHandler;
583
+ logger?: ILogger;
584
+ basicAuthHeader?: string;
585
+ hasErrorHandler: boolean;
586
+ getData<T = any>(config: IRequestConfig): Promise<{
587
+ data: T | string | undefined;
588
+ details?: ResponseDetails;
589
+ }>;
590
+ getAsyncData<T = any>(config: IAsyncRequestConfig<T>): void;
591
+ setAuthHeader(value: string, noBto?: boolean): void;
592
+ resetAuthHeader(): void;
593
+ }
594
+
595
+ type StoreId = string;
596
+ interface IStoreConfig {
597
+ name: string;
598
+ id: StoreId;
599
+ isEncrypted?: boolean;
600
+ validKeys?: Record<string, string>;
601
+ noCompoundKey?: boolean;
602
+ errorHandler?: IErrorHandler;
603
+ logger?: ILogger;
604
+ type?: StorageType;
605
+ }
606
+ interface IStoreManager {
607
+ stores?: Record<StoreId, IStore>;
608
+ isInitialized?: boolean;
609
+ errorHandler?: IErrorHandler;
610
+ logger?: ILogger;
611
+ init(): void;
612
+ initializeStorageState(): void;
613
+ setStore(storeConfig: IStoreConfig): IStore;
614
+ getStore(id: StoreId): IStore | undefined;
615
+ }
616
+ interface IStore {
617
+ id: string;
618
+ name: string;
619
+ isEncrypted: boolean;
620
+ validKeys: Record<string, string>;
621
+ engine: IStorage;
622
+ originalEngine: IStorage;
623
+ noKeyValidation?: boolean;
624
+ noCompoundKey?: boolean;
625
+ errorHandler?: IErrorHandler;
626
+ logger?: ILogger;
627
+ pluginsManager?: IPluginsManager;
628
+ createValidKey(key: string): string | undefined;
629
+ swapQueueStoreToInMemoryEngine(): void;
630
+ set(key: string, value: any): void;
631
+ get<T = any>(key: string): Nullable<T>;
632
+ remove(key: string): void;
633
+ getOriginalEngine(): IStorage;
634
+ decrypt(value?: Nullable<string>): Nullable<string>;
635
+ encrypt(value: any): string;
636
+ crypto(value: string, mode: 'encrypt' | 'decrypt'): string;
637
+ onError(error: unknown): void;
638
+ }
639
+ interface IStorage extends Storage {
640
+ configure?(options: StorageOptions): void;
641
+ keys(): string[];
642
+ isEnabled?: boolean;
643
+ }
644
+ type StorageOptions = Partial<ICookieStorageOptions | ILocalStorageOptions | IInMemoryStorageOptions>;
645
+ interface ICookieStorageOptions extends CookieOptions {
646
+ samesite?: CookieSameSite;
647
+ domain?: string;
648
+ secure?: boolean;
649
+ enabled?: boolean;
650
+ sameDomainCookiesOnly?: boolean;
651
+ }
652
+ interface ILocalStorageOptions {
653
+ enabled?: boolean;
654
+ }
655
+ interface IInMemoryStorageOptions {
656
+ enabled?: boolean;
657
+ }
658
+
659
+ type PageCallOptions = {
660
+ category?: string;
661
+ name?: string;
662
+ properties?: Nullable<ApiObject>;
663
+ options?: Nullable<ApiOptions>;
664
+ callback?: ApiCallback;
665
+ };
666
+ type TrackCallOptions = {
667
+ name: string;
668
+ properties?: Nullable<ApiObject>;
669
+ options?: Nullable<ApiOptions>;
670
+ callback?: ApiCallback;
671
+ };
672
+ type IdentifyCallOptions = {
673
+ userId?: string | null;
674
+ traits?: Nullable<IdentifyTraits>;
675
+ options?: Nullable<ApiOptions>;
676
+ callback?: ApiCallback;
677
+ };
678
+ type AliasCallOptions = {
679
+ to?: Nullable<string>;
680
+ from?: Nullable<string>;
681
+ options?: Nullable<ApiOptions>;
682
+ callback?: ApiCallback;
683
+ };
684
+ type GroupCallOptions = {
685
+ groupId?: Nullable<string>;
686
+ traits?: Nullable<ApiObject>;
687
+ options?: Nullable<ApiOptions>;
688
+ callback?: ApiCallback;
689
+ };
690
+
691
+ /**
692
+ * Store Implementation with dedicated storage
693
+ */
694
+ declare class Store implements IStore {
695
+ id: string;
696
+ name: string;
697
+ isEncrypted: boolean;
698
+ validKeys: Record<string, string>;
699
+ engine: IStorage;
700
+ originalEngine: IStorage;
701
+ noKeyValidation?: boolean;
702
+ noCompoundKey?: boolean;
703
+ errorHandler?: IErrorHandler;
704
+ hasErrorHandler: boolean;
705
+ logger?: ILogger;
706
+ pluginsManager?: IPluginsManager;
707
+ constructor(config: IStoreConfig, engine?: IStorage, pluginsManager?: IPluginsManager);
708
+ /**
709
+ * Ensure the key is valid and with correct format
710
+ */
711
+ createValidKey(key: string): string | undefined;
712
+ /**
713
+ * Switch to inMemoryEngine, bringing any existing data with.
714
+ */
715
+ swapQueueStoreToInMemoryEngine(): void;
716
+ /**
717
+ * Set value by key.
718
+ */
719
+ set(key: string, value: any): void;
720
+ /**
721
+ * Get by Key.
722
+ */
723
+ get<T = any>(key: string): Nullable<T>;
724
+ /**
725
+ * Remove by Key.
726
+ */
727
+ remove(key: string): void;
728
+ /**
729
+ * Get original engine
730
+ */
731
+ getOriginalEngine(): IStorage;
732
+ /**
733
+ * Decrypt values
734
+ */
735
+ decrypt(value?: Nullable<string>): Nullable<string>;
736
+ /**
737
+ * Encrypt value
738
+ */
739
+ encrypt(value: Nullable<any>): string;
740
+ /**
741
+ * Extension point to use with encryption plugins
742
+ */
743
+ crypto(value: Nullable<any>, mode: 'encrypt' | 'decrypt'): string;
744
+ /**
745
+ * Handle errors
746
+ */
747
+ onError(error: unknown): void;
748
+ }
749
+ //# sourceMappingURL=Store.d.ts.map
750
+
751
+ interface IUserSessionManager {
752
+ storeManager?: IStoreManager;
753
+ init(): void;
754
+ setAnonymousId(anonymousId?: string, rudderAmpLinkerParam?: string): void;
755
+ getAnonymousId(options?: AnonymousIdOptions): string;
756
+ refreshSession(): void;
757
+ getSessionId(): Nullable<number>;
758
+ getGroupId(): Nullable<string>;
759
+ getUserId(): Nullable<string>;
760
+ setUserId(userId?: null | string): void;
761
+ setUserTraits(traits?: Nullable<ApiObject>): void;
762
+ getUserTraits(): Nullable<ApiObject>;
763
+ getGroupTraits(): Nullable<ApiObject>;
764
+ setGroupId(groupId?: Nullable<string>): void;
765
+ setGroupTraits(traits?: Nullable<ApiObject>): void;
766
+ reset(resetAnonymousId?: boolean, noNewSessionStart?: boolean): void;
767
+ start(sessionId?: number): void;
768
+ end(): void;
769
+ syncStorageDataToState(): void;
770
+ setAuthToken(token: Nullable<string>): void;
771
+ }
772
+
773
+ interface IConfigManager {
774
+ httpClient: IHttpClient;
775
+ errorHandler?: IErrorHandler;
776
+ logger?: ILogger;
777
+ init: () => void;
778
+ getConfig: () => void;
779
+ processConfig: () => void;
780
+ }
781
+
782
+ interface IEventManager {
783
+ init(): void;
784
+ addEvent(event: APIEvent): void;
785
+ resume(): void;
786
+ }
787
+
788
+ interface ICapabilitiesManager {
789
+ logger?: ILogger;
790
+ errorHandler?: IErrorHandler;
791
+ externalSrcLoader: IExternalSrcLoader;
792
+ init(): void;
793
+ detectBrowserCapabilities(): void;
794
+ prepareBrowserCapabilities(): void;
795
+ attachWindowListeners(): void;
796
+ onReady(): void;
797
+ }
798
+
799
+ type PreloadedEventCall = Array<string | any>;
800
+ type RudderAnalyticsPreloader = {
801
+ [index: string]: (...args: any[]) => any;
802
+ };
803
+
804
+ interface IAnalytics {
805
+ preloadBuffer: BufferQueue<PreloadedEventCall>;
806
+ initialized: boolean;
807
+ httpClient: IHttpClient;
808
+ logger: ILogger;
809
+ errorHandler: IErrorHandler;
810
+ externalSrcLoader: IExternalSrcLoader;
811
+ capabilitiesManager: ICapabilitiesManager;
812
+ storeManager?: IStoreManager;
813
+ configManager?: IConfigManager;
814
+ eventManager?: IEventManager;
815
+ userSessionManager?: IUserSessionManager;
816
+ pluginsManager?: IPluginsManager;
817
+ clientDataStore?: Store;
818
+ /**
819
+ * Start application lifecycle if not already started
820
+ */
821
+ load(writeKey: string, dataPlaneUrl?: string | Partial<LoadOptions>, loadOptions?: Partial<LoadOptions>): void;
822
+ /**
823
+ * Orchestrate the lifecycle of the application phases/status
824
+ */
825
+ startLifecycle(): void;
826
+ /**
827
+ * Load browser polyfill if required
828
+ */
829
+ onMounted(): void;
830
+ /**
831
+ * Prepare internal services and load configuration
832
+ */
833
+ onBrowserCapabilitiesReady(): void;
834
+ /**
835
+ * Enqueue in buffer the events that were triggered pre SDK initialization
836
+ */
837
+ enqueuePreloadBufferEvents(bufferedEvents: PreloadedEventCall[]): void;
838
+ /**
839
+ * Start the process of consuming the buffered events that were triggered pre SDK initialization
840
+ */
841
+ processDataInPreloadBuffer(): void;
842
+ /**
843
+ * Assign instances for the internal services
844
+ */
845
+ prepareInternalServices(): void;
846
+ /**
847
+ * Load configuration
848
+ */
849
+ loadConfig(): void;
850
+ /**
851
+ * Initialize the storage and event queue
852
+ */
853
+ onPluginsReady(): void;
854
+ /**
855
+ * Load plugins
856
+ */
857
+ onConfigured(): void;
858
+ /**
859
+ * Trigger onLoaded callback if any is provided in config & emit initialised event
860
+ */
861
+ onInitialized(): void;
862
+ /**
863
+ * Emit ready event
864
+ */
865
+ onReady(): void;
866
+ /**
867
+ * Consume preloaded events buffer
868
+ */
869
+ processBufferedEvents(): void;
870
+ /**
871
+ * Load device mode destinations
872
+ */
873
+ loadDestinations(): void;
874
+ /**
875
+ * Invoke the ready callbacks if any exist
876
+ */
877
+ onDestinationsReady(): void;
878
+ /**
879
+ * To register a callback for SDK ready state
880
+ */
881
+ ready(callback: ApiCallback, isBufferedInvocation?: boolean): void;
882
+ /**
883
+ * To record a page view event
884
+ */
885
+ page(pageOptions: PageCallOptions, isBufferedInvocation?: boolean): void;
886
+ /**
887
+ * To record a user track event
888
+ */
889
+ track(trackCallOptions: TrackCallOptions, isBufferedInvocation?: boolean): void;
890
+ /**
891
+ * To record a user identification event
892
+ */
893
+ identify(identifyCallOptions: IdentifyCallOptions, isBufferedInvocation?: boolean): void;
894
+ /**
895
+ * To record a user alias event
896
+ */
897
+ alias(aliasCallOptions: AliasCallOptions, isBufferedInvocation?: boolean): void;
898
+ /**
899
+ * To record a user group event
900
+ */
901
+ group(groupCallOptions: GroupCallOptions, isBufferedInvocation?: boolean): void;
902
+ /**
903
+ * To get anonymousId set in the SDK
904
+ */
905
+ getAnonymousId(options?: AnonymousIdOptions): string | undefined;
906
+ /**
907
+ * To set anonymousId
908
+ */
909
+ setAnonymousId(anonymousId?: string, rudderAmpLinkerParam?: string, isBufferedInvocation?: boolean): void;
910
+ /**
911
+ * Clear user information, optionally anonymousId as well
912
+ */
913
+ reset(resetAnonymousId?: boolean, isBufferedInvocation?: boolean): void;
914
+ /**
915
+ * To get userId set in the SDK
916
+ */
917
+ getUserId(): Nullable<string> | undefined;
918
+ /**
919
+ * To get user traits set in the SDK
920
+ */
921
+ getUserTraits(): Nullable<ApiObject> | undefined;
922
+ /**
923
+ * To get groupId set in the SDK
924
+ */
925
+ getGroupId(): Nullable<string> | undefined;
926
+ /**
927
+ * To get group traits set in the SDK
928
+ */
929
+ getGroupTraits(): Nullable<ApiObject> | undefined;
930
+ /**
931
+ * To manually start user session in the SDK
932
+ */
933
+ startSession(sessionId?: number, isBufferedInvocation?: boolean): void;
934
+ /**
935
+ * To manually end user session in the SDK
936
+ */
937
+ endSession(isBufferedInvocation?: boolean): void;
938
+ /**
939
+ * To fetch the current sessionId
940
+ */
941
+ getSessionId(): Nullable<number>;
942
+ /**
943
+ * To record consent
944
+ * @param options Consent API options
945
+ */
946
+ consent(options?: ConsentOptions, isBufferedInvocation?: boolean): void;
947
+ /**
948
+ * To set auth token
949
+ */
950
+ setAuthToken(token: string): void;
951
+ }
952
+
953
+ declare class RudderAnalytics implements IRudderAnalytics<IAnalytics> {
954
+ static globalSingleton: Nullable<RudderAnalytics>;
955
+ analyticsInstances: Record<string, IAnalytics>;
956
+ defaultAnalyticsKey: string;
957
+ logger: Logger;
958
+ constructor();
959
+ /**
960
+ * Set instance to use if no specific writeKey is provided in methods
961
+ * automatically for the first created instance
962
+ * TODO: to support multiple analytics instances in the near future
963
+ */
964
+ setDefaultInstanceKey(writeKey: string): void;
965
+ /**
966
+ * Retrieve an existing analytics instance
967
+ */
968
+ getAnalyticsInstance(writeKey?: string): IAnalytics;
969
+ /**
970
+ * Create new analytics instance and trigger application lifecycle start
971
+ */
972
+ load(writeKey: string, dataPlaneUrl: string, loadOptions?: Partial<LoadOptions>): void;
973
+ /**
974
+ * Trigger load event in buffer queue if exists and stores the
975
+ * remaining preloaded events array in global object
976
+ */
977
+ triggerBufferedLoadEvent(): void;
978
+ /**
979
+ * Get ready callback arguments and forward to ready call
980
+ */
981
+ ready(callback: ApiCallback): void;
982
+ /**
983
+ * Process page arguments and forward to page call
984
+ */
985
+ page(category?: string | Nullable<ApiObject> | ApiCallback, name?: string | Nullable<ApiOptions> | Nullable<ApiObject> | ApiCallback, properties?: Nullable<ApiOptions> | Nullable<ApiObject> | ApiCallback, options?: Nullable<ApiOptions> | ApiCallback, callback?: ApiCallback): void;
986
+ /**
987
+ * Process track arguments and forward to page call
988
+ */
989
+ track(event: string, properties?: Nullable<ApiObject> | ApiCallback, options?: Nullable<ApiOptions> | ApiCallback, callback?: ApiCallback): void;
990
+ /**
991
+ * Process identify arguments and forward to page call
992
+ */
993
+ identify(userId?: string | number | Nullable<IdentifyTraits>, traits?: Nullable<IdentifyTraits> | Nullable<ApiOptions> | ApiCallback, options?: Nullable<ApiOptions> | ApiCallback, callback?: ApiCallback): void;
994
+ /**
995
+ * Process alias arguments and forward to page call
996
+ */
997
+ alias(to?: Nullable<string> | ApiCallback, from?: string | Nullable<ApiOptions> | ApiCallback, options?: Nullable<ApiOptions> | ApiCallback, callback?: ApiCallback): void;
998
+ /**
999
+ * Process group arguments and forward to page call
1000
+ */
1001
+ group(groupId: string | number | Nullable<ApiObject> | ApiCallback, traits?: Nullable<ApiOptions> | Nullable<ApiObject> | ApiCallback, options?: Nullable<ApiOptions> | ApiCallback, callback?: ApiCallback): void;
1002
+ reset(resetAnonymousId?: boolean): void;
1003
+ getAnonymousId(options?: AnonymousIdOptions): string | undefined;
1004
+ setAnonymousId(anonymousId?: string, rudderAmpLinkerParam?: string): void;
1005
+ getUserId(): Nullable<string> | undefined;
1006
+ getUserTraits(): Nullable<ApiObject> | undefined;
1007
+ getGroupId(): Nullable<string> | undefined;
1008
+ getGroupTraits(): Nullable<ApiObject> | undefined;
1009
+ startSession(sessionId?: number): void;
1010
+ endSession(): void;
1011
+ getSessionId(): Nullable<number>;
1012
+ setAuthToken(token: string): void;
1013
+ consent(options?: ConsentOptions): void;
1014
+ }
1015
+ //# sourceMappingURL=RudderAnalytics.d.ts.map
1016
+
1017
+ declare global {
1018
+ interface Window {
1019
+ rudderanalytics: RudderAnalytics | RudderAnalyticsPreloader | undefined;
1020
+ }
1021
+ }
1022
+ //# sourceMappingURL=index.d.ts.map
1023
+
1024
+ export { type AnonymousIdOptions, type ApiCallback, type ApiObject, type ApiOptions, type BeaconQueueOpts, type ConsentOptions, type CookieSameSite, type DestinationsQueueOpts, type IdentifyTraits, type IntegrationOpts, type LoadOptions, type LogLevel, type PluginName, type PreloadedEventCall, type QueueOpts, RudderAnalytics, type RudderAnalyticsPreloader, type SessionOpts, type UaChTrackLevel };