• Stars
    star
    112
  • Rank 312,240 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 16 years ago
  • Updated over 13 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[NO LONGER WORKS WITH GOOGLE] - Rugalytics is a Ruby API for accessing your Google Analytics Data

The Rugalytics gem no longer works due to changes by Google¶ ↑

For analytics access, check out garb instead: github.com/vigetlabs/garb

Old Docs Below¶ ↑

Rugalytics is a Ruby API for accessing your Google Analytics Data.

Warning: API under development¶ ↑

The Rugalytics API is in early development so it may change slightly over time. It should be in working order, so please give it a test spin! Sometimes Google changes it’s CSV export format, which can break Rugalytics. It’s usually fixed within a week of such occurrences.

The source code is hosted at github. Feel free to fork the code if you have something to contribute:

http://github.com/robmckinnon/rugalytics

Install as a Gem¶ ↑

Should be up at rubyforge, so to install:

sudo gem install rugalytics

Authenticate¶ ↑

Login with your Google Analytics user name and password:

require 'rubygems'
require 'rugalytics'

Rugalytics.login 'username', 'password'

Obtain Profile¶ ↑

Get profile using account name and profile name:

profile = Rugalytics.find_profile('your_site.com', 'blog.your_site.com')

If account name and profile name are the same:

profile = Rugalytics.find_profile('your_site.com')

Change Language Settings to English¶ ↑

At present your language setting for your Google Analytics account must be set to English for Rugalytics to work.

Google: Settings -> Language: choose UK English

OR

Google: Settings -> Language: choose US English

Get Profile Summary Statistics¶ ↑

Obtaining page views:

profile.pageviews # default period is one month ending today
=> 160600

profile.pageviews :from=>'2007-01-01'
=> 2267550

profile.pageviews :from=>'2007-01-01', :to=>'2007-01-02'
=> 24980

The pageviews method is doing this under the hood:

report = profile.pageviews_report :from=>'2007-01-01', :to=>'2007-01-02'

report.pageviews_total
=> 16600

Using the report you can get pageviews_by_day:

report.pageviews_by_day
=> [[Mon, 01 Jan 2007, 8200], [Tue, 02 Jan 2007, 8400]]

In the report, there is a pageviews_graph containing the points:

report.pageviews_graph.sum_of_points
=> 16600

report.pageviews_graph.points_by_day
=> [[Mon, 01 Jan 2007, 8200], [Tue, 02 Jan 2007, 8400]]

Lots of Reports!¶ ↑

The report name comes from the Google Analytics URL for a CSV report export. The report name is the rpt parameter from the URL, e.g. ‘Pageviews’ or ‘TrafficSources’:

https://www.google.com/analytics/reporting/export?fmt=2&...&&rpt=PageviewsReport&...
https://www.google.com/analytics/reporting/export?fmt=2&...&&rpt=TrafficSourcesReport&...

If you are logged in to the Analytics website, you can find the CSV URL by clicking on the Export tab, and then mousing over the CSV option.

To discover a list of report names, there’s a method on profile:

profile.report_names
=> ["ad_versions_report", "adwords_report", "all_sources_report",
    "average_pageviews_report", "bounce_rate_report", "browsers_report",
    "campaigns_report", "colors_report", "content_by_title_report",
    "content_drilldown_report", "content_report", "dashboard_report",
    "depth_of_visit_report", "direct_sources_report", "entrances_report",
    "exits_report", "flash_report", "geo_map_report", "hostnames_report",
    "java_report", "keyword_position_report", "keywords_report",
    "languages_report", "length_of_visit_report", "loyalty_report",
    "networks_report", "os_browsers_report", "pageviews_report",
    "platforms_report", "recency_report", "referring_sources_report",
    "resolutions_report", "search_engines_report", "speeds_report",
    "time_on_site_report", "top_content_detail_keywords_report",
    "top_content_detail_navigation_report", "top_content_detail_path_report",
    "top_content_detail_sources_report", "top_content_report",
    "traffic_sources_report", "unique_visitors_report",
    "visitor_types_report", "visitors_overview_report", "visits_report"]

Load a Report¶ ↑

Let’s load the TrafficSources report:

report = profile.traffic_sources_report

report.name
=> "Traffic Sources Overview"

report.start_date
=> "28 May 2008"

report.end_date
=> "4 June 2008"

report.source_items.collect{|s| "#{s.sources}: #{s.visits}"}.first
=> "google (organic): 15210"

report.keyword_items.collect{|k| "#{k.keywords}: #{k.visits}"}[1]
=> "oecd nz report summary 2007: 14"

Let’s try another report, VisitorsOverview:

report = profile.visitors_overview_report

report.browser_items[1]
=> # Rugalytics::Item @percentage_visits="0.18", @visits="3140", @browser="Firefox"

report.connection_speed_items[3]
=> # Rugalytics::Item @connection_speed="Dialup", @percentage_visits="0.06340057402849197", @visits="1100"

Let’s now grab 100 lines of the Networks report:

report = profile.networks_report :rows=>100

report.items.size
=> 100

report.items.first.network_location
=> "telecom xtra"

Report by URL¶ ↑

Entrance search keywords by URL:

report = profile.top_content_detail_keywords_report(:url=>'/projects/abc')
report.name
=> "Entrance Keywords:,/projects/abc"

report.items.collect{|i| "#{i.keyword} (#{i.unique_pageviews})"}
=> ["project abc (200)", "abc project (110)"]

Pageviews by URL:

report = profile.top_content_detail_report(:url => "/projects/abc")
report.name
=> "Content Detail:,/projects/abc"

report.pageviews_total
=> 179

You can get a content drilldown report, for pages under a certain URL path:

report = profile.content_drilldown_report(:url => "/projects/abc/")
report.name
=> "Content Drilldown,/projects/abc/"

report.items.first
=> # Rugalytics::Item @bounce_rate="0.85", @unique_pageviews="155",
         @percentage_exit="0.776536312849162", @time_on_page="165.75",
         @pageviews="179", @path="/reports/", @dollar_index="0.0",
         @url="http://your_site.com/projects/abc/reports/"

Pageviews by page title:

report = profile.content_by_title_detail_report(:page_title => "Project ABC | Company XYZ")
report.name
=> "Content by Title Detail:,Project ABC | Company XYZ"

report.items.first
=> # Rugalytics::Item @bounce_rate="0.85", @unique_pageviews="1550",
         @percentage_exit="0.776536312849162", @time_on_page="165.75",
         @pageviews="179", @path="/projects/abc", @dollar_index="0.0",
         @url="http://your_site.com/projects/abc"

Use in Rails¶ ↑

To use from Rails, make a config file rails_root/config/rugalytics.yml with the following contents:

---
account: your_account_name
profile: your_profile_name
username: your_user_name
password: your_pass_w

Remember to tell your source control system to ignore this file! If you’re using git, this means adding config/rugalytics.yml to your .gitignore file.

vi .gitignore
config/rugalytics.yml

You can now use Rugalytics from within Rails, and login will be done automatically, e.g.:

profile = Rugalytics.default_profile
report = profile.top_content_report(:from=>(Date.today - 7) )
top_items_over_week = report.items.sort_by{|i| i.unique_pageviews.to_i}.reverse

Rugalytics on Rugrat - a Greasemonkey script for Firefox¶ ↑

TO INSTALL:

Create a rugalytics.yml config file containing:

---
account: your_account_name
profile: your_profile_name
username: your_user_name
password: your_pass_w

Run rugalytics executable on console in same directory as rugalytics.yml:

> rugalytics

Add Greasemonkey to Firefox:

https://addons.mozilla.org/firefox/748/

Go to:

http://localhost:8888/

Add rugrat user script:

http://localhost:8888/rugrat.user.js

Configure website for rugrat to run over:

Firefox -> Tools -> Greasemonkey -> Manage User Scripts
-> select rugrat -> press "Add"
-> add your site, e.g. http://your_site.com/*
-> press "Close"

Browse your site!

Ruby Manor Presentation Slides - Nov 2008¶ ↑

Rugalytics - making a Ruby API to Google Analytics data - presentation slides from Ruby Manor 2008:

http://www.slideshare.net/delineator/rugalytics-ruby-manor-nov-2008-presentation/

Acknowledgements¶ ↑

Rugalytics started life as a fork of jnunemaker’s Statwhore. As the code and project scope began to diverge significantly from Statwhore, a new project was initiated. Rugalytics makes use of the googlebase gem to login to Google.

Rugalytics makes use of the morph gem to emerge Ruby class definitions at runtime based on the contents of the CSV reports from Google Analytics.

License¶ ↑

See LICENSE for the terms of this software.

More Repositories

1

data_morph

Create streams of Elixir structs, maps with atom keys, and keyword lists from CSV/TSV data streams
Elixir
20
star
2

morph

Morph allows you to emerge Ruby class definitions from data or by calling assignment methods.
Ruby
17
star
3

companies-house

Ruby API to UK Companies House XML Gateway.
Ruby
13
star
4

ukcompanies

Rails app for serving data about UK Companies
Ruby
13
star
5

lastfm-growls

Gig notifications via last.fm for band you're 'now playing' - uses last.fm api and growl
Ruby
12
star
6

ons-openapi

Ruby wrapper around the ONS OpenAPI - the UK Office of National Statistics's data API
Ruby
8
star
7

pitfalls

norns library for defining microtonal scales and chords - play on grid as a isomorphic keyboard
Lua
7
star
8

twfynz

Rails app to help people track Aotearoa New Zealand's Parliament
Ruby
7
star
9

pottery

Pottery, same as Morph, plus ability to persist instances to a database; requires Morph and Soup gems.
Ruby
5
star
10

nz-hansard

experimentally storing NZ Hansard data in git
4
star
11

legislation-uk

Ruby API to UK legislation service at: http://www.legislation.gov.uk/
Ruby
4
star
12

billtweets

what it says on the tin
Ruby
3
star
13

openregister-ruby

A Ruby API to UK government data registers http://www.openregister.org/
Ruby
3
star
14

scalpel

SCALPEL - Scraper Alert Parser Extraction Library
Ruby
3
star
15

tell_us_once

Ruby
3
star
16

jedit-ruby-plugin

jEdit Ruby editor plugin - converts jEdit into an intelligent Ruby editor
Java
3
star
17

sic_uk

Ruby on Rails plugin for UK's Standard Industrial Classification (SIC) codes
Ruby
3
star
18

police_complaints

Ruby
3
star
19

lobbyist

Ruby
2
star
20

midi_freq

Elixir utils for MIDI number to frequency conversions
Elixir
2
star
21

acoba

2
star
22

csv_validator

Ruby
2
star
23

poli-people

non-active project
Ruby
2
star
24

expertgroups

Ruby
2
star
25

aidwiki

wiki of aid data
Ruby
2
star
26

blade

experiment ignore (BLADE - Bespoke Linked Application Data Extraction)
Ruby
2
star
27

constituencies_uk

Ruby on Rails plugin for UK's 2010 parliamentary constituencies.
Ruby
2
star
28

node-monome-pad

first pretend to be a serialosc server, then decorate launchpads as a grid
1
star
29

gc-osc-rust-sdl2

Rust code to convert game controller signals to Open Sound Controller (OSC) messages.
Rust
1
star
30

open_banking_ex

Elixir helper functions for using the UK Open Banking API standard
Elixir
1
star
31

midi_loop

MIDI Elixir LiveView playpen
Elixir
1
star
32

mpr121_touch_midi

Convert MPR121 capacitive touch events into BLE MIDI messsages
JavaScript
1
star
33

changeling

experimental implementation of extract function refactoring for Elixir
Elixir
1
star
34

compdent

Ruby
1
star
35

heroku_gandi_dns

Manage DNS records at Gandi for the domains used by your Heroku applications.
Ruby
1
star