rubygoogle-analyticslegato

Legato totalEvents different from web interface


I'm using the Legato gem to access the total number of a certain event from Google Analytics in Ruby, but I'm getting inconsistent results with the web interface.

I have a model like so:

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    

...then I use this by doing:

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

...and looking at the totalEvents stat.

When I pass in dates in January, e.g. start_date = "2014-01-01".to_date and end_date = "2014-01-31".to_date then it works fine, and returns the identical number of totalEvents to the Google Analytics web interface.

However, when I use it in for last month, start_date = "2014-07-01".to_date and end_date = "2014-07-31".to_date then it's considerably less than in the web interface (Legato returns 555 vs 662 in the web interface).

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!


Solution

  • 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)