Skip to content

Add counter - #439

Merged
rsmoke merged 5 commits into
stagingfrom
add_counter
Jun 15, 2026
Merged

Add counter#439
rsmoke merged 5 commits into
stagingfrom
add_counter

Conversation

@rsmoke

@rsmoke rsmoke commented Jun 15, 2026

Copy link
Copy Markdown
Member

This pull request introduces a comprehensive first-party analytics system for tracking, aggregating, and displaying page view data within the application. It adds automatic page view tracking, background jobs for data rollup and pruning, models for storing aggregated analytics, and a new admin-only dashboard for visualizing traffic and usage trends. The dashboard includes summary cards, interactive charts, and top pages, and is accessible via a new navigation link for admins.

Analytics Tracking and Data Collection

  • Introduces a Trackable concern, included in ApplicationController, which automatically tracks page views (excluding bots and non-HTML requests) by enqueueing a TrackPageViewJob after each request. The job records session, user, controller/action, sanitized path, referrer, device type, HTTP status, and request duration in the PageView model. [1] [2] [3] [4]

Data Aggregation and Rollup

  • Adds background jobs (AnalyticsRollupJob) and models (AnalyticsHourlyRollup, AnalyticsDailyRollup) to aggregate raw page view data into hourly and daily rollup tables for efficient querying and charting. Includes logic for pruning old data. [1] [2] [3]

Analytics Dashboard UI

  • Implements a new AnalyticsDashboardController and associated views to display live summary stats, interactive hourly/daily charts (using a new Stimulus controller and Chart.js), and top pages. The dashboard supports time range selection and manual chart refresh. [1] [2] [3] [4]

Authorization and Navigation

  • Restricts dashboard access to admins via a new AnalyticsDashboardPolicy, and adds a navigation link to the dashboard for authorized users. [1] [2]

Most important changes:

1. Analytics Tracking and Jobs

  • Adds the Trackable concern to ApplicationController to automatically track page views, with logic to filter bots and sensitive paths, and enqueues a background job for each tracked view. [1] [2]
  • Implements TrackPageViewJob to persist page view data, and PageView model methods for live stats, top pages, and aggregation. [1] [2]

2. Data Aggregation

  • Adds AnalyticsRollupJob for hourly/daily aggregation and pruning, and new rollup models (AnalyticsHourlyRollup, AnalyticsDailyRollup) with methods for summarizing and querying analytics data. [1] [2] [3]

3. Analytics Dashboard UI

  • Introduces AnalyticsDashboardController and views for the admin dashboard, including summary cards, interactive charts (with Chart.js via Stimulus), and a top pages table. Supports time range selection and manual refresh. [1] [2] [3] [4]

4. Authorization and Navigation

  • Restricts dashboard access to admins with AnalyticsDashboardPolicy, and adds a navigation link for authorized users. [1] [2]

rsmoke added 5 commits June 15, 2026 13:52
- Included Trackable module in ApplicationController for tracking purposes.
- Added new analytics jobs in recurring.yml for hourly, daily rollup, and pruning.
- Updated queue.yml to configure analytics queue with specific threading and polling settings.
- Defined route for analytics dashboard in routes.rb.
- Enhanced layout views to include links to the analytics dashboard for authorized users.
- Added Chart.js to importmap for data visualization support.
- Created tables for analytics_daily_rollups and analytics_hourly_rollups with relevant columns for tracking user interactions.
- Added sequences for both tables to manage primary key generation.
- Established primary key constraints and unique indexes to ensure data integrity and optimize query performance.
- Included additional table for page_views with corresponding sequence and constraints for comprehensive analytics tracking.
- Implemented a refresh action in the AnalyticsDashboardController to trigger rollup jobs synchronously, allowing immediate chart updates.
- Updated the analytics dashboard view to include a refresh button and a notice for stale data.
- Modified the analytics policy to authorize the refresh action for admin users.
- Adjusted routes to include a POST endpoint for refreshing analytics data.
- Enhanced the PageView model with live summary and top pages methods to provide real-time analytics data.
- Improved data handling in the controller to ensure top pages and summary stats reflect current data without waiting for rollup jobs.
- Modified the properties layer in tailwind.css to enhance support for various CSS features.
- Updated theme and base layers to ensure consistent styling and improved layout handling.
- Adjusted spacing and color variables for better design flexibility and responsiveness.
@rsmoke
rsmoke merged commit 8e4e8c4 into staging Jun 15, 2026
3 checks passed
@rsmoke
rsmoke deleted the add_counter branch June 15, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant