andrew (owner)

Revisions

gist: 101606 Download_button fork
public
Public Clone URL: git://gist.github.com/101606.git
Embed All Files: show embed
last_months_hits.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'rubygems'
require 'garb' # http://github.com/vigetlabs/garb/
require 'sparklines' # http://github.com/topfunky/sparklines
 
Garb::Session.login('analytics@email.com', 'password')
 
site = Garb::Profile.all.first
 
days = []
length = 86400
 
puts "Generating graph of hits on #{site.title} homepage over last month"
 
30.times do |day|
  r = Garb::Report.new(site)
  
  r.metrics << :pageviews
  r.dimensions << :request_uri
  r.filters << {:request_uri.eql => '/'}
  r.start_date = Time.now - (length*day)
  r.end_date = Time.now - (length*(day-1))
    
  days << r.all.first.pageviews.to_i
end
 
graph = Sparklines.plot(days, :type => 'smooth', :height => 20, :step => 1, :line_color => '#0080FF')
 
graph_file = File.new("graph.jpg", "w")
graph_file.write(graph)
graph_file.close