Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# connection and profile selection skipped
class Pageview
extend Legato::Model
metrics :pageviews
dimensions :pagePath, :date
filter :for_path, &lambda { |path| contains(:pagePath, path) }
end
start = DateTime.now.prev_month
today = DateTime.now
path = '/support.html'
puts profile.pageview(start_date: start, end_date: today, sort: 'date').for_path(path).to_a
#<OpenStruct pagePath="/support.html", date="20140303", pageviews="17">
#<OpenStruct pagePath="/support.html", date="20140304", pageviews="8">
#<OpenStruct pagePath="/support.html", date="20140305", pageviews="11">
#<OpenStruct pagePath="/support.html", date="20140306", pageviews="5">
#<OpenStruct pagePath="/support.html", date="20140307", pageviews="11">
#<OpenStruct pagePath="/support.html", date="20140308", pageviews="9">
#<OpenStruct pagePath="/support.html", date="20140309", pageviews="3">
#<OpenStruct pagePath="/support.html", date="20140310", pageviews="12">
#<OpenStruct pagePath="/support.html", date="20140311", pageviews="10">
#<OpenStruct pagePath="/support.html", date="20140312", pageviews="8">
#<OpenStruct pagePath="/support.html", date="20140313", pageviews="7">
#<OpenStruct pagePath="/support.html", date="20140314", pageviews="5">
#<OpenStruct pagePath="/support.html", date="20140315", pageviews="3">
#<OpenStruct pagePath="/support.html", date="20140316", pageviews="2">
#<OpenStruct pagePath="/support.html", date="20140317", pageviews="8">
#<OpenStruct pagePath="/support.html", date="20140318", pageviews="13">
#<OpenStruct pagePath="/support.html", date="20140319", pageviews="10">
#<OpenStruct pagePath="/support.html", date="20140320", pageviews="9">
#<OpenStruct pagePath="/support.html", date="20140321", pageviews="6">
#<OpenStruct pagePath="/support.html", date="20140322", pageviews="9">
#<OpenStruct pagePath="/support.html", date="20140323", pageviews="4">
#<OpenStruct pagePath="/support.html", date="20140324", pageviews="16">
#<OpenStruct pagePath="/support.html", date="20140325", pageviews="10">
#<OpenStruct pagePath="/support.html", date="20140326", pageviews="11">
#<OpenStruct pagePath="/support.html", date="20140327", pageviews="8">
#<OpenStruct pagePath="/support.html", date="20140328", pageviews="6">
#<OpenStruct pagePath="/support.html", date="20140329", pageviews="4">
#<OpenStruct pagePath="/support.html", date="20140330", pageviews="6">
#<OpenStruct pagePath="/support.html", date="20140331", pageviews="6">
#<OpenStruct pagePath="/support.html", date="20140401", pageviews="20">
#<OpenStruct pagePath="/support.html", date="20140402", pageviews="9">
#<OpenStruct pagePath="/support.html", date="20140403", pageviews="5">
{
"totalResults":32,
"columnHeaders":
[{"name":"ga:pagePath"},{"name":"ga:date"},{"name":"ga:pageviews"}],
"totalsForAllResults":{"ga:pageviews":"271"},
"rows":[
["/support.html","20140303","17"],
["/support.html","20140304","8"],
["/support.html","20140305","11"],
["/support.html","20140306","5"],
["/support.html","20140307","11"],
["/support.html","20140308","9"],
["/support.html","20140309","3"],
["/support.html","20140310","12"],
["/support.html","20140311","10"],
["/support.html","20140312","8"],
["/support.html","20140313","7"],
["/support.html","20140314","5"],
["/support.html","20140315","3"],
["/support.html","20140316","2"],
["/support.html","20140317","8"],
["/support.html","20140318","13"],
["/support.html","20140319","10"],
["/support.html","20140320","9"],
["/support.html","20140321","6"],
["/support.html","20140322","9"],
["/support.html","20140323","4"],
["/support.html","20140324","16"],
["/support.html","20140325","10"],
["/support.html","20140326","11"],
["/support.html","20140327","8"],
["/support.html","20140328","6"],
["/support.html","20140329","4"],
["/support.html","20140330","6"],
["/support.html","20140331","6"],
["/support.html","20140401","20"],
["/support.html","20140402","9"],
["/support.html","20140403","5"]
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.