我想在谷歌分析中将页面时间的抽样率从1%提高到10%。
我们使用全局站点标记(gtag.js)将GA添加到我们的站点。
以下是当前配置:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-123456-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-123456-1');
</script>根据文档,以下内容将捕获用户加载时间,但不会增加采样率。
// Feature detects Navigation Timing API support.
if (window.performance) {
// Gets the number of milliseconds since page load
// (and rounds the result since the value must be an integer).
var timeSincePageLoad = Math.round(performance.now());
// Sends the timing event to Google Analytics.
gtag('event', 'timing_complete', {
'name': 'load',
'value': timeSincePageLoad,
'event_category': 'JS Dependencies'
});
}发布于 2022-02-14 13:55:13
这是通过设置gtag('config','UA-XXXX-X',{‘site_speed_sample’:100})来解决的。
https://stackoverflow.com/questions/68994494
复制相似问题