import { sendGAEvent } from "@next/third-parties/google";

const IS_PROD = process.env.NODE_ENV === "production";

export function trackEvent(
  action: string,
  params?: Record<string, string>
) {
  if (typeof window === "undefined") return;
  // Skip tracking in dev — keeps prod stats clean and silences 401s on self-hosted
  // analytics endpoint (allowlist contient seulement aciebenergie.fr en prod).
  if (!IS_PROD) return;
  // GA4
  sendGAEvent("event", action, params ?? {});
  // OpenPanel (self-hosted)
  window.op?.track(action, params ?? {});
}
