Google Analytics(分析) - 发送自定义维度,但有些缺失

时间:2015-02-15 11:13:28

标签: jquery google-analytics

我尝试在GA中记录自定义会话ID,以及在会话中访问页面的序列号(因此用户访问的第一页获得1,第二页获得2,等等)。这是我的代码:

jQuery(document).ready( function($) {
function genGuid(){
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
        return v.toString(16);
        });
}

if (typeof $.cookie('optltcs_session') == 'undefined'){
    var guid = genGuid();
    var date = new Date();
    date.setTime(date.getTime() + (30 * 60 * 1000));
    $.cookie('optltcs_session', guid, {path: '/', expires: date});
    $.cookie('optltcs_viewed', 0, {path: '/'});
}
else{
    if (typeof $.cookie('optltcs_viewed') == 'undefined'){
        $.cookie('optltcs_viewed', 0, {path: '/'});
    }
    else{
        old = $.cookie('optltcs_viewed', Number);
        $.cookie('optltcs_viewed', old+1, {path: '/'});
    }
}
ga('set', 'dimension1', $.cookie('optltcs_session'));
ga('set', 'dimension4', $.cookie('optltcs_viewed'));
ga('send', 'event', 'PIDSID', 'send', {'nonInteraction': 1});
})

它的工作除了一些'尺寸4'缺少变量 - 在会话中我可以看到页面视图号。 0,然后没有。缺少6和1-5。可能是什么原因?我如何调试它(浏览器上的本地调试器显示这工作正常)?

1 个答案:

答案 0 :(得分:0)

事实证明,GA引擎将使用在会话上下文中发送的新维度4覆盖旧维度4。

我的解决方案是只将会话ID发送给GA,并将页面id-s(dimension4)发送到我自己的服务器,这样我以后可以加入这两个数据集来获得完整的图片。