[英]Can't disable Google Analytics page_view events
After setting send_page_view: false
, google analytics still keeps sending automatic page_view
events, even tho I tried to do that manually设置
send_page_view: false
后,谷歌分析仍然继续发送自动page_view
事件,即使我尝试手动执行此操作
<!-- Global site tag (gtag.js) - Google Analytics -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-*********"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "G-*********", {
send_page_view: false,
});
</script>
withTracker.jsx withTracker.jsx
export default (WrappedComponent) => {
const trackPage = (page) => {
if (page) {
window.gtag("event", "page_view", {
page_path: page.location.pathname,
page_title: getTitleFromPathname(page.location.pathname),
});
}
};
const HOC = (props) => {
useEffect(() => trackPage(props), [props.location]);
return <WrappedComponent {...props} />;
};
return HOC;
};
Route example:路线示例:
<Route path="/404" component={withTracker(NotFound404)} />
After setting send_page_view: false
, google analytics still keeps sending automatic page_view
events, even tho I tried to do that manually设置
send_page_view: false
,谷歌分析仍然不断发送自动page_view
事件,即使我试图手动执行
<!-- Global site tag (gtag.js) - Google Analytics -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-*********"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "G-*********", {
send_page_view: false,
});
</script>
withTracker.jsx withTracker.jsx
export default (WrappedComponent) => {
const trackPage = (page) => {
if (page) {
window.gtag("event", "page_view", {
page_path: page.location.pathname,
page_title: getTitleFromPathname(page.location.pathname),
});
}
};
const HOC = (props) => {
useEffect(() => trackPage(props), [props.location]);
return <WrappedComponent {...props} />;
};
return HOC;
};
Route example:路线示例:
<Route path="/404" component={withTracker(NotFound404)} />
This is not the case for me using Google Analytics 4 release 2022.08.05 .使用 Google Analytics 4 release 2022.08.05对我来说并非如此。
You can install Google Analytics Debugger and add debug_mode: true
to gtag('config')
params to see in the console what exactly happens.您可以安装Google Analytics Debugger并将
debug_mode: true
添加到gtag('config')
参数,以在控制台中查看究竟发生了什么。
I didn't need to do this but it's also recommended to turn off history event tracking in Enhanced Measurement settings.我不需要这样做,但也建议在增强测量设置中关闭历史事件跟踪。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.