analytics.js事件并非总是发送 [英] analytics.js event not always sent

查看:113
本文介绍了analytics.js事件并非总是发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASPX Web应用程序中实现了analytics.js(新版本). 我的综合浏览量很好,但是事件通常没有发送.

I implemented analytics.js (new version) in my ASPX webapplication. I got pageview working just fine, but events is very often not being send.

在我的示例中,我尝试按下3个不同的按钮,但只有其中一个触发了该事件. 我向每个事件添加了一个警告框,以验证它是否真正被触发了,并且所有这些都显示出来.

In my example, I tried pushing 3 different buttons, but only one of them fired the event. I added an alert-box to each event, to verify that it actually is fired, and these all show.

这是我的js,位于</head>

This is my js, placed just before the </head>

(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-1', {
    'cookieDomain': 'none'
});
ga('send', 'pageview', {
    'page': '/team/main',
    'title': 'Logged in'
});

$(document).ready(function() {
    $(".team_button").on("click", function() {
        ga('send', 'event', 'button', 'click', 'Team select button', {
            'page': '/team/'
        })
    });
    $(".calendar_month_prev").on("click", function() {
        ga('send', 'event', 'button', 'click', 'Calendar: Prev month', {
            'page': '/team/'
        })
    });
    $(".calendar_month_next").on("click", function() {
        ga('send', 'event', 'button', 'click', 'Calendar: Next month', {
            'page': '/team/'
        })
    });
    $(".calendar_day_selected").on("click", function() {
        ga('send', 'event', 'button', 'click', 'Calendar: Same day reload', {
            'page': '/team/'
        })
    });
    $(".calendar_day_active").on("click", function() {
        ga('send', 'event', 'button', 'click', 'Calendar: Select day', {
            'page': '/team/'
        })
    });
});

推荐答案

在加载新页面时,当前页面上的待处理请求被取消-在这种情况下,分析跟踪像素请求. 异步"更多地是指分析javascript代码的加载,而不是分析数据的处理.

When a new page is being loaded, pending requests on the current page are canceled -- in this case the analytics tracking pixel request. 'async' is referring more to the loading of the analytics javascript code then the processing of analytics data.

使用ga.js,一种常见的方法是停止点击事件的传播,发送事件,然后在跟随链接之前延迟一小段时间(150毫秒).

With ga.js, a common approach is to stop propagation of the click event, send the event, and then delay for a small amount (150ms) before following the link.

使用analytics.js,无需延迟,您可以在发送分析数据后使用hitCallback来运行代码. 请参阅Google Analytics(分析)中的设置点击回调文档

With analytics.js, instead of a delay, you can use hitCallback to run code after the analytics data has been sent. See Setting the Hit Callback in the Google Analytics docs

这篇关于analytics.js事件并非总是发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆