Created
January 17, 2012 07:11
-
-
Save pdxmph/1625380 to your computer and use it in GitHub Desktop.
Super-Quick Sinatra "Get the views from GA" server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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