ReferenceError:未定义dataLayer

时间:2019-05-23 13:06:23

标签: google-analytics

因此,我正在尝试使用提供的代码来设置Google Analytics(分析):

  <Head>
    <script async src="https://www.googletagmanager.com/gtag/js?id=my-id"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'my-id');
    </script>
  </Head>

但正在接​​收上述错误消息。我在这里俯瞰什么?

生成的堆栈跟踪如下:

Uncaught ReferenceError: dataLayer is not defined
    at Meta (VM79 _app.js.eb2961df9cc079665d85.hot-update.js:24)
    at renderWithHooks (VM47 react-dom.development.js:12938)
    at mountIndeterminateComponent (VM47 react-dom.development.js:15020)
    at beginWork (VM47 react-dom.development.js:15625)
    at performUnitOfWork (VM47 react-dom.development.js:19312)
    at workLoop (VM47 react-dom.development.js:19352)
    at HTMLUnknownElement.callCallback (VM47 react-dom.development.js:149)
    at Object.invokeGuardedCallbackDev (VM47 react-dom.development.js:199)
    at invokeGuardedCallback (VM47 react-dom.development.js:256)
    at replayUnitOfWork (VM47 react-dom.development.js:18578)
    at renderRoot (VM47 react-dom.development.js:19468)
    at performWorkOnRoot (VM47 react-dom.development.js:20342)
    at performWork (VM47 react-dom.development.js:20254)
    at performSyncWork (VM47 react-dom.development.js:20228)
    at requestWork (VM47 react-dom.development.js:20097)
    at scheduleWork (VM47 react-dom.development.js:19911)
    at scheduleRootUpdate (VM47 react-dom.development.js:20572)
    at updateContainerAtExpirationTime (VM47 react-dom.development.js:20600)
    at updateContainer (VM47 react-dom.development.js:20657)
    at ReactRoot.render (VM47 react-dom.development.js:20953)
    at legacyRenderSubtreeIntoContainer (VM47 react-dom.development.js:21105)
    at Object.render (VM47 react-dom.development.js:21155)
    at renderReactElement (VM39 main.js:8591)
    at _temp11 (VM39 main.js:8275)
    at doRender (VM39 main.js:8316)
    at VM39 main.js:8374
    at _catch (VM39 main.js:8239)
    at _temp6 (VM39 main.js:8373)
    at render (VM39 main.js:8392)
    at VM39 main.js:8534
    at VM39 main.js:5985
    at Set.forEach (<anonymous>)
    at Set.<anonymous> (VM39 main.js:1675)
    at Router.notify (VM39 main.js:5984)
    at Router.update (VM39 main.js:5489)
    at VM36 _app.js:53429
    at hotApply (VM37 webpack.js:681)
    at VM37 webpack.js:363

0 个答案:

没有答案