A Rack Middleware wrapper around Gabba which sends server-side notifications to Google Analytics.
Allows filtering by content type or url string
Add the following to your app's Gemfile:
gem 'angerfist'
Then follow the instructions, depending on what Rack-based platform you're using.
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.
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.
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:
use Rack::Angerfist, tracker_id: GA_TRACKER_ID, domain: GA_TRACKER_DOMAIN, content_types: ["application/json"]
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:
use Rack::Angerfist, tracker_id: GA_TRACKER_ID, domain: GA_TRACKER_DOMAIN, paths: ["/path"]
config = {
tracker_id: GA_TRACKER_ID,
domain: GA_TRACKER_DOMAIN,
paths: ["/path"]
}
Rails.application.config.middleware.use(Rack::Angerfist, config)
The code is open source under the MIT license. See the LICENSE.md file for full details.