import crypto from "crypto";
import { useCallback } from "react";
const placeholder = () => console.error(new Error("gtag not found"));
export const gtagTracking = () => {
    return globalThis.gtag ?? placeholder;
};
export const useGtag = () => {
    const gtag = gtagTracking();
    const track = useCallback((trackType, eventName, options) => gtag(trackType, eventName, options), [gtag]);
    const trackEvent = useCallback((eventName, options) => {
        // @ts-ignore
        return track("event", eventName, options);
    }, [track]);
    return { track, trackEvent };
};
export const useGtagTracking = () => {
    const gtag = gtagTracking();
    const trackEvent = useCallback(gtag, [gtag]);
    return trackEvent;
};
export const useGtagTrackUser = () => {
    const gtag = gtagTracking();
    const trackUser = useCallback((name) => {
        const hash = crypto.createHash("sha256").update(name).digest("hex");
        gtag("set", {
            user_id: hash,
        });
    }, [gtag]);
    return trackUser;
};
export const useGtagConfig = ( /* TODO config in args */) => {
    const gtag = gtagTracking();
    const trackConfig = useCallback(() => {
        gtag("config", "UA-136203948-1", {
            custom_map: {
                dimension1: "user_id",
                dimension2: "clientId",
                dimension4: "sessionId",
            },
            linker: {
                domains: [
                    "eosdt.com",
                    "blog.eosdt.com",
                    "equilibrium.io",
                    "knowledgebase.equilibrium.io",
                    "dsp.equilibrium.io",
                    "eos2dt.com",
                    "genshiro.equilibrium.io",
                ],
                accept_incoming: true,
            },
        });
    }, []);
    return trackConfig;
};
export const getAmplitudeClient = () => {
    const client = globalThis.amplitude?.getInstance?.();
    if (!client) {
        console.error(new Error("amplitude not found"));
        return;
    }
    return client;
};
export const useAmplitude = () => {
    const logEvent = useCallback((...args) => {
        const client = getAmplitudeClient();
        if (!client)
            return;
        return client.logEvent(...args);
    }, []);
    return { logEvent };
};
//# sourceMappingURL=tracking.js.map