import { normalizeUrl } from "../utils/url.js";
import { ConfigManager } from "./base.js";
const DEFAULT_ANALYTICS_URL = "https://demo.tilework.tech";
export const analyticsApi = {
    trackEvent: async (args) => {
        const config = ConfigManager.loadConfig();
        const baseUrl = config?.organizationUrl ?? DEFAULT_ANALYTICS_URL;
        const url = normalizeUrl({ baseUrl, path: "/api/analytics/track" });
        try {
            const response = await fetch(url, {
                method: "POST",
                headers: { "Content-Type": "application/json" },
                body: JSON.stringify(args),
            });
            if (!response.ok) {
                return { success: false };
            }
            return (await response.json());
        }
        catch {
            // Analytics failures should be silent - don't interrupt user flow
            return { success: false };
        }
    },
};
//# sourceMappingURL=analytics.js.map