Skip to content

Instantly share code, notes, and snippets.

@pdxmph
Created June 16, 2011 21:43
Show Gist options
  • Save pdxmph/1030367 to your computer and use it in GitHub Desktop.
Save pdxmph/1030367 to your computer and use it in GitHub Desktop.
Basic Mobile Report
#!/usr/bin/env ruby -W0
require "rubygems"
require "garb"
sd = Date.parse("2011-05-01")
ed = Date.parse("2011-05-30")
config = YAML.load(File.open('smt_config.yml'))
sites = config["sites"]
google_user = config["ga"]["user"]
google_password = config["ga"]["pass"]
Garb::Session.login(google_user, google_password)
@profiles = Garb::Management::Profile.all
class MobileMetrics
extend Garb::Model
metrics :pageviews
dimensions :operating_system, :is_mobile
end
class MobileFavorites
extend Garb::Model
metrics :pageviews
dimensions :operating_system, :is_mobile, :page_title
end
sites.each do |s|
profile = @profiles.detect {|p| p.id == s[1]['GA'] }
puts s[0]
MobileMetrics.results(profile, :start_date => sd, :end_date => ed).each do |r|
next unless r.is_mobile == "Yes"
puts "\t#{r.operating_system} : #{r.pageviews}"
end
favorite_results = MobileFavorites.results(profile,
:start_date => sd,
:end_date => ed,
:limit => 20,
:sort => :pageviews.desc,
:filters => {:is_mobile.eql => "Yes", :operating_system.eql => "BlackBerry"}
)
puts "\n\tTop BlackBerry Stories for #{s[0]}:\r\r"
favorite_results.each do |r|
puts "\t#{r.page_title.gsub(/\ \|.+$/,"")} : #{r.pageviews}"
end
puts "\r\r\r"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment