1

我正在使用 Legato gem 从 Ruby 中的 Google Analytics 访问某个事件的总数,但我得到的结果与 Web 界面不一致。

我有一个这样的模型:

module Analytics
    class ViewedContent
        extend Legato::Model

        metrics :users, :new_users, :total_events        

        filter :my_org do
            # Look u[ event_label=X AND event_action=Y
            [
                eql(:event_label, "My Organisation", Legato.and_join_character),
                eql(:event_action, 'Viewed_Content', Legato.and_join_character)
            ]
        end
    end
end    

...然后我通过这样做来使用它:

query = Analytics::ViewedContent.my_org.results(profile, {
    :start_date => start_date,
    :end_date => end_date
})

...并查看totalEvents统计数据。

当我在一月份传递日期时,例如start_date = "2014-01-01".to_date然后end_date = "2014-01-31".to_date它工作正常,并将相同数量的返回totalEvents到谷歌分析网络界面。

但是,当我在上个月使用它时,start_date = "2014-07-01".to_dateend_date = "2014-07-31".to_date比在 Web 界面中要少得多(Legato 在 Web 界面中返回 555 与 662)。

It makes me wonder if it's something to do with British Summer Time (I'm currently in UTC+1) except that even extending the date range by a day either side doesn't bring it up to the same as what the web interface reports, which would appear to rule that out.

Any thoughts much appreciated!

4

1 回答 1

1

With a bit of help from Query Explorer I discovered that the problem is definitely at Google's end, rather than due to Legato. The problem was with this line here:

metrics :users, :new_users, :total_events   

If I changed that to just fetch :total_events then suddenly it started returning the same value as the Google Analytics web interface. I now make a separate request for :users and :new_users by looking up a segment (rather than just this filter)

于 2014-08-26T12:58:53.677 回答