Skip to content

Add detailed public metrics view for published projects#2557

Merged
lukepayyapilli merged 4 commits intoMIT-LCP:devfrom
lukepayyapilli:feature/project-metrics-detail
Jan 20, 2026
Merged

Add detailed public metrics view for published projects#2557
lukepayyapilli merged 4 commits intoMIT-LCP:devfrom
lukepayyapilli:feature/project-metrics-detail

Conversation

@lukepayyapilli
Copy link
Contributor

@lukepayyapilli lukepayyapilli commented Jan 15, 2026

Summary

  • Add view_count(), views_by_version(), and views_over_time() methods to PublishedProject model.
  • Add unique_viewers_count() and unique_viewers_by_month() methods to AccessLogQuerySet.
  • Add new published_project_metrics view using model methods.
  • Create metrics template showing Unique Registered Project Views (current + all versions), views by version table, and views over time.
  • Add URL route at /content/<slug>/metrics/<version>/.
  • Add "View Details" button to Project Views sidebar card.
  • Add fixture data with AccessLog entries for local testing.
  • Add tests for metrics view and manager methods.

Approach

Created a dedicated metrics page accessible from the Project Views card in the sidebar. View counting logic is encapsulated in PublishedProject model methods (view_count(), views_by_version(), views_over_time()), which delegate to AccessLogQuerySet methods for the actual queries.

Reasoning

  • Model methods make the logic reusable and testable.
  • Using unique_viewers_by_month() counts unique viewers per month (same user viewing in multiple months is counted once per month).
  • Fixture data uses "LogCategory.ACCESS" format to match Django's enum string representation.

Screenshots

Screenshot 2026-01-19 at 10 25 03 AM Screenshot 2026-01-19 at 10 25 23 AM

Part of #2336

@lukepayyapilli lukepayyapilli force-pushed the feature/project-metrics-detail branch from faf41ae to c3d7275 Compare January 15, 2026 16:01
Copy link
Member

@tompollard tompollard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again Luke. I added a couple of quick comments but would like to take a deeper look later!

@lukepayyapilli
Copy link
Contributor Author

lukepayyapilli commented Jan 15, 2026

Thanks for the review @tompollard! These are great improvements. I've addressed your feedback:

  • Use get_object_or_404(): Updated to use get_object_or_404() instead of try/except.
  • Move imports to top of module: Removed the unused imports (Count, TruncMonth) that were inside the function.
  • Move logic to PublishedProject model: Added three new methods to PublishedProject:
    • view_count(all_versions=False) - returns unique viewer count for this version or all versions
    • views_by_version() - returns list of view counts per version
    • views_over_time() - returns monthly view counts

The view is now much cleaner and delegates to these model methods. Let me know if there are other improvements you'd like me to make (e.g. add additional visualizations or aggregated metrics etc.) - thanks!

@lukepayyapilli lukepayyapilli force-pushed the feature/project-metrics-detail branch from 9218a2f to ffb8555 Compare January 15, 2026 17:45
@lukepayyapilli
Copy link
Contributor Author

lukepayyapilli commented Jan 15, 2026

Apologies @tompollard - I missed some inline imports in the model methods. Fixed now by importing AccessLog at the top of the file from project.modelcomponents.log to avoid circular import issues.

Copy link
Member

@tompollard tompollard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Luke!

@lukepayyapilli lukepayyapilli added this pull request to the merge queue Jan 20, 2026
Merged via the queue into MIT-LCP:dev with commit 4ec24b8 Jan 20, 2026
7 checks passed
@lukepayyapilli lukepayyapilli deleted the feature/project-metrics-detail branch January 20, 2026 14:21
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.

2 participants

Comments