import legacy from "@vitejs/plugin-legacy";

export default {
  plugins: [
    legacy({
      targets: ["defaults", "not IE 11"],
    }),
    {
      name: "google-tag-manager",
      transformIndexHtml() {
        if (process.env.TRACKEAR_A_LXS_USUARIXS) {
          const id = process.env.TRACKEAR_A_LXS_USUARIXS;
          return [
            {
              tag: "script",
              attrs: {
                src: "https://www.googletagmanager.com/gtag/js?id=" + id,
                async: true,
              },
            },
            {
              tag: "script",
              children: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${id}');`,
            },
          ];
        } else return [];
      },
    },
  ],
};
