ActsAsActive enhances any ActiveRecord model with easy-to-implement activity tracking. By simply adding a few lines of code, gain insights into daily stats, streaks, and heatmap data for user interactions. This gem offers robust tracking capabilities while integrating smoothly into existing applications, making it a valuable tool for developers.
ActsAsActive is a Ruby gem designed to seamlessly integrate activity tracking into any ActiveRecord model. This powerful tool provides instant insights into daily statistics, streak analytics, and generates data suitable for heatmaps.
Key Features
-
Effortless Integration: Adds activity tracking capabilities to an ActiveRecord model with minimal setup. A polymorphic association is established automatically, and an Activity record is generated for each designated lifecycle event.
-
Tracking Customization: Customize activity tracking through options such as conditionals and hooks. This allows for precise tracking of user actions based on predefined criteria.
class Record < ApplicationRecord
acts_as_active on: [:create, :update], # ➜ Track different actions
if: -> { track_activity? }, # ➜ Enable tracking based on conditions
unless: -> { skip_tracking? },
after_record: -> (activity) { activity.update(metadata: {be: "BOP!"}) } # ➜ Post-processing hook for activities
end
- Activity Insights: Quickly assess user engagement with methods to check activity status and retrieve statistics over various ranges:
record.active_today? # => true
record.activity_count(range: 1.day.ago..Date.today) # => 2
record.heatmap(range: 1.week.ago..Date.today) # => { "2025-08-01" => 1, "2025-08-02" => 3 }
-
Metadata Support: Store and query additional information through metadata fields in JSON or JSONB format, facilitating enhanced data management and retrieval. Examples for PostgreSQL and MySQL/SQLite are provided for granular queries.
-
Testing Made Simple: Run comprehensive tests to ensure functionality and reliability with ease:
ruby -Ilib:ruby test/test_acts_as_active.rb
Contributors are encouraged to report bugs and submit pull requests to enhance this project further. The repository maintains a collaborative and inclusive environment as outlined in its code of conduct.
For additional information and resources, visit the ActsAsActive GitHub repository. Its features simplify the process of incorporating activity tracking into applications, making it an essential tool for any Ruby on Rails developer.
No comments yet.
Sign in to be the first to comment.