import AutoCapture from "./autoCapture"; import { StatsigClient } from "statsig-js"; import { getStatsigUser } from "./utils"; export default abstract class StatsigWA { static _captureHelper: AutoCapture | null = null; static _statsigInstance: StatsigClient | null = null; public static async initialize( apiKey: string, autoStart: boolean, shouldAutoCapture: boolean = true, ) { if (shouldAutoCapture) { this._captureHelper = new AutoCapture(autoStart); } this._statsigInstance = new StatsigClient(apiKey, getStatsigUser()); await this._statsigInstance.initializeAsync(); this._captureHelper?.setStatsigInstance(this._statsigInstance); if (window) { (window as any)['statsig_wa'] = (window as any)['statsig_wa'] || this; } } public static start() { this._captureHelper?.start(); } public static stop() { this._captureHelper?.stop(); } public static getStatsigUser() { return getStatsigUser(); } public static getStatsigClient() { return this._statsigInstance; } } if (document.currentScript) { debugger; const srcUrl = document.currentScript.getAttribute('src'); const baseUrl = window?.location?.href; if (srcUrl && baseUrl) { try { const url = new URL(srcUrl, baseUrl); const apiKey = url.searchParams.get('apikey'); const autoStart = url.searchParams.get('autostart') !== '0'; const autoCapture = url.searchParams.get('autocapture') !== '0'; if (apiKey) { StatsigWA.initialize(apiKey, autoStart, autoCapture); } else { console.error('Statsig Web AutoCapture: No API key provided'); } } catch (e) { console.error('Statsig Web AutoCapture: Invalid source URL'); } } }