Socket
Book a DemoInstallSign in
Socket

simple_analytics

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple_analytics

0.0.2
bundlerRubygems
Version published
Maintainers
1
Created
Source

SimpleAnalytics

Build Status

SimpleAnalytics gem provides accessing Google Analytics Export Api. It uses Version 3.0 of the Google Core Reporting API with JSON. You can find the google documentation here.

Getting Started

You can add it to your Gemfile with:

gem 'simple_analytics'

Authentication using the ClientLogin:

analytics = SimpleAnalytics::Api.authenticate('user@gmail.com', 'password')

The authenticate method sets an auth_token in the analytics service object. Then you can fetch the report data:

analytics.fetch(
  'ids'        => 'ga:id',
  'metrics'    => 'ga:visitors',
  'dimensions' => 'ga:country',
  'start-date' => '2012-01-01',
  'end-date'   => '2012-01-10'
)
# => [["United States","24451"], ["Brazil","15616"], ["Spain","3966"]]

The fetch method sets and returns rows. Required query parameters are used to configure which data to return from the Google Analytics:

  • ids — The profile IDs from which to access data.
  • start-date — The beginning of the date range.
  • end-date — The end of the date range.
  • metrics — The numeric values to return.

For more detailed information about the parameters see google REST docs.

Authentication

For the authentication it uses gem google_client_login based on the ClientLogin. You can also pass extra parameters which allows the gem (see the gem's README):

options = { :accountType => 'GOOGLE', :source => 'company-app-version' }
analytics = SimpleAnalytics::Api.authenticate('user@gmail.com', 'password', options)

Authentication Token

You can set yourself the auth_token to use it in the fetching:

analytics.auth_token = 'your-token-from-oauth'

Example

All parameters are escaped before a request. For date format you can use the next tip: Date.today.strftime("%Y-%m-%d").

analytics = SimpleAnalytics::Api.authenticate('user@gmail.com', 'password')

analytics.fetch(
  'ids'        => 'ga:id',
  'metrics'    => 'ga:visitors',
  'dimensions' => 'ga:country',
  'start-date' => '2012-01-01',
  'end-date'   => '2012-01-10'
)
# => [["United States","24451"], ["Brazil","15616"], ["Spain","3966"]]

analytics.rows
# => [["United States","24451"], ["Brazil","15616"], ["Spain","3966"]]

analytics.body
# => returns the parsed response body (hash), where you can get other info, see google docs.

analytics.fetch(
  'ids'        => 'ga:another-id',
  'metrics'    => 'ga:visitors,ga:newVisits',
  'dimensions' => 'ga:pagePath',
  'filters'    => 'ga:pagepath=~/articles/[\w-]+\z'
  'start-date' => '2012-01-01',
  'end-date'   => '2012-01-10'
)
# => [["/articles/first-post","12", "2"], ["/articles/second-post","2", "1"]]

analytics.rows
# => [["/articles/first-post","12", "2"], ["/articles/second-post","2", "1"]]

Dependencies

  • Ruby 1.8.7 or later

FAQs

Package last updated on 15 Jan 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.