quanta.tools
Version:
Quanta.js: JS SDK for Quanta Tools
155 lines (154 loc) • 5.44 kB
TypeScript
/**
* Quanta Analytics SDK for Web
*/
declare class Quanta {
private static _initialized;
private static _initializing;
private static _initializingPromise;
private static _id;
private static _appId;
private static _abLetters;
private static _abDict;
private static _queue;
private static _isProcessing;
private static _installDate;
private static _skipFirstViewEvent;
private static _skipNavigationViewEvents;
private static _skipAllViewEvents;
private static _isFirstViewEvent;
private static _currentPath;
protected static makeAsyncStorage(): {
getItem: (key: string) => Promise<string | null>;
setItem: (key: string, value: string) => Promise<void>;
};
static asyncStorage: {
getItem: (key: string) => Promise<string | null>;
setItem: (key: string, value: string) => Promise<void>;
};
/**
* Initialize the Quanta SDK
* @param appId Your Quanta application ID (optional if loaded via script tag)
*/
static initialize(appId?: string): void;
static loadAppId(): Promise<string | null>;
static setAppId(appId: string): Promise<void>;
/**
* Initialize the Quanta SDK
* @param appId Your Quanta application ID (optional if loaded via script tag)
*/
static initializeAsync(appId?: string): Promise<void>;
/**
* Set up listeners to detect URL changes from both history API and navigation events
*/
protected static setupUrlChangeListeners(): void;
/**
* Handle URL changes by checking if path changed and sending view event
*/
protected static handleUrlChange(): Promise<void>;
static maybeSendViewEvent(): Promise<void>;
/**
* Send a view event to Quanta
*/
static sendViewEvent(): Promise<void>;
/**
* Parse data attributes from the script tag
*/
private static parseScriptTagAttributes;
protected static getScriptTag(): HTMLScriptElement | null;
/**
* Extract app ID from the script tag URL
* Expected format: https://js.quanta.tools/app/{appId}.js
*/
protected static getAppIdFromScriptTag(): string | null;
/**
* Log an event to Quanta
* @param event Event name
* @param addedArguments Additional event parameters or formatted argument string
*/
static log(event: string, addedArguments?: Record<string, string> | string): void;
/**
* Log an event to Quanta
* @param event Event name
* @param addedArguments Additional event parameters or formatted argument string
*/
static logAsync(event: string, addedArguments?: Record<string, string> | string): Promise<void>;
/**
* Log an event with revenue to Quanta
* @param event Event name
* @param revenue Revenue amount
* @param addedArguments Additional event parameters or formatted argument string
*/
static logWithRevenue(event: string, revenue?: number, addedArguments?: Record<string, string> | string): void;
protected static isServerSide(): boolean;
/**
* Log an event with revenue to Quanta
* @param event Event name
* @param revenue Revenue amount
* @param addedArguments Additional event parameters or formatted argument string
*/
static logWithRevenueAsync(event: string, revenue?: number, addedArguments?: Record<string, string> | string): Promise<void>;
/**
* Get the result of an AB test for an experiment
* @param experimentName The name of the experiment
* @returns The variant letter (A, B, C, etc.)
*/
static abTest(experimentName: string): string;
/**
* Get the result of an AB test for an experiment
* @param experimentName The name of the experiment
* @returns The variant letter (A, B, C, etc.)
*/
static abTestAsync(experimentName: string): Promise<string>;
/**
* Set the user ID
* @param id User ID
*/
static setId(id: string): void;
/**
* Set the user ID
* @param id User ID
*/
static setIdAsync(id: string): Promise<void>;
/**
* Get the current user ID
* @returns User ID
*/
static getId(): string;
private static loadOrCreateId;
private static loadOrCreateInstallDate;
protected static systemLanguageProvider(): string;
protected static getBundleId(): string;
protected static getVersion(): string;
private static getUserData;
protected static getDeviceInfo(): string;
protected static getOSInfo(): string;
private static getOSInfoSafe;
protected static isDebug(): boolean;
private static safe;
private static stringForDouble;
private static enqueueEvent;
private static processQueue;
private static sendEvent;
private static saveQueue;
private static loadQueue;
private static setAbJson;
private static getAbLetters;
private static getAbDict;
private static stringToNumber;
private static generateUuid;
private static shortenUuid;
private static isValidUUID;
private static shouldLog;
private static loggingEnabled;
static enableLogging(): void;
static disableLogging(): void;
private static debugLog;
private static debugWarn;
private static debugError;
/**
* Checks if the app has been claimed and shows welcome message if not
*/
private static checkClaimed;
}
export { Quanta };
export default Quanta;