// @bun
// src/libs/posthog/client.ts
import posthog from "posthog-js";
var analyticsEventNames = {
  CTA_INSTALL_CLICK: "cta_install_click",
  CTA_STUDIO_CLICK: "cta_studio_click",
  DOCS_QUICKSTART_VIEW: "docs_quickstart_view",
  COPY_COMMAND_CLICK: "copy_command_click",
  EXAMPLE_REPO_OPEN: "example_repo_open"
};
var posthogKey = process.env.NEXT_PUBLIC_CONTRACTSPEC_POSTHOG_KEY;
var posthogHost = process.env.NEXT_PUBLIC_POSTHOG_HOST || "https://eu.posthog.com";
var shouldCaptureAnalytics = () => {
  if (typeof window === "undefined")
    return false;
  const nav = window.navigator;
  const dntWindow = window;
  const dnt = nav.doNotTrack ?? nav.msDoNotTrack ?? dntWindow.doNotTrack;
  return dnt !== "1" && dnt !== "yes";
};
function initPosthog() {
  if (typeof window === "undefined")
    return;
  if (!posthogKey) {
    console.warn("[PostHog] NEXT_PUBLIC_CONTRACTSPEC_POSTHOG_KEY is missing");
    return;
  }
  if (!shouldCaptureAnalytics())
    return;
  const isDev = false;
  posthog.init(posthogKey, {
    api_host: posthogHost,
    autocapture: !isDev,
    capture_dead_clicks: !isDev,
    capture_performance: !isDev,
    capture_pageview: !isDev,
    capture_heatmaps: !isDev,
    capture_exceptions: !isDev,
    debug: false
  });
}
function captureAnalyticsEvent(event, properties) {
  if (!posthogKey)
    return;
  if (!shouldCaptureAnalytics())
    return;
  try {
    const globalPosthog = globalThis.posthog;
    const instance = globalPosthog ?? posthog;
    instance?.capture?.(event, properties);
  } catch {
    return;
  }
}
var client_default = posthog;
export {
  posthogKey,
  posthogHost,
  posthog,
  initPosthog,
  client_default as default,
  captureAnalyticsEvent,
  analyticsEventNames
};
