如何在 gatsby 中使用谷歌标签管理器

Coh*_*ent 5 google-tag-manager reactjs gatsby

我正在使用 gatsby 和 gatsby-plugin-tag-manager,但无法触发自定义事件。我的 gatsby-config.js 看起来像这样:

    {
      resolve: `gatsby-plugin-google-tagmanager`,
      options: {
        id: 'GTM-XXXXXXX',
        includeInDevelopment: true,
        defaultDataLayer: function() {
          return {
            pageType: window.pageType,
            // platform: 'gatsby',
          }
        },
      },
Run Code Online (Sandbox Code Playgroud)

当我在本地运行所有内容时,我可以使用以下代码正确触发我的事件:

window.dataLayer.push({
  event: 'gatsby-course-splash-sign-up',
})
Run Code Online (Sandbox Code Playgroud)

问题是,当我将其静态部署到 s3 存储桶而不是在服务器上运行时,当页面视图触发时,其他任何事情都没有。有谁知道如何让自定义触发器工作?谢谢!