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

import { ga4MeasurementId } from "@/lib/env";

/**
 * Google Analytics 4 via `@next/third-parties` (the official Next.js
 * integration). Loads `gtag.js` after hydration and auto-tracks pageviews on
 * history changes, so client-side route navigations are measured too.
 *
 * Renders nothing when `NEXT_PUBLIC_GA4_MEASUREMENT_ID` is unset, so swapping
 * or disabling the GA property is just an env change + redeploy.
 */
export function GoogleAnalyticsTag() {
  if (!ga4MeasurementId) return null;

  return <GoogleAnalytics gaId={ga4MeasurementId} />;
}
