@rudderstack/analytics-js 3.6.0 → 3.7.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.
@@ -0,0 +1,1043 @@
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 | Date | 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?: 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
+ organization?: string;
342
+ region?: string;
343
+ anonymous?: string | boolean;
344
+ country?: string;
345
+ custom?: string;
346
+ ip?: string;
347
+ privateAttributeNames?: any;
348
+ secondary?: any;
349
+ customPageId?: string;
350
+ isRudderEvents?: boolean;
351
+ optOutType?: boolean | string | number;
352
+ groupType?: string | number;
353
+ anonymousId?: string | number;
354
+ ip_address?: string;
355
+ number?: string | number;
356
+ [index: string]: string | number | boolean | ApiObject | null | Date | (string | number | boolean | null | Date | ApiObject)[] | undefined;
357
+ };
358
+
359
+ type AnalyticsIdentifyMethod = {
360
+ (userId: string, traits?: Nullable<IdentifyTraits>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
361
+ (userId: string, traits?: Nullable<IdentifyTraits>, callback?: ApiCallback): void;
362
+ (userId: string, callback?: ApiCallback): void;
363
+ (traits: Nullable<IdentifyTraits>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
364
+ (traits: Nullable<IdentifyTraits>, callback?: ApiCallback): void;
365
+ };
366
+ type AnalyticsPageMethod = {
367
+ (category: string, name: string, properties?: Nullable<ApiObject>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
368
+ (category: string, name: string, properties?: Nullable<ApiObject>, callback?: ApiCallback): void;
369
+ (category: string, name: string, callback?: ApiCallback): void;
370
+ (name: string, properties?: Nullable<ApiObject>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
371
+ (name: string, properties?: Nullable<ApiObject>, callback?: ApiCallback): void;
372
+ (name: string, callback?: ApiCallback): void;
373
+ (properties: Nullable<ApiObject>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
374
+ (properties: Nullable<ApiObject>, callback?: ApiCallback): void;
375
+ (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, traits?: Nullable<IdentifyTraits>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
384
+ (groupId: string, traits?: Nullable<IdentifyTraits>, callback?: ApiCallback): void;
385
+ (groupId: string, callback?: ApiCallback): void;
386
+ (traits: Nullable<IdentifyTraits>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
387
+ (traits: Nullable<IdentifyTraits>, callback?: ApiCallback): void;
388
+ };
389
+ type AnalyticsAliasMethod = {
390
+ (to: string, from?: string, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
391
+ (to: string, from?: string, callback?: ApiCallback): void;
392
+ (to: string, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
393
+ (to: string, callback?: ApiCallback): void;
394
+ };
395
+ interface IRudderAnalytics<T = any> {
396
+ analyticsInstances: Record<string, T>;
397
+ defaultAnalyticsKey: string;
398
+ logger: ILogger;
399
+ /**
400
+ * Set the writeKey of the analytics instance that should be default
401
+ */
402
+ setDefaultInstanceKey(writeKey: string, autoSet: boolean): void;
403
+ /**
404
+ * Get the instance of Analytics that is set as default
405
+ */
406
+ getAnalyticsInstance(writeKey?: string): T;
407
+ /**
408
+ * Trigger load event in buffer queue if exists
409
+ */
410
+ triggerBufferedLoadEvent(): void;
411
+ /**
412
+ * Call control pane to get client configs
413
+ */
414
+ load(writeKey: string, dataPlaneUrl: string, loadOptions?: Partial<LoadOptions>): void;
415
+ /**
416
+ * To register a callback for SDK ready state
417
+ */
418
+ ready(callback: ApiCallback): void;
419
+ /**
420
+ * To record a page view event
421
+ */
422
+ page: AnalyticsPageMethod;
423
+ /**
424
+ * To record a user track event
425
+ */
426
+ track: AnalyticsTrackMethod;
427
+ /**
428
+ * To record a user identification event
429
+ */
430
+ identify: AnalyticsIdentifyMethod;
431
+ /**
432
+ * To record a user alias event
433
+ */
434
+ alias: AnalyticsAliasMethod;
435
+ /**
436
+ * To record a user group event
437
+ */
438
+ group: AnalyticsGroupMethod;
439
+ /**
440
+ * Clear user information
441
+ *
442
+ * @param resetAnonymousId optionally clears anonymousId as well
443
+ */
444
+ reset(resetAnonymousId?: boolean): void;
445
+ /**
446
+ * To get anonymousId set in the SDK
447
+ *
448
+ * @param options options for anonymousId
449
+ */
450
+ getAnonymousId(options?: AnonymousIdOptions): string | undefined;
451
+ /**
452
+ * To set anonymousId
453
+ *
454
+ * @param anonymousId custom anonymousId value
455
+ * @param rudderAmpLinkerParam AMP Linker ID string
456
+ */
457
+ setAnonymousId(anonymousId?: string, rudderAmpLinkerParam?: string): void;
458
+ /**
459
+ * To get userId set in the SDK
460
+ */
461
+ getUserId(): Nullable<string> | undefined;
462
+ /**
463
+ * To get user traits set in the SDK
464
+ */
465
+ getUserTraits(): Nullable<ApiObject> | undefined;
466
+ /**
467
+ * To get groupId set in the SDK
468
+ */
469
+ getGroupId(): Nullable<string> | undefined;
470
+ /**
471
+ * To get group traits set in the SDK
472
+ */
473
+ getGroupTraits(): Nullable<ApiObject> | undefined;
474
+ /**
475
+ * To manually start user session in the SDK
476
+ */
477
+ startSession(sessionId?: number): void;
478
+ /**
479
+ * To manually end user session in the SDK
480
+ */
481
+ endSession(): void;
482
+ /**
483
+ * To set authorization token
484
+ * @param token token value
485
+ */
486
+ setAuthToken(token: string): void;
487
+ /**
488
+ * To fetch the current sessionId
489
+ */
490
+ getSessionId(): Nullable<number>;
491
+ /**
492
+ * To provide consent
493
+ * @param options Consent API options
494
+ */
495
+ consent(options?: ConsentOptions): void;
496
+ }
497
+
498
+ /**
499
+ * A buffer queue to serve as a store for any type of data
500
+ */
501
+ declare class BufferQueue<T = any> {
502
+ items: T[];
503
+ constructor();
504
+ enqueue(item: T): void;
505
+ dequeue(): Nullable<T> | undefined;
506
+ isEmpty(): boolean;
507
+ size(): number;
508
+ clear(): void;
509
+ }
510
+ //# sourceMappingURL=BufferQueue.d.ts.map
511
+
512
+ interface IExternalSourceLoadConfig {
513
+ url: string;
514
+ id: string;
515
+ callback?(id?: string): unknown;
516
+ async?: boolean;
517
+ timeout?: number;
518
+ extraAttributes?: Record<string, string>;
519
+ }
520
+ interface IExternalSrcLoader {
521
+ errorHandler?: {
522
+ onError(error: unknown, context?: string, customMessage?: string, shouldAlwaysThrow?: boolean): void;
523
+ leaveBreadcrumb(breadcrumb: string): void;
524
+ notifyError(error: Error, errorState: ErrorState): void;
525
+ };
526
+ logger?: ILogger;
527
+ timeout: number;
528
+ loadJSFile(config: IExternalSourceLoadConfig): void;
529
+ }
530
+
531
+ type SDKError = unknown | Error | ErrorEvent | Event | PromiseRejectionEvent;
532
+ interface IErrorHandler {
533
+ logger?: ILogger;
534
+ pluginEngine?: IPluginEngine;
535
+ errorBuffer: BufferQueue<PreLoadErrorData>;
536
+ init(httpClient: IHttpClient, externalSrcLoader: IExternalSrcLoader): void;
537
+ onError(error: SDKError, context?: string, customMessage?: string, shouldAlwaysThrow?: boolean, errorType?: string): void;
538
+ leaveBreadcrumb(breadcrumb: string): void;
539
+ notifyError(error: Error, errorState: ErrorState): void;
540
+ attachErrorListeners(): void;
541
+ }
542
+ type ErrorState = {
543
+ severity: string;
544
+ unhandled: boolean;
545
+ severityReason: {
546
+ type: string;
547
+ };
548
+ };
549
+ type PreLoadErrorData = {
550
+ error: SDKError;
551
+ errorState: ErrorState;
552
+ };
553
+
554
+ interface IRequestConfig {
555
+ url: string;
556
+ options?: Partial<IXHRRequestOptions>;
557
+ isRawResponse?: boolean;
558
+ timeout?: number;
559
+ }
560
+ type ResponseDetails = {
561
+ response: string;
562
+ error?: Error;
563
+ xhr?: XMLHttpRequest;
564
+ options: IXHRRequestOptions;
565
+ };
566
+ type AsyncRequestCallback<T> = (data?: T | string | undefined, details?: ResponseDetails) => void;
567
+ interface IAsyncRequestConfig<T> extends IRequestConfig {
568
+ callback?: AsyncRequestCallback<T>;
569
+ }
570
+ interface IXHRRequestOptions {
571
+ method: HTTPClientMethod;
572
+ url: string;
573
+ headers: Record<string, string | undefined>;
574
+ data?: XMLHttpRequestBodyInit;
575
+ sendRawData?: boolean;
576
+ withCredentials?: boolean;
577
+ }
578
+ type HTTPClientMethod = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
579
+ interface IHttpClient {
580
+ errorHandler?: IErrorHandler;
581
+ logger?: ILogger;
582
+ basicAuthHeader?: string;
583
+ hasErrorHandler: boolean;
584
+ getData<T = any>(config: IRequestConfig): Promise<{
585
+ data: T | string | undefined;
586
+ details?: ResponseDetails;
587
+ }>;
588
+ getAsyncData<T = any>(config: IAsyncRequestConfig<T>): void;
589
+ setAuthHeader(value: string, noBto?: boolean): void;
590
+ resetAuthHeader(): void;
591
+ }
592
+
593
+ type StoreId = string;
594
+ interface IStoreConfig {
595
+ name: string;
596
+ id: StoreId;
597
+ isEncrypted?: boolean;
598
+ validKeys?: Record<string, string>;
599
+ noCompoundKey?: boolean;
600
+ errorHandler?: IErrorHandler;
601
+ logger?: ILogger;
602
+ type?: StorageType;
603
+ }
604
+ interface IStoreManager {
605
+ stores?: Record<StoreId, IStore>;
606
+ isInitialized?: boolean;
607
+ errorHandler?: IErrorHandler;
608
+ logger?: ILogger;
609
+ init(): void;
610
+ initializeStorageState(): void;
611
+ setStore(storeConfig: IStoreConfig): IStore;
612
+ getStore(id: StoreId): IStore | undefined;
613
+ }
614
+ interface IStore {
615
+ id: string;
616
+ name: string;
617
+ isEncrypted: boolean;
618
+ validKeys: Record<string, string>;
619
+ engine: IStorage;
620
+ originalEngine: IStorage;
621
+ noKeyValidation?: boolean;
622
+ noCompoundKey?: boolean;
623
+ errorHandler?: IErrorHandler;
624
+ logger?: ILogger;
625
+ pluginsManager?: IPluginsManager;
626
+ createValidKey(key: string): string | undefined;
627
+ swapQueueStoreToInMemoryEngine(): void;
628
+ set(key: string, value: any): void;
629
+ get<T = any>(key: string): Nullable<T>;
630
+ remove(key: string): void;
631
+ getOriginalEngine(): IStorage;
632
+ decrypt(value?: Nullable<string>): Nullable<string>;
633
+ encrypt(value: any): string;
634
+ crypto(value: string, mode: 'encrypt' | 'decrypt'): string;
635
+ onError(error: unknown): void;
636
+ }
637
+ interface IStorage extends Storage {
638
+ configure?(options: StorageOptions): void;
639
+ keys(): string[];
640
+ isEnabled?: boolean;
641
+ }
642
+ type StorageOptions = Partial<ICookieStorageOptions | ILocalStorageOptions | IInMemoryStorageOptions>;
643
+ interface ICookieStorageOptions extends CookieOptions {
644
+ samesite?: CookieSameSite;
645
+ domain?: string;
646
+ secure?: boolean;
647
+ enabled?: boolean;
648
+ sameDomainCookiesOnly?: boolean;
649
+ }
650
+ interface ILocalStorageOptions {
651
+ enabled?: boolean;
652
+ }
653
+ interface IInMemoryStorageOptions {
654
+ enabled?: boolean;
655
+ }
656
+
657
+ type PageCallOptions = {
658
+ category?: string;
659
+ name?: string;
660
+ properties?: Nullable<ApiObject>;
661
+ options?: Nullable<ApiOptions>;
662
+ callback?: ApiCallback;
663
+ };
664
+ type TrackCallOptions = {
665
+ name: string;
666
+ properties?: Nullable<ApiObject>;
667
+ options?: Nullable<ApiOptions>;
668
+ callback?: ApiCallback;
669
+ };
670
+ type IdentifyCallOptions = {
671
+ userId?: Nullable<string>;
672
+ traits?: Nullable<IdentifyTraits>;
673
+ options?: Nullable<ApiOptions>;
674
+ callback?: ApiCallback;
675
+ };
676
+ type AliasCallOptions = {
677
+ to: string;
678
+ from?: string;
679
+ options?: Nullable<ApiOptions>;
680
+ callback?: ApiCallback;
681
+ };
682
+ type GroupCallOptions = {
683
+ groupId?: Nullable<string>;
684
+ traits?: Nullable<ApiObject>;
685
+ options?: Nullable<ApiOptions>;
686
+ callback?: ApiCallback;
687
+ };
688
+
689
+ /**
690
+ * Store Implementation with dedicated storage
691
+ */
692
+ declare class Store implements IStore {
693
+ id: string;
694
+ name: string;
695
+ isEncrypted: boolean;
696
+ validKeys: Record<string, string>;
697
+ engine: IStorage;
698
+ originalEngine: IStorage;
699
+ noKeyValidation?: boolean;
700
+ noCompoundKey?: boolean;
701
+ errorHandler?: IErrorHandler;
702
+ hasErrorHandler: boolean;
703
+ logger?: ILogger;
704
+ pluginsManager?: IPluginsManager;
705
+ constructor(config: IStoreConfig, engine?: IStorage, pluginsManager?: IPluginsManager);
706
+ /**
707
+ * Ensure the key is valid and with correct format
708
+ */
709
+ createValidKey(key: string): string | undefined;
710
+ /**
711
+ * Switch to inMemoryEngine, bringing any existing data with.
712
+ */
713
+ swapQueueStoreToInMemoryEngine(): void;
714
+ /**
715
+ * Set value by key.
716
+ */
717
+ set(key: string, value: any): void;
718
+ /**
719
+ * Get by Key.
720
+ */
721
+ get<T = any>(key: string): Nullable<T>;
722
+ /**
723
+ * Remove by Key.
724
+ */
725
+ remove(key: string): void;
726
+ /**
727
+ * Get original engine
728
+ */
729
+ getOriginalEngine(): IStorage;
730
+ /**
731
+ * Decrypt values
732
+ */
733
+ decrypt(value?: Nullable<string>): Nullable<string>;
734
+ /**
735
+ * Encrypt value
736
+ */
737
+ encrypt(value: Nullable<any>): string;
738
+ /**
739
+ * Extension point to use with encryption plugins
740
+ */
741
+ crypto(value: Nullable<any>, mode: 'encrypt' | 'decrypt'): string;
742
+ /**
743
+ * Handle errors
744
+ */
745
+ onError(error: unknown): void;
746
+ }
747
+ //# sourceMappingURL=Store.d.ts.map
748
+
749
+ interface IUserSessionManager {
750
+ storeManager?: IStoreManager;
751
+ init(): void;
752
+ setAnonymousId(anonymousId?: string, rudderAmpLinkerParam?: string): void;
753
+ getAnonymousId(options?: AnonymousIdOptions): string;
754
+ refreshSession(): void;
755
+ getSessionId(): Nullable<number>;
756
+ getGroupId(): Nullable<string>;
757
+ getUserId(): Nullable<string>;
758
+ setUserId(userId?: null | string): void;
759
+ setUserTraits(traits?: Nullable<ApiObject>): void;
760
+ getUserTraits(): Nullable<ApiObject>;
761
+ getGroupTraits(): Nullable<ApiObject>;
762
+ setGroupId(groupId?: Nullable<string>): void;
763
+ setGroupTraits(traits?: Nullable<ApiObject>): void;
764
+ reset(resetAnonymousId?: boolean, noNewSessionStart?: boolean): void;
765
+ start(sessionId?: number): void;
766
+ end(): void;
767
+ syncStorageDataToState(): void;
768
+ setAuthToken(token: Nullable<string>): void;
769
+ }
770
+
771
+ interface IConfigManager {
772
+ httpClient: IHttpClient;
773
+ errorHandler?: IErrorHandler;
774
+ logger?: ILogger;
775
+ init: () => void;
776
+ getConfig: () => void;
777
+ processConfig: () => void;
778
+ }
779
+
780
+ interface IEventManager {
781
+ init(): void;
782
+ addEvent(event: APIEvent): void;
783
+ resume(): void;
784
+ }
785
+
786
+ interface ICapabilitiesManager {
787
+ logger?: ILogger;
788
+ errorHandler?: IErrorHandler;
789
+ externalSrcLoader: IExternalSrcLoader;
790
+ init(): void;
791
+ detectBrowserCapabilities(): void;
792
+ prepareBrowserCapabilities(): void;
793
+ attachWindowListeners(): void;
794
+ onReady(): void;
795
+ }
796
+
797
+ type PreloadedEventCall = Array<string | any>;
798
+ type RudderAnalyticsPreloader = {
799
+ [index: string]: (...args: any[]) => any;
800
+ };
801
+
802
+ interface IAnalytics {
803
+ preloadBuffer: BufferQueue<PreloadedEventCall>;
804
+ initialized: boolean;
805
+ httpClient: IHttpClient;
806
+ logger: ILogger;
807
+ errorHandler: IErrorHandler;
808
+ externalSrcLoader: IExternalSrcLoader;
809
+ capabilitiesManager: ICapabilitiesManager;
810
+ storeManager?: IStoreManager;
811
+ configManager?: IConfigManager;
812
+ eventManager?: IEventManager;
813
+ userSessionManager?: IUserSessionManager;
814
+ pluginsManager?: IPluginsManager;
815
+ clientDataStore?: Store;
816
+ /**
817
+ * Start application lifecycle if not already started
818
+ */
819
+ load(writeKey: string, dataPlaneUrl?: string | Partial<LoadOptions>, loadOptions?: Partial<LoadOptions>): void;
820
+ /**
821
+ * Orchestrate the lifecycle of the application phases/status
822
+ */
823
+ startLifecycle(): void;
824
+ /**
825
+ * Load browser polyfill if required
826
+ */
827
+ onMounted(): void;
828
+ /**
829
+ * Prepare internal services and load configuration
830
+ */
831
+ onBrowserCapabilitiesReady(): void;
832
+ /**
833
+ * Enqueue in buffer the events that were triggered pre SDK initialization
834
+ */
835
+ enqueuePreloadBufferEvents(bufferedEvents: PreloadedEventCall[]): void;
836
+ /**
837
+ * Start the process of consuming the buffered events that were triggered pre SDK initialization
838
+ */
839
+ processDataInPreloadBuffer(): void;
840
+ /**
841
+ * Assign instances for the internal services
842
+ */
843
+ prepareInternalServices(): void;
844
+ /**
845
+ * Load configuration
846
+ */
847
+ loadConfig(): void;
848
+ /**
849
+ * Initialize the storage and event queue
850
+ */
851
+ onPluginsReady(): void;
852
+ /**
853
+ * Load plugins
854
+ */
855
+ onConfigured(): void;
856
+ /**
857
+ * Trigger onLoaded callback if any is provided in config & emit initialised event
858
+ */
859
+ onInitialized(): void;
860
+ /**
861
+ * Emit ready event
862
+ */
863
+ onReady(): void;
864
+ /**
865
+ * Consume preloaded events buffer
866
+ */
867
+ processBufferedEvents(): void;
868
+ /**
869
+ * Load device mode destinations
870
+ */
871
+ loadDestinations(): void;
872
+ /**
873
+ * Invoke the ready callbacks if any exist
874
+ */
875
+ onDestinationsReady(): void;
876
+ /**
877
+ * To register a callback for SDK ready state
878
+ */
879
+ ready(callback: ApiCallback, isBufferedInvocation?: boolean): void;
880
+ /**
881
+ * To record a page view event
882
+ */
883
+ page(pageOptions: PageCallOptions, isBufferedInvocation?: boolean): void;
884
+ /**
885
+ * To record a user track event
886
+ */
887
+ track(trackCallOptions: TrackCallOptions, isBufferedInvocation?: boolean): void;
888
+ /**
889
+ * To record a user identification event
890
+ */
891
+ identify(identifyCallOptions: IdentifyCallOptions, isBufferedInvocation?: boolean): void;
892
+ /**
893
+ * To record a user alias event
894
+ */
895
+ alias(aliasCallOptions: AliasCallOptions, isBufferedInvocation?: boolean): void;
896
+ /**
897
+ * To record a user group event
898
+ */
899
+ group(groupCallOptions: GroupCallOptions, isBufferedInvocation?: boolean): void;
900
+ /**
901
+ * To get anonymousId set in the SDK
902
+ */
903
+ getAnonymousId(options?: AnonymousIdOptions): string | undefined;
904
+ /**
905
+ * To set anonymousId
906
+ */
907
+ setAnonymousId(anonymousId?: string, rudderAmpLinkerParam?: string, isBufferedInvocation?: boolean): void;
908
+ /**
909
+ * Clear user information, optionally anonymousId as well
910
+ */
911
+ reset(resetAnonymousId?: boolean, isBufferedInvocation?: boolean): void;
912
+ /**
913
+ * To get userId set in the SDK
914
+ */
915
+ getUserId(): Nullable<string> | undefined;
916
+ /**
917
+ * To get user traits set in the SDK
918
+ */
919
+ getUserTraits(): Nullable<ApiObject> | undefined;
920
+ /**
921
+ * To get groupId set in the SDK
922
+ */
923
+ getGroupId(): Nullable<string> | undefined;
924
+ /**
925
+ * To get group traits set in the SDK
926
+ */
927
+ getGroupTraits(): Nullable<ApiObject> | undefined;
928
+ /**
929
+ * To manually start user session in the SDK
930
+ */
931
+ startSession(sessionId?: number, isBufferedInvocation?: boolean): void;
932
+ /**
933
+ * To manually end user session in the SDK
934
+ */
935
+ endSession(isBufferedInvocation?: boolean): void;
936
+ /**
937
+ * To fetch the current sessionId
938
+ */
939
+ getSessionId(): Nullable<number>;
940
+ /**
941
+ * To record consent
942
+ * @param options Consent API options
943
+ */
944
+ consent(options?: ConsentOptions, isBufferedInvocation?: boolean): void;
945
+ /**
946
+ * To set auth token
947
+ */
948
+ setAuthToken(token: string): void;
949
+ }
950
+
951
+ declare class RudderAnalytics implements IRudderAnalytics<IAnalytics> {
952
+ static globalSingleton: Nullable<RudderAnalytics>;
953
+ analyticsInstances: Record<string, IAnalytics>;
954
+ defaultAnalyticsKey: string;
955
+ logger: Logger;
956
+ constructor();
957
+ /**
958
+ * Set instance to use if no specific writeKey is provided in methods
959
+ * automatically for the first created instance
960
+ * TODO: to support multiple analytics instances in the near future
961
+ */
962
+ setDefaultInstanceKey(writeKey: string): void;
963
+ /**
964
+ * Retrieve an existing analytics instance
965
+ */
966
+ getAnalyticsInstance(writeKey?: string): IAnalytics;
967
+ /**
968
+ * Create new analytics instance and trigger application lifecycle start
969
+ */
970
+ load(writeKey: string, dataPlaneUrl: string, loadOptions?: Partial<LoadOptions>): void;
971
+ /**
972
+ * Trigger load event in buffer queue if exists and stores the
973
+ * remaining preloaded events array in global object
974
+ */
975
+ triggerBufferedLoadEvent(): void;
976
+ /**
977
+ * Get ready callback arguments and forward to ready call
978
+ */
979
+ ready(callback: ApiCallback): void;
980
+ /**
981
+ * Process page arguments and forward to page call
982
+ */
983
+ page(category: string, name: string, properties?: Nullable<ApiObject>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
984
+ page(category: string, name: string, properties?: Nullable<ApiObject>, callback?: ApiCallback): void;
985
+ page(category: string, name: string, callback?: ApiCallback): void;
986
+ page(name: string, properties?: Nullable<ApiObject>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
987
+ page(name: string, properties?: Nullable<ApiObject>, callback?: ApiCallback): void;
988
+ page(name: string, callback?: ApiCallback): void;
989
+ page(properties: Nullable<ApiObject>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
990
+ page(properties: Nullable<ApiObject>, callback?: ApiCallback): void;
991
+ page(callback?: ApiCallback): void;
992
+ /**
993
+ * Process track arguments and forward to page call
994
+ */
995
+ track(event: string, properties?: Nullable<ApiObject>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
996
+ track(event: string, properties?: Nullable<ApiObject>, callback?: ApiCallback): void;
997
+ track(event: string, callback?: ApiCallback): void;
998
+ /**
999
+ * Process identify arguments and forward to page call
1000
+ */
1001
+ identify(userId: string, traits?: Nullable<IdentifyTraits>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
1002
+ identify(userId: string, traits?: Nullable<IdentifyTraits>, callback?: ApiCallback): void;
1003
+ identify(userId: string, callback?: ApiCallback): void;
1004
+ identify(traits: Nullable<IdentifyTraits>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
1005
+ identify(traits: Nullable<IdentifyTraits>, callback?: ApiCallback): void;
1006
+ /**
1007
+ * Process alias arguments and forward to page call
1008
+ */
1009
+ alias(to: string, from?: string, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
1010
+ alias(to: string, from?: string, callback?: ApiCallback): void;
1011
+ alias(to: string, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
1012
+ alias(to: string, callback?: ApiCallback): void;
1013
+ /**
1014
+ * Process group arguments and forward to page call
1015
+ */
1016
+ group(groupId: string, traits?: Nullable<IdentifyTraits>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
1017
+ group(groupId: string, traits?: Nullable<IdentifyTraits>, callback?: ApiCallback): void;
1018
+ group(groupId: string, callback?: ApiCallback): void;
1019
+ group(traits: Nullable<IdentifyTraits>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
1020
+ group(traits: Nullable<IdentifyTraits>, callback?: ApiCallback): void;
1021
+ reset(resetAnonymousId?: boolean): void;
1022
+ getAnonymousId(options?: AnonymousIdOptions): string | undefined;
1023
+ setAnonymousId(anonymousId?: string, rudderAmpLinkerParam?: string): void;
1024
+ getUserId(): Nullable<string> | undefined;
1025
+ getUserTraits(): Nullable<ApiObject> | undefined;
1026
+ getGroupId(): Nullable<string> | undefined;
1027
+ getGroupTraits(): Nullable<ApiObject> | undefined;
1028
+ startSession(sessionId?: number): void;
1029
+ endSession(): void;
1030
+ getSessionId(): Nullable<number>;
1031
+ setAuthToken(token: string): void;
1032
+ consent(options?: ConsentOptions): void;
1033
+ }
1034
+ //# sourceMappingURL=RudderAnalytics.d.ts.map
1035
+
1036
+ declare global {
1037
+ interface Window {
1038
+ rudderanalytics: RudderAnalytics | RudderAnalyticsPreloader | undefined;
1039
+ }
1040
+ }
1041
+ //# sourceMappingURL=index.d.ts.map
1042
+
1043
+ 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 };