Javascript 使用测量协议时Google Analytics屏幕时间不正确

Javascript 使用测量协议时Google Analytics屏幕时间不正确,javascript,google-analytics,Javascript,Google Analytics,我使用Tizen TV应用程序的测量协议,因为我不能使用JS(需要域名)或Android/iOS SDK 我正在发送 { v: 1, tid: GA_TRACKING_ID, cid: data.deviceId, t: 'screenview', dh: 'something.com', dp: encodeURIComponent($location.path()), cd: tr

我使用Tizen TV应用程序的测量协议,因为我不能使用JS(需要域名)或Android/iOS SDK

我正在发送

{
        v: 1,
        tid: GA_TRACKING_ID,
        cid: data.deviceId,
        t: 'screenview',
        dh: 'something.com',
        dp: encodeURIComponent($location.path()),
        cd: transition.to().title + ($stateParams.gaTitle ? ' (' + $stateParams.gaTitle + ')' : '') || 'Unknown',
        an: 'XXX',
        'ga:mobileDeviceModel': data.deviceModel
}
到<代码>https://www.google-analytics.com/collect


但屏幕时间似乎总是在几秒钟内,例如30秒等。我测试了很长时间停留在页面上,但它似乎没有正确反映。我猜这是因为我只发送了一次点击,谷歌无法知道它何时停止?有办法解决这个问题吗

Google Analytics的会话计算基于用户的交互。如果用户单击,会话将获得心跳信号。如果用户正在观看电影(例如电视),它将不会与您的应用程序进行交互,会话将停止

请看这一页
首先,您需要决定会话超时(Admin->property->tracking.js) 默认值为30分钟意味着您需要以低于30分钟的间隔生成点击,以防止新会话中出现新的点击

然后,您需要确保点击次数足够频繁,并包括其当前页面/屏幕名称,例如:

{ // start video
        v: 1,
        tid: GA_TRACKING_ID,
        cid: data.deviceId,
        t: 'screenview',
        dh: 'something.com',
        dp: encodeURIComponent($location.path()),
        cd: transition.to().title + ($stateParams.gaTitle ? ' (' + $stateParams.gaTitle + ')' : '') || 'Unknown',
        an: 'XXX',
        'ga:mobileDeviceModel': data.deviceModel
}
{ // < 30 minutes later
        v: 1,
        tid: GA_TRACKING_ID,
        cid: data.deviceId,
        t: 'event',
        ec: 'Inactivity',
        ea: 'Watching Video',
        el: ..video name..,
        ev: 28,
        ni: 0,  // count as interaction, ni=1 are ignored in time calculations 
        dh: 'something.com',
        dp: encodeURIComponent($location.path()),
        cd: transition.to().title + ($stateParams.gaTitle ? ' (' + $stateParams.gaTitle + ')' : '') || 'Unknown',
        an: 'XXX',
        'ga:mobileDeviceModel': data.deviceModel
}
{  // user does something (can wait 30 minutes more before a new ni event)
        v: 1,
        tid: GA_TRACKING_ID,
        cid: data.deviceId,
        t: 'event',
        ec: 'Activity',
        ea: 'Volume Adjustment Down',
        el: ..video name..,
        ev: 5,
        ni: 0,
        dh: 'something.com',
        dp: encodeURIComponent($location.path()),
        cd: transition.to().title + ($stateParams.gaTitle ? ' (' + $stateParams.gaTitle + ')' : '') || 'Unknown',
        an: 'XXX',
        'ga:mobileDeviceModel': data.deviceModel
}
{  // user goes to new screen (also calculated as the end of screen time)
        v: 1,
        tid: GA_TRACKING_ID,
        cid: data.deviceId,
        t: 'screenview',
        dh: 'something.com',
        dp: encodeURIComponent($location.path()),
        cd: 'somewhere else',
        an: 'XXX',
        'ga:mobileDeviceModel': data.deviceModel
}
{//启动视频
五:一,,
tid:GA_跟踪ID,
cid:data.deviceId,
t:‘屏幕视图’,
卫生署:"something.com",,
dp:encodeURIComponent($location.path()),
cd:transition.to().title+($stateParams.gaTitle?'(“+$stateParams.gaTitle+”):“”)| |“未知”,
安:“XXX”,
'ga:mobileDeviceModel':data.deviceModel
}
{//<30分钟后
五:一,,
tid:GA_跟踪ID,
cid:data.deviceId,
t:‘事件’,
欧共体:“不活动”,
ea:‘看视频’,
el:…视频名称。。,
ev:28,
ni:0,//计算为交互,在时间计算中忽略ni=1
卫生署:"something.com",,
dp:encodeURIComponent($location.path()),
cd:transition.to().title+($stateParams.gaTitle?'(“+$stateParams.gaTitle+”):“”)| |“未知”,
安:“XXX”,
'ga:mobileDeviceModel':data.deviceModel
}
{//用户执行某些操作(可以在新ni事件之前再等待30分钟)
五:一,,
tid:GA_跟踪ID,
cid:data.deviceId,
t:‘事件’,
欧共体:“活动”,
ea:‘音量调整下降’,
el:…视频名称。。,
ev:5,
倪:0,,
卫生署:"something.com",,
dp:encodeURIComponent($location.path()),
cd:transition.to().title+($stateParams.gaTitle?'(“+$stateParams.gaTitle+”):“”)| |“未知”,
安:“XXX”,
'ga:mobileDeviceModel':data.deviceModel
}
{//用户转到新屏幕(也计算为屏幕结束时间)
五:一,,
tid:GA_跟踪ID,
cid:data.deviceId,
t:‘屏幕视图’,
卫生署:"something.com",,
dp:encodeURIComponent($location.path()),
cd:“其他地方”,
安:“XXX”,
'ga:mobileDeviceModel':data.deviceModel
}

如果您能够发送所有退出事件,那么您可能希望在退出(或每4小时一次)时使用,以便在该时段的所有数据都已输入后,计算会话。

您是否可以进一步了解您面临的问题,例如如何发送以及您希望返回什么(采用哪种方法)。更多相关代码可能会有所帮助。更新了我的OP。但基本上我正在对
API进行调用https://www.google-analytics.com/collect
太棒了,我明天会试试这个。但我有一个问题。难道我不应该至少有30分钟的平均会话时间吗?为什么我的会话时间这么短?@JiewMeng你的会话时间是从第一次命中到最后一次命中,任何30分钟的间隔都会中断会话,因此如果你导航2分钟,然后在某个地方停留40分钟,然后去其他地方,你会有一次几次命中的会话,两分钟,一次38分钟后,命中1次,0秒。但是,如果您希望会话显示为“停留”在同一屏幕/页面上,同时生成其他命中类型,则还必须小心保持cd/dp/dh参数不变。@JiewMeng您也可以在命中生成器上以任何方式进行测试,如果您使用“qt”,则可以创建用户4小时的虚拟会话一次完成一个cid,然后在报告->受众->用户资源管理器中查看它们。