import { withQuery } from "ufo";
import { useRegistryScript } from "#nuxt-scripts-utils";
import { object, string } from "#nuxt-scripts-validator";
export const GoogleAnalyticsOptions = object({ id: string() });
export function useScriptGoogleAnalytics(_options) {
  return useRegistryScript(_options?.key || "google-analytics", (options) => ({
    scriptInput: {
      src: withQuery("https://www.googletagmanager.com/gtag/js", { id: options?.id })
    },
    schema: import.meta.dev ? void 0 : GoogleAnalyticsOptions,
    scriptOptions: {
      use: () => {
        return { dataLayer: window.dataLayer, gtag: window.gtag };
      },
      stub: import.meta.client ? void 0 : ({ fn }) => {
        return fn === "dataLayer" ? [] : void 0;
      },
      performanceMarkFeature: "nuxt-third-parties-ga",
      ...{ tagPriority: 1 }
    },
    // eslint-disable-next-line
    clientInit: import.meta.server ? void 0 : () => {
      window.dataLayer = window.dataLayer || [];
      window.gtag = function gtag() {
        window.dataLayer.push(arguments);
      };
      window.gtag("js", /* @__PURE__ */ new Date());
      window.gtag("config", options.id);
    }
  }), _options);
}
