• Stars
    star
    147
  • Rank 251,347 (Top 5 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 12 years ago
  • Updated about 1 year ago

Reviews

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

Repository Details

A Ruby wrapper for the Google Analytics API

Garb Gem Version CI License

https://github.com/Sija/garb

Google Shutting Down Deprecated Auth on April 20th, 2015

On April 20th, Google will be shutting down ClientLogin, AuthSub, and OAuth 1.0. https://groups.google.com/forum/#!topic/google-analytics-api-notify/g8wbdUqEDd0

Legato

There's rewritten and (moar) actively maintained version of the library in the form of Legato. You might want to check it out as it's mostly compatible with Garb.

Important Changes

This fork contains heavily modified version of vigetlab's Garb library. It works only with version 3 of Google API.

Please read CHANGELOG.

Description

Provides a Ruby API to the Google Analytics API.

https://developers.google.com/analytics/devguides/reporting/core/v3/coreDevguide

Basic Usage

Single User Login

Garb::Session.api_key = api_key # required for 2-step authentication
Garb::Session.login(username, password)

OAuth Access Token

Garb::Session.access_token = access_token # an instance of OAuth2::Client

Accounts, WebProperties, Profiles, and Goals

Garb::Management::Account.all
Garb::Management::WebProperty.all
Garb::Management::Profile.all
Garb::Management::Goal.all

Profiles for a UA- Number (a WebProperty)

profile = Garb::Management::Profile.all.detect { |p| p.web_property_id == 'UA-XXXXXXX-X' }

Define a Report Class

class Exits
  extend Garb::Model

  metrics :exits, :pageviews
  dimensions :page_path
end

Get the Results

Exits.results(profile, filters: { :page_path.eql => '/' })

OR shorthand

profile.exits(filters: { :page_path.eql => '/' })

Be forewarned, these numbers are for the last 30 days and may be slightly different from the numbers displayed in Google Analytics' dashboard for 1 month.

Other Parameters

  • start_date: The date of the period you would like this report to start
  • end_date: The date to end, inclusive
  • limit: The maximum number of results to be returned
  • offset: The starting index
  • all: Return all results if true (which might result in several requests to GAPI)
  • sampling_level: Specify precision vs speed strategy (default, faster, greater_precision)

Metrics & Dimensions

Metrics and Dimensions are very complex because of the ways in which they can and cannot be combined.

I suggest reading the google documentation to familiarize yourself with this.

https://developers.google.com/analytics/devguides/reporting/core/dimsmets#q=bouncerate

When you've returned, you can pass the appropriate combinations to Garb, as symbols.

Filtering

Google Analytics supports a significant number of filtering options.

https://developers.google.com/analytics/devguides/reporting/core/v3/reference#filters

Here is what we can do currently: (the operator is a method on a symbol for the appropriate metric or dimension)

Operators on metrics:

:eql      => '==',
:not_eql  => '!=',
:gt       => '>',
:gte      => '>=',
:lt       => '<',
:lte      => '<='

Operators on dimensions:

:matches          => '==',
:does_not_match   => '!=',
:contains         => '=~',
:does_not_contain => '!~',
:substring        => '=@',
:not_substring    => '!@'

Given the previous Exits example report in shorthand, we can add an option for filter:

profile.exits(filters: { :page_path.eql => '/extend/effectively-using-git-with-subversion/' })

SSL

Version 0.2.3 includes support for real ssl encryption for SINGLE USER authentication. First do:

Garb::Session.login(username, password, secure: true)

Next, be sure to download https://curl.haxx.se/ca/cacert.pem into your application somewhere. Then, point Garb.ca_cert_file property to that file.

For whatever reason, simply creating a new certificate store and setting the defaults would not validate the google ssl certificate as authentic.

OPEN / READ TIMEOUT

The open and read timeout values used with the network client (Net::HTTP) are configurable. Both values default to 60 seconds.

Garb.open_timeout = 3
Garb.read_timeout = 3

TODOS

  • rebuild AND/OR filtering in Garb::Model

Requirements

  • active_support >= 2.2
  • multi_json >= 1.3

Requirements for Testing

  • shoulda
  • mocha
  • bourne

Install

Add this line to your application’s Gemfile:

gem 'garb'

Then run:

bundle install

Contributors

Many Thanks, for all their help, goes to:

  • Patrick Reagan
  • Justin Marney
  • Nick Plante
  • James Cook
  • Chris Gunther
  • Sijawusz Pur Rahnama

More Repositories

1

raven.cr

Raven is a Crystal client for Sentry
Crystal
120
star
2

debug.cr

Debug macro for Crystal
Crystal
92
star
3

ipaddress.cr

A Crystal library to handle IPv4 and IPv6 addresses in a modern and productive way.
Crystal
43
star
4

retriable.cr

Retriable.cr is a simple DSL to retry failed code blocks
Crystal
38
star
5

any_hash.cr

Better JSON::Any for Crystal
Crystal
33
star
6

blurhash.cr

A pure Crystal implementation of BlurHash algorithm
Crystal
22
star
7

backtracer.cr

Crystal shard aiming to assist with parsing backtraces into a structured form.
Crystal
16
star
8

crystal-dash-docset

Dash docset generator for Crystal
Shell
16
star
9

ksuid.cr

Crystal implementation of K-Sortable Globally Unique IDs
Crystal
16
star
10

gphoto2.cr

Crystal shard wrapping libgphoto2
Crystal
15
star
11

climate.cr

Tiny tool to make your CLI output 🌈 coloured
Crystal
14
star
12

serialport.cr

Crystal bindings for libserialport: cross-platform library for accessing serial ports.
Crystal
12
star
13

base62.cr

Base62 encoder/decoder for Crystal
Crystal
10
star
14

crystal-environment

Crystal::Environment
Crystal
7
star
15

gphoto2-web

Web API for libgphoto2
Crystal
6
star
16

gitbook2pdf

CLI utility to turn a published GitBook website into a collection of PDFs for offline reading
JavaScript
3
star
17

Gizmo

Quick'n'easy file based content management system
PHP
2
star
18

jsonl.cr

Crystal shard for handling JSONL (JSON Lines) parsing
Crystal
1
star
19

Sija

1
star
20

coffeeshop

Unfinished Coffee powered, Express based framework for Node.js
CoffeeScript
1
star
21

kPilot.w3

Web backend for kPilot Konnekt IM plugin.
PHP
1
star
22

markdown

PSR-0 compliant Markdown library
PHP
1
star
23

seedling

Rails 3 plugin for a database-independent YAML seeds import/export.
Ruby
1
star
24

MazeSolver

Maze solver written in PHP 5.
PHP
1
star
25

kZmieniacz

kZmieniacz to wtyczka dla komunikatora Konnekt pozwalająca zmieniać status opisowy jednocześnie we wszystkich wykorzystywanych sieciach.
C++
1
star
26

photoindex

Ancient, self-contained php gallery script.
PHP
1
star
27

resque-dry

Ruby
1
star
28

swift

Never finished C++ templating engine.
C++
1
star
29

kulturadaru

PHP
1
star
30

smartypants

PSR-0 compliant Smartypants library
PHP
1
star
31

kAway

Away system for the Konnekt IM
C++
1
star
32

git-rewrite-author

CLI tool for rewriting author/committer history of a git repository
Crystal
1
star
33

QRKit

QR Reader in Objective C ported from zxing
C++
1
star
34

thumb-cutter

Blazingly fast thumb cutting and image juggling middleware for any node/express.js kitchen sink
JavaScript
1
star
35

sunspot_resque

Sunspot-Resque Session Proxy
Ruby
1
star
36

jquery.clamp

JavaScript with CSS "overflow: ellipsis" line clamping, as jQuery plugin and standalone AMD module
CoffeeScript
1
star