小编La *_*ch'的帖子

类型错误:window.gtag 不是函数

我对 GTM 完全感到困惑,我将它实现到我的网站上以触发一些事件来处理流量等...大约 2 天我看到了以下错误:

Error from the trackerPageView =>  TypeError: window.gtag is not a function
    at _app.js:1
    at _app.js:1
    at commons.c57c1be722ad069a7405.js:1
    at Array.map (<anonymous>)
    at Object.emit (commons.c57c1be722ad069a7405.js:1)
    at commons.c57c1be722ad069a7405.js:1
Run Code Online (Sandbox Code Playgroud)

我没有看到任何关于这个问题的文档,所以我发了一篇文章来集中有关这个问题的信息。

我的配置是一个 webApp(nextjs、Reactjs、typeScript、redux),希望这会有所帮助。

_document.tsx:

import Document, { Head, Main, NextScript } from "next/document";
import { GA_TRACKING_ID } from "../lib/gtag";
import { Fragment } from "react";

export default class MyDocument extends Document {
  setGoogleTags() {
    return {
      __html: `
            (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','${GA_TRACKING_ID}');
          `,
    };
  }

  render() { …
Run Code Online (Sandbox Code Playgroud)

typescript google-tag-manager reactjs next.js

9
推荐指数
3
解决办法
3万
查看次数

useEffect 错误:缩小的 React 错误 #321(GTM 实现而不是 google analitycs)

为什么我在next build编译过程中遇到了 Minified React Error #321 ?我惹事了useEffect()吗?

部分错误抛出:

Automatically optimizing pages .(node:763) ExperimentalWarning: The fs.promises API is experimental
(node:762) ExperimentalWarning: The fs.promises API is experimental
(node:761) ExperimentalWarning: The fs.promises API is experimental
Automatically optimizing pages .Error: Minified React error #321; visit https://reactjs.org/docs/error-decoder.html?invariant=321 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
    at Z (/XXX/XXX/XXX/XXX/.next/serverless/pages/index.js:10945:404)
    at module.exports.viRO.exports.useEffect (/XXX/XXX/XXX/XXX/.next/serverless/pages/index.js:10950:356)
    at App (/XXX/XXX/XXX/XXX/.next/serverless/pages/index.js:7133:29)
    at d (/XXX/XXX/XXX/XXX/.next/serverless/pages/index.js:1023:498)
    at $a (/XXX/XXX/XXX/XXX/.next/serverless/pages/index.js:1026:16)
    at a.b.render …
Run Code Online (Sandbox Code Playgroud)

reactjs next.js gtag.js

7
推荐指数
2
解决办法
8199
查看次数