Skip to content

A Rack Middleware wrapper which sends server-side notifications to Google Analytics.

License

Notifications You must be signed in to change notification settings

OpenAddressesUK/angerfist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Dependency Status Code Climate Gem Version License Badges

Angerfist

A Rack Middleware wrapper around Gabba which sends server-side notifications to Google Analytics.

Allows filtering by content type or url string

Setup

Add the following to your app's Gemfile:

gem 'angerfist'

Then follow the instructions, depending on what Rack-based platform you're using.

Sinatra

Add use Rack::Angerfist to your Sinatra application like so

class App < Sinatra::Base
    use Rack::Angerfist, tracker_id: GA_TRACKER_ID, domain: GA_TRACKER_DOMAIN
end

Where GA_TRACKER_ID is your Google Analytics Tracker ID and GA_TRACKER_DOMAIN is your app's domain.

Rails

Add angerfist.rb to your app's initializers folder with the following content:

config = {
  tracker_id: GA_TRACKER_ID,
  domain: GA_TRACKER_DOMAIN,
}

Rails.application.config.middleware.use(Rack::Angerfist, config)

Where GA_TRACKER_ID is your Google Analytics Tracker ID and GA_TRACKER_DOMAIN is your app's domain.

Additional options

If you only want to filter by content type (for example, if you want to track usage of a JSON API), you can add the an array of content types to your config, like so:

Sinatra

use Rack::Angerfist, tracker_id: GA_TRACKER_ID, domain: GA_TRACKER_DOMAIN, content_types: ["application/json"]

Rails

config = {
  tracker_id: GA_TRACKER_ID,
  domain: GA_TRACKER_DOMAIN,
  content_types: ["application/json"]
}

Rails.application.config.middleware.use(Rack::Angerfist, config)

If you want to filter by page path, you can similarly add an array of paths to your config like so:

Sinatra

use Rack::Angerfist, tracker_id: GA_TRACKER_ID, domain: GA_TRACKER_DOMAIN, paths: ["/path"]

Rails

config = {
  tracker_id: GA_TRACKER_ID,
  domain: GA_TRACKER_DOMAIN,
  paths: ["/path"]
}

Rails.application.config.middleware.use(Rack::Angerfist, config)

Licence

The code is open source under the MIT license. See the LICENSE.md file for full details.

About

A Rack Middleware wrapper which sends server-side notifications to Google Analytics.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages