Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Simple Analytics logo

Simple Analytics Rails

License: MIT Ruby Code Style Standard Tests

Simple Analytics is a privacy friendly analytics. No consent required from your visitors!

This gem adds the JavaScript Tracking Script to the <head> & <body> tag of your Ruby on Rails applications.

🚀 Installation

Add this line to your application's Gemfile:

gem 'simple_analytics_rails'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install simple_analytics_rails

✨ Usage

After the gem is installed, it will automatically append the Simple Analytics JavaScript snippet before the </head> tag on your HTML pages.

However you can also configure it via an initializer:

# config/initializers/simple_analytics.rb
SimpleAnalyticsRails.configure do |configuration|
  # ==> Overwrite domain name
  # Default is ""
  configuration.hostname = ""

  # ==> Hash mode
  # Default is ""
  configuration.mode = "hash"

  # ==> Do not track
  # Default is false
  configuration.collect_dnt = false

  # ==> Ignore pages
  # Default is ""
  configuration.ignore_pages = "/search/*,/account/*,/vouchers"

  # ==> Override variable used for JavaScript Events
  # Default is "sa_event"
  configuration.sa_global = "sa_event"

  # ==> Trigger custom page views
  # Default is true
  configuration.auto_collect = true

  # ==> Onload Callback
  # Default is ""
  configuration.onload_callback = "onloadCallback()"

  # ==> Custom Domain
  # Default is ""
  configuration.custom_domain = ""

  # ==> Inject JavaScript To Head
  # You can disable the automatic JavaScript injection if you'd like.
  # Default is true
  configuration.enabled = Rails.env.production?

🙏 Contributing

Bug reports and pull requests are welcome on GitHub at .

Code of Conduct

Everyone interacting in the SimpleAnalyticsRails project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Coding Standards

This project uses Standard for Ruby code to minimize bike shedding related to source formatting.

Please run bundle exec standardrb --fix prior to submitting pull requests.

📦 Releasing

  1. Bump version number at lib/simple_analytics_rails/version.rb
  2. Commit and push changes
  3. Publish a new release on GitHub
  4. A GitHub Action will then publish the latest version to

📝 License

The gem is available as open source under the terms of the MIT License.