Ruby on rails 用ruby发送google分析事件
我用ruby编写了以下google analytics实时代码:Ruby on rails 用ruby发送google分析事件,ruby-on-rails,ruby,google-analytics,Ruby On Rails,Ruby,Google Analytics,我用ruby编写了以下google analytics实时代码: # Execute the query sa_visitCount = client.execute(:api_method => analytics.data.realtime.get, :parameters => { 'ids' => "ga:" + saprofileID, 'metrics' => "ga:activeVisitors", }) 接着是: send\u事件('sa
# Execute the query
sa_visitCount = client.execute(:api_method => analytics.data.realtime.get, :parameters => {
'ids' => "ga:" + saprofileID,
'metrics' => "ga:activeVisitors",
})
接着是:
send\u事件('sa\u realtimevisitors',当前:sa\u visitCount.data.rows)
这非常有效,并返回一个活动访问者计数。
现在,我正试图改变这一点,以返回我在google analytics上创建的事件。下面是这次活动的情况。您可以在“实时和事件”下找到这一点。我试图使用屏幕截图中列为#2的事件类别“广告”。
我在ruby中尝试使用的代码如下
phonehub_visitCount = client.execute(:api_method => analytics.data.realtime.get, :parameters => {
'ids' => "ga:" + saprofileID,
'metrics' => "ga:sessionsWithEvent",
})
接着是:
send_event('phonehub_event', current: phonehub_visitCount.data.rows)
这不会返回任何结果。我仍然使用原始的GA ID,但是我试图告诉它查看我创建的事件。ruby中有没有办法让GA实时返回事件的结果?理想情况下,我正在寻找的解决方案是返回我举办的活动的实时活跃访客 进一步研究后,我发现我必须在api方法中指定v3 因此,不要使用
phonehub\u visitCount=client.execute(:api\u method=>analytics.data.realtime.get,:parameters=>{
我不得不使用
api\u method=client.discovered\u api('analytics','v3').data.ga.get
然后加上
phonehub\u visitCount=client.execute(:api\u method=>api\u method,:parameters=>{