【问题标题】:Setting setSiteSpeedSampleRate in gtag.js在 gtag.js 中设置 setSiteSpeedSampleRate
【发布时间】:2021-08-31 07:25:36
【问题描述】:

我想在谷歌分析中将页面计时的采样率从 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>

根据doc,以下将捕获用户加载时间,但不会增加采样率。

// 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'
  });
}

【问题讨论】:

    标签: google-analytics universal-analytics gtag.js


    【解决方案1】:

    通过设置 gtag('config', 'UA-XXXX-X',{'site_speed_sample_rate': 100}) 解决了这个问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多