BrowserSense
Log information about the browsers accessings your Rails application.
Installation
BrowserSense monitors which browser is accessing your Ruby on Rails app.
Add the gem to your application’s Gemfile and then bundle:
gem "browser_sense"
bundle
To enable logging, add browser_sense to the application_controller.rb of
your app, i.e.:
class ApplicationController < ActionController::Base
[...]
include BrowserSenseFilter
browser_sense
[...]
endData logged
Each invocation of a route of your application generates a line in the log storing the following details:
- Browser name
- Platform
- Device name
- Controller being invoked
- Method of the controller being invoked
- Request format (e.g. html, json)
- Hashed IP, which allows to track requests from the same IP, while preserving privacy
- Timestamp
Information is stored in the application log, each line prefixed by
BrowserSense and data presented in CSV.
Example
$ cat production.log [...] BrowserSense: "Firefox","linux","Unknown","Devise::SessionsController","new","12ca17b49af2289436f303e0166030a21e525d266e209267433801a8fd4071a0","2022-06-09T10:08:09+02:00" [...]
Analyzing Data
When you want to analyze data, extract the information with:
grep BrowserSense production.log | cut -f2- -d: > data.csv
and then, e.g., open the resulting file in a spreadsheet.
There is also a ruby script browser_sense. The script takes as input the
pathname of the file with the log and prints to stdout the result of various
analyses. The script is a quick hack, wrapping sed, grep and miller
(Miller), which must be installed on your machine for the script to succeed.
If you want more reports and plots, you can use the log_sense gem
(https://rubygems.org/gems/log_sense), which understands the data generated by
this gem.
Development
After checking out the repo, run bin/setup to install dependencies. Then,
run rake test to run the tests. You can also run bin/console for an
interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake
install. To release a new version, update the version number in version.rb,
and then run bundle exec rake release, which will create a git tag for the
version, push git commits and the created tag, and push the .gem file to
rubygems.org
Contributing
TODO
Changelog
Authors and Contributors
Known Bugs
We have been running BrowserSense for quite a few years with no particular issues. There are no known bugs; there is an unknown number of unknown bugs.
You are most welcome to report issues and missing features, using the Issue tracker.
License
The gem is available as open source under the terms of the MIT License.