import { getLocationParams } from "@/utils";



export default function () {
  // 获取链接参数
  const p = getLocationParams();
  // 如果没有像素id不生成
  if (!p.tagId) {
    return
  }
  let script = document.createElement("script");
  script.id = "google-script";
  script.type = "text/javascript";
  script.async = true;
  script.src = `https://www.googletagmanager.com/gtag/js?id=${p.tagId}`
  document.getElementsByTagName("head")[0].appendChild(script);


  let script2 = document.createElement("script");
  script2.innerHTML = `
      window.dataLayer = window.dataLayer || [];
      function gtag() {
        dataLayer.push(arguments);
      }
      gtag("js", new Date());

      gtag("config", ${p.tagId});
  `
  document.getElementsByTagName("body")[0].appendChild(script2); 
}  