调整谷歌分析中的反弹率。

时间:2023-02-01 13:51:19

I am trying to chance the way a bounce is registered in Google Analytics.

我试着碰运气在谷歌分析中注册的方式。

This is my analytics code:

这是我的分析代码:

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxxxx-1x', 'auto');
ga('send', 'pageview');
</script>

I want to make it so that a bounce only registers if they left the site before 5 seconds elapsed. How could I go about doing this? I know there should be some way to do it with js.

我想让它在5秒之前离开站点的时候才会被弹出。我该怎么做呢?我知道应该用js来做。

Any help would be appreciated.

如有任何帮助,我们将不胜感激。

Thanks!

谢谢!

1 个解决方案

#1


4  

You could send a Custom Event, so as to "ping" Google Analytics and prevent a Bounce from being logged.

您可以发送一个定制的事件,以便“ping”谷歌分析,防止被记录的反弹。

This could be something like:

这可能是:

<script type="text/javascript">
   (function () {
      setTimeout(function () {
         if (typeof window.ga !== 'undefined') {
            ga('send', 'event', 'Bounce Disabling', 'Ping', '5 second timeout');
         }
      }, 5*1000); // 5000ms delay
   })();
</script>

Edit: If you want to record data based on the time elapsed on the page, you could use something like the following.

编辑:如果您想根据页面上的时间来记录数据,您可以使用如下的内容。

Passing the elapsedTime value as the last parameter of the ga() call will allow you to have Metrics like Average Event Value automatically computed -- should that be of any use to you.

将elapsedTime值作为ga()调用的最后一个参数传递,将允许您拥有自动计算的平均事件值之类的指标——这对您有任何用处。

<script type="text/javascript">
    (function () {
        var initTime = new Date().getTime();

        window.addEventListener('beforeunload', function (event) {
            var closeTime = new Date().getTime();
            var elapsedTime = closeTime - initTime; // Time elapsed since page loaded (in ms).

            if (typeof ga !== 'undefined') {
                if (elapsedTime <= 60 * 1000) { // 60 000 ms = 1 min
                    // Page loaded less than 1 minute ago:
                    ga('send', 'event', 'Page View Time', 'Duration', 'Under 1 minute', elapsedTime);
                } else {
                    // Page loaded over 1 minute ago:
                    ga('send', 'event', 'Page View Time', 'Duration', 'Over 1 minute', elapsedTime);
                }
            }
        });
    })();
</script>

#1


4  

You could send a Custom Event, so as to "ping" Google Analytics and prevent a Bounce from being logged.

您可以发送一个定制的事件,以便“ping”谷歌分析,防止被记录的反弹。

This could be something like:

这可能是:

<script type="text/javascript">
   (function () {
      setTimeout(function () {
         if (typeof window.ga !== 'undefined') {
            ga('send', 'event', 'Bounce Disabling', 'Ping', '5 second timeout');
         }
      }, 5*1000); // 5000ms delay
   })();
</script>

Edit: If you want to record data based on the time elapsed on the page, you could use something like the following.

编辑:如果您想根据页面上的时间来记录数据,您可以使用如下的内容。

Passing the elapsedTime value as the last parameter of the ga() call will allow you to have Metrics like Average Event Value automatically computed -- should that be of any use to you.

将elapsedTime值作为ga()调用的最后一个参数传递,将允许您拥有自动计算的平均事件值之类的指标——这对您有任何用处。

<script type="text/javascript">
    (function () {
        var initTime = new Date().getTime();

        window.addEventListener('beforeunload', function (event) {
            var closeTime = new Date().getTime();
            var elapsedTime = closeTime - initTime; // Time elapsed since page loaded (in ms).

            if (typeof ga !== 'undefined') {
                if (elapsedTime <= 60 * 1000) { // 60 000 ms = 1 min
                    // Page loaded less than 1 minute ago:
                    ga('send', 'event', 'Page View Time', 'Duration', 'Under 1 minute', elapsedTime);
                } else {
                    // Page loaded over 1 minute ago:
                    ga('send', 'event', 'Page View Time', 'Duration', 'Over 1 minute', elapsedTime);
                }
            }
        });
    })();
</script>