import { readAnalyticsConsent } from "./cookie-consent-storage";

type MatomoWindow = Window &
  typeof globalThis & {
    _paq?: unknown[][];
  };

export const trackEvent = (category: string, action: string, name?: string): void => {
  if (readAnalyticsConsent() !== "analytics-accepted") return;
  const matomoWindow = window as MatomoWindow;
  matomoWindow._paq = matomoWindow._paq ?? [];
  matomoWindow._paq.push(["trackEvent", category, action, name ?? ""]);
};
