Development, Tools

Google Analytics – visits for all visitors – comparison Ruby script

Hi. I stole this GA Visits for all visitors ruby script from our CTO. Hope you find it useful. It requires installed Ruby.

It displays

  • visits for all visitors
  • hourly view
  • yesterday – compared to – day before
  • current day – compared to – day before
  • side-by-side

Visits for all visitors - Google Analytics ruby script

Note: screenshot does not display Tupalo.com data, but data from another experimental domain.

here is the code, all you need to do is to paste your profile-id into it. (the stuff after &id= highlighted in yellow).

#!/usr/bin/ruby -wKU

class Fixnum
def day(v=self); v * 24 * 3600; end
def week(v=self); v * 7.day; end
end

def google_analytics_visitors_compared_to_last_week_url(time = Time.now)
date_now = time.strftime("%Y%m%d")
date_last_week = (time - 1.week).strftime("%Y%m%d")
"https://www.google.com/analytics/reporting/visits?id=your id here&seg0=-1&pdr=#{date_now}-#{date_now}&cdr=#{date_last_week}-#{date_last_week}&cmp=date_range&gdfmt=hour&rpt=VisitsReport&gdfmt=hour"
end

def open_in_browser(url)
system "open '#{url}'"
end

open_in_browser google_analytics_visitors_compared_to_last_week_url(Time.now)
open_in_browser google_analytics_visitors_compared_to_last_week_url(Time.now - 1.day)

Previous Post Next Post

You Might Also Like

2 Comments

  • Reply franz enzenhofer September 27, 2010 at 9:40 am

    yes, but where would be the fun in that?

    also the .rb script is great to put it into your login routine.

  • Reply Andreas Klinger September 27, 2010 at 9:26 am

    Isn’t this a better job for javascript? to make a bookmarklet out of it ?

  • Leave a Reply