{"id":21565824,"url":"https://github.com/basesecrete/active_analytics","last_synced_at":"2025-04-14T11:10:00.566Z","repository":{"id":62552740,"uuid":"344555757","full_name":"BaseSecrete/active_analytics","owner":"BaseSecrete","description":"First-party, privacy-focused traffic analytics for Ruby on Rails applications.","archived":false,"fork":false,"pushed_at":"2025-03-13T14:24:20.000Z","size":300,"stargazers_count":438,"open_issues_count":1,"forks_count":12,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-14T11:09:57.081Z","etag":null,"topics":["analytics","privacy","rails","ruby","trafic-analytics"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BaseSecrete.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-04T17:30:30.000Z","updated_at":"2025-04-06T19:40:05.000Z","dependencies_parsed_at":"2024-01-13T20:51:45.071Z","dependency_job_id":"b27acd50-c765-4bf3-a23d-216753c948cb","html_url":"https://github.com/BaseSecrete/active_analytics","commit_stats":{"total_commits":89,"total_committers":2,"mean_commits":44.5,"dds":0.4044943820224719,"last_synced_commit":"b40643c2321da7e442674b90cefc133a4af7a81a"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseSecrete%2Factive_analytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseSecrete%2Factive_analytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseSecrete%2Factive_analytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseSecrete%2Factive_analytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BaseSecrete","download_url":"https://codeload.github.com/BaseSecrete/active_analytics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248868766,"owners_count":21174758,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics","privacy","rails","ruby","trafic-analytics"],"created_at":"2024-11-24T10:21:58.603Z","updated_at":"2025-04-14T11:10:00.532Z","avatar_url":"https://github.com/BaseSecrete.png","language":"Ruby","readme":"# ActiveAnalytics\n\n\u003cimg align=\"right\" width=\"200px\" src=\"app/assets/images/active_analytics.png\" alt=\"active analytics logo\" style=\"margin: 0 0 72px 48px;\" /\u003e\n\nSimple traffic analytics for the win of privacy.\n\n* NO cookies\n* NO JavaScript\n* NO third parties\n* NO bullshit\n\n**ActiveAnalytics** is a Rails engine directly mountable in your Ruby on Rails application. It doesn't reveal anything about specific visitors. It cannot be blocked by adblockers or other privacy-protecting extensions (and doesn't need to).\n\n**ActiveAnalytics** lets you know about:\n\n* **Sources**: What are the pages and domains that bring some traffic.\n* **Page views**: What are the pages that are the most viewed in your application.\n* **Next/previous page**: What are the entry and exit pages for a given page of your application.\n* **Browser statistics**: What browsers and which versions are visiting your site.\n\n\u003cimg src=\"app/assets/images/active_analytics_screenshot.png\" alt=\"active analytics logo\" style=\"max-width: 100%; margin: 24px 0;\" /\u003e\n\n## Installation\nAdd this line to your application's Gemfile:\n```ruby\ngem 'active_analytics'\n```\n\nThen execute bundle and run the migration:\n```bash\nbundle\nrails active_analytics:install:migrations\nrails db:migrate\n```\n\nAdd the route to ActiveAnalytics dashboard at the desired endpoint:\n\n```ruby\n# config/routes.rb\nmount ActiveAnalytics::Engine, at: \"analytics\"  # http://localhost:3000/analytics\n```\nBy default ActiveAnalytics will extend `ActionController::Base`, but you can specify a custom base controller for the ActiveAnalytics dashboard:\n\n```ruby\n# config/initializers/active_analytics.rb\nRails.application.configure do\n  ActiveAnalytics.base_controller_class = \"AdminController\"\nend\n```\n\n\nThe next step is to collect trafic and there is 2 options.\n\n### Record requests synchronously\n\nThis is the easiest way to start with.\nHowever it's less performant since it triggers a write into your database for each request.\nYour controllers have to call `ActiveAnalytics.record_request(request)` to record page views.\nThe Rails way to achieve is to use `after_action` :\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  after_action :record_page_view\n\n  def record_page_view\n    # This is a basic example, you might need to customize some conditions.\n    # For most sites, it makes no sense to record anything other than HTML.\n    if response.content_type \u0026\u0026 response.content_type.start_with?(\"text/html\")\n      # Add a condition to record only your canonical domain\n      # and use a gem such as crawler_detect to skip bots.\n      ActiveAnalytics.record_request(request)\n    end\n  end\nend\n```\n\nIn case you don't want to record all page views, because each application has sensitive URLs such as password reset and so on, simply define a `skip_after_action :record_page_view` in the relevant controller.\n\n### Queue requests asynchronously\n\nIt requires more work and it's relevant if your application handle a large trafic.\nThe idea is to queue data into Redis because it does not require the database writing to the disk on each request.\nFirst you have to set the Redis URL or connection.\n\n```ruby\n# File lib/patches/active_analytics.rb or config/initializers/active_analytics.rb\n\nActiveAnalytics.redis_url = \"redis://user:password@host/1\" # Default ENV[\"ACTIVE_ANALYTICS_REDIS_URL\"] || ENV[\"REDIS_URL\"] || \"redis://localhost\"\n\n# If you use special connection options you have to instantiate it yourself\nActiveAnalytics.redis = Redis.new(\n  url: ENV[\"REDIS_URL\"],\n  reconnect_attempts: 10,\n  ssl_params: {verify_mode: OpenSSL::SSL::VERIFY_NONE}\n)\n```\n\nThen your controllers have to call `ActiveAnalytics.queue_request(request)` to queue page views.\nThe Rails way to achieve is to use `after_action` :\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  after_action :queue_page_view\n\n  def queue_page_view\n    # This is a basic example, you might need to customize some conditions.\n    # For most sites, it makes no sense to record anything other than HTML.\n    if response.content_type \u0026\u0026 response.content_type.start_with?(\"text/html\")\n      # Add a condition to record only your canonical domain\n      # and use a gem such as crawler_detect to skip bots.\n      ActiveAnalytics.queue_request(request)\n    end\n  end\nend\n```\n\nQueued data need to be saved into the database in order to be viewable in the ActiveAnalytics dashboard.\nFor that, call `ActiveAnalytics.flush_queue` from a cron task or a background job.\n\nIt's up to you if you want to flush the queue every hour or every 10 minutes.\nI advise to execute the last flush of the day at 23:59.\nIt prevents from shifting the trafic to the next day.\nIn that case only the last minute will be shifted to the next day, even if the flush ends after midnight.\nThis small imperfection allows a simpler implementation for now.\nKeep it simple !\n\n\n## Authentication and permissions\n\nActiveAnalytics cannot guess how you handle user authentication, because it is different for all Rails applications.\nSo you have to monkey patch `ActiveAnalytics::ApplicationController` in order to inject your own mechanism.\nThe patch can be saved wherever you want.\nFor example, I like to have all the patches in one place, so I put them in `lib/patches`.\n\n```ruby\n# lib/patches/active_analytics.rb\n\nActiveAnalytics::ApplicationController.class_eval do\n    before_action :require_admin\n\n    def require_admin\n      # This example supposes there are current_user and User#admin? methods\n      raise ActionController::RoutingError.new(\"Not found\") unless current_user.try(:admin?)\n    end\n  end\nend\n```\n\nThen you have to require the monkey patch.\nBecause it's loaded via require, it won't be reloaded in development.\nSince you are not supposed to change this file often, it should not be an issue.\n\n```ruby\n# config/application.rb\nconfig.after_initialize do\n  require \"patches/active_analytics\"\nend\n```\n\nIf you use Devise, you can check the permission directly from routes.rb :\n\n```ruby\n# config/routes.rb\nauthenticate :user, -\u003e (u) { u.admin? } do # Supposing there is a User#admin? method\n  mount ActiveAnalytics::Engine, at: \"analytics\" # http://localhost:3000/analytics\nend\n```\n\n## License\nThe gem is available as open-source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\nMade by [Base Secrète](https://basesecrete.com).\n\nRails developer? Check out [RoRvsWild](https://rorvswild.com), our Ruby on Rails application monitoring tool.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasesecrete%2Factive_analytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbasesecrete%2Factive_analytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasesecrete%2Factive_analytics/lists"}