0.0
No commit activity in last 3 years
No release in over 3 years
Ruby Statcounter API wrapper
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 1.16.1
= 2.0.3
= 12.3.0
= 3.7.0
= 0.9.1
= 3.2.1

Runtime

<= 0.15.2, >= 0.8
 Project Readme

Statcounter

Build Status Gem Version

Ruby Statcounter API wrapper

Installation

Add this line to your application's Gemfile:

gem 'statcounter'

And then execute:

$ bundle

Or install it yourself as:

$ gem install statcounter

Initialization

# config/initializers/statcounter.rb

Statcounter.configure do |config|
  config.username = 'STATCOUNTER_USERNAME_HERE'
  config.secret = 'STATCOUNTER_API_PASSWORD_HERE'
  config.timeout = 60 # default is 60
  config.timezone = 'America/New_York' #default is America/New_York
end

In case your app has to handle multiple Statcounter accounts you can pass credentials to each endpoint wrapper method like this:

Statcounter::Projects.all(username: 'STATCOUNTER_USERNAME_HERE', secret: 'STATCOUNTER_API_PASSWORD_HERE')

Examples

Projects

Get all your projects

Statcounter::Projects.all

# returns array of project hashes
[
  {
    project_id: '1000000',
    project_name: 'mywebsite1.com',
    url: 'https://www.mywebsite1.com',
    project_group_id: '1',
    project_group_name: 'Websites',
    hidden_group: '0',
  },
]

Find projects

When selecting one projects:

Statcounter::Projects.find(1000000)

# returns project hash
{
  project_name: 'mywebsite1.com',
  log_size:  '500',
  timezone:  'America/New_York',
  url: 'https://www.mywebsite1.com',
  log_oldest_entry: 'LOG_OLDEST_ENTRY',
  log_latest_entry: 'LOG_LATEST_ENTRY',
  created_at: 'CREATED_AT'
}

When selecting multiple projects:

Statcounter::Projects.find([1000000, 1000001])

# returns array of project hashes
[
  {
    project_name: 'mywebsite1.com',
    log_size:  '500',
    timezone:  'America/New_York',
    url: 'https://www.mywebsite1.com',
    log_oldest_entry: 'LOG_OLDEST_ENTRY',
    log_latest_entry: 'LOG_LATEST_ENTRY',
    created_at: 'CREATED_AT'
  },
  {
    project_name: 'mywebsite2.com',
    log_size:  '500',
    timezone:  'America/New_York',
    url: 'https://www.mywebsite2.com',
    log_oldest_entry: 'LOG_OLDEST_ENTRY',
    log_latest_entry: 'LOG_LATEST_ENTRY',
    created_at: 'CREATED_AT'
  }
]

Create project

Statcounter::Projects.create(
  project_name: 'mywebsite1.com',
  url: 'https://www.mywebsite2.com',
  public_stats: true, # default false
  timezone: 'Europe/Vilnius',
)

# returns hash with id and security code
{
  project_id: '1000000',
  security_code: 'hjk89077hh',
}

Delete project

Statcounter::Projects.delete(
  project_id: '123123',
  admin_username: 'admin',
  admin_password: 'password',
)

# return string 'ok'
'ok'

Summary stats

Get daily

When one project:

Statcounter::SummaryStats.daily(
  project_ids: 1000,
  date_from: Date.yesterday,
  date_to: Date.yesterday,
)

# Returns array of summary stats by date

[
  {
    date: '2016-07-04',
    page_views: '876',
    unique_visits: '609',
    returning_visits: '57',
    first_time_visits: '552',
  }
]

When multiple projects:

Statcounter::SummaryStats.daily(
  project_ids: [1000, 1001],
  date_from: Date.yesterday,
  date_to: Date.yesterday,
)

# Returns hash where key is project id and value is array of summery stats by date

{
  1000 => [
    {
      date: '2016-07-04',
      page_views: '876',
      unique_visits: '609',
      returning_visits: '57',
      first_time_visits: '552',
    }
  ],
  1001 => [
    {
      date: '2016-07-04',
      page_views: '876',
      unique_visits: '609',
      returning_visits: '57',
      first_time_visits: '552',
    }
  ],
}