Javascript Google tag manager在路由更改后未发送分析请求

Javascript Google tag manager在路由更改后未发送分析请求,javascript,reactjs,google-analytics,google-tag-manager,Javascript,Reactjs,Google Analytics,Google Tag Manager,我正在尝试在react应用程序中实现google标签管理器。它可以在页面重新加载时工作,但当我通过路由在应用程序之间移动时,它不会在google analytics中注册页面视图 我尝试了react gtm模块,但它也在重新加载,而不是改变路线 index.html 在head标签中添加以下代码 <!-- Google Tag Manager --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.st

我正在尝试在react应用程序中实现google标签管理器。它可以在页面重新加载时工作,但当我通过路由在应用程序之间移动时,它不会在google analytics中注册页面视图

我尝试了
react gtm模块
,但它也在重新加载,而不是改变路线

index.html
head
标签中添加以下代码

<!-- Google Tag Manager -->
<script>(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','GTM-XXXX');</script>
<!-- End Google Tag Manager -->
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
在我的组件
componentDidMount
中,我正在
dataLayer

dataLayer.push({
    event: 'Pageview',
    pagePath: 'page-path-here',
    pageTitle: 'page-title-here',
});
我已经创建了
pagePath
pageTitle
数据层变量,并将它们分配给Google analytics标签。我还创建了一个自定义触发器
PageView
,并将其添加到Google analytics标签中的触发器中

数据层变量

自定义触发器

将数据层变量分配给Analytics标签

谁能给我指一下正确的方向吗

编辑: 详细数据层变量视图

首次加载(重新加载)

路线变更

加载页面时,您在
index.html
中编写的代码只运行一次如果您想在页面更改中注册事件,您需要在要触发的路由上触发相同的事件,您可以从
窗口访问
数据层
变量

window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
    event: 'Pageview',
    pagePath: 'page-path-here',
    pageTitle: 'page-title-here',
});


现在我可以在Google Analytics中看到关于路线更改的页面视图。

设置似乎是正确的,尽管文章中没有详细的变量设置。您在GTM调试视图中看到了什么?你看到了吗?变量的值是什么?触发了什么标记?@kgrg我可以看到事件在第一次加载时被发送进来。路由更改未触发pageView触发器。我是否需要在进入数据层后执行任何操作,比如调用任何tagmanager函数?