Skip to content

Instantly share code, notes, and snippets.

@pdxmph
Created January 17, 2012 07:11
Show Gist options
  • Save pdxmph/1625380 to your computer and use it in GitHub Desktop.
Save pdxmph/1625380 to your computer and use it in GitHub Desktop.
Super-Quick Sinatra "Get the views from GA" server
require "rubygems"
require "sinatra"
require "garb"
require "active_support/all"
Garb::Session.login(google_user, google_password)
$profiles = Garb::Management::Profile.all
$profile = $profiles.detect {|p| p.id == "7294335" }
class PostStats
extend Garb::Model
metrics :pageviews
dimensions :page_path
end
post '/pageviews' do
@pub_date = Date.parse(params[:pub_date])
@post_id = params[:id]
views_report = PostStats.results($profile,
:start_date => @pub_date,
:end_date => @pub_date + 7.days,
:filters => {:page_path.contains => "/#{@post_id}/",
:sort => :pageviews.descending}
)
views_report.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment