Repository navigation
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Analytics failures can leave completed administrative actions unaudited, while anonymous share grants lack a shared budget to bound event storage and provider workload.
8 open issues
Analytics failure can roll back the security audit · New Anonymous grants lack a shared storage and delivery budget · New Canvas share links bypass share_link_created tracking · New Replica previews do not record template_previewed events · New Add migration coverage for preserved notification data · New Downgrade cannot handle newly retained event names · New Enumerate affected stories and provide required screenshots · New Test first-open counting after event retention cleanup · New
What changed in this PR
This PR extends Hub’s existing repository analytics pipeline so administrators can measure feature usage without tracking browser clicks.
Changes:
- Adds nine events covering sharing, previews, canvas pairing, review activity, notifications, and learning actions.
- Expands the SQLite event constraint, adds durable notification first-open tracking, and isolates page-view analytics failures.
- Updates event choices, Storybook fixtures, documentation, and tests for attribution, deduplication, refused actions, and saved selections.
Analytics Storybook screenshot evidence remains incomplete.
| File | Description |
|---|---|
| hub/test/models/session_revocation_concurrency_test.rb | Removes analytics events during test cleanup. |
| hub/test/models/github_app_dual_barrier_concurrency_test.rb | Cleans up repository analytics events. |
| hub/test/models/conversation_notifications_test.rb | Checks reaction attribution and remove/re-add counting. |
| hub/test/models/comment_mentions_test.rb | Checks mention attribution and deduplication. |
| hub/test/integration/templates_test.rb | Covers daily preview counting and analytics failures. |
| hub/test/integration/shared_builds_test.rb | Covers anonymous grant counting and failure isolation. |
| hub/test/integration/share_links_test.rb | Checks creation events and refused actions. |
| hub/test/integration/notifications_test.rb | Covers first opens, attribution, and write retries. |
| hub/test/integration/learnings_test.rb | Checks run-request and decision events. |
| hub/test/integration/fresh_authorizations_test.rb | Verifies protected destination event selections. |
| hub/test/integration/canvas_pairings_test.rb | Checks approval attribution and refused or repeated approvals. |
| hub/test/integration/analytics_test.rb | Verifies selected events persist through destination updates. |
| hub/docs/analytics.md | Documents new events, counting rules, and failure behavior. |
| hub/db/schema.rb | Adds accepted event names and notification open state. |
| hub/db/migrate/20261124170000_add_hub_feature_usage_events.rb | Expands the event constraint and adds first-open state. |
| hub/config/locales/analytics.en.yml | Adds labels for the nine new events. |
| hub/app/models/share_preview_grant.rb | Records anonymous preview-grant issuance. |
| hub/app/models/share_link.rb | Yields newly created links before committing. |
| hub/app/models/review_comment/thread.rb | Records newly added reactions. |
| hub/app/models/review_comment.rb | Shares privacy-limited analytics identifiers. |
| hub/app/models/notification.rb | Claims and records a notification’s first open. |
| hub/app/models/learning/run.rb | Records new or promoted manual run requests. |
| hub/app/models/comment_mention.rb | Records mentions under the comment author’s identity. |
| hub/app/models/canvas_pairing.rb | Records successful pairing approvals. |
| hub/app/models/analytics/event.rb | Adds event types and guarded page-view writes. |
| hub/app/javascript/pages/analytics-page/stories.tsx | Expands the Storybook event-selection fixture. |
| hub/app/controllers/templates_controller.rb | Records available template previews once daily. |
| hub/app/controllers/share_links_controller.rb | Records browser-created public share links. |
| hub/app/controllers/notifications_controller.rb | Records authorized notification opens. |
| hub/app/controllers/learning_decisions_controller.rb | Records saved learning-decision versions. |
| hub/app/controllers/concerns/has_share_link_context.rb | Passes a creation callback to the share-link model. |
| docs/adr/0001-learning-extension-architecture.md | Separates historical event coverage from the current guide. |
Review effort: Max (adaptive)
Comment on lines
+41
to
+42
| Analytics::Event.transaction do | ||
| record_security_audit(outcome: "succeeded") |
Comment on lines
+54
to
+58
| Analytics::Event.record! \ | ||
| repository: share_link.prototype.repository, | ||
| name: "shared_preview_opened", | ||
| source_key: "share_preview_grant/#{grant.id}/issued", | ||
| properties: { prototype_id: share_link.prototype_id, build_id: share_link.build_id } |
Comment on lines
+24
to
+30
| create_share_link do |link| | ||
| Analytics::Event.record! \ | ||
| repository: @repository, | ||
| name: "share_link_created", | ||
| source_key: "share_link/#{link.id}/created", | ||
| actor_id: Analytics.actor_id(user: link.created_by), | ||
| properties: { prototype_id: link.prototype_id, build_id: link.build_id } |
| @preview_path = PreviewGrant.validate_return_path \ | ||
| params.key?(:return_path) ? params[:return_path] : @template.fetch("path") | ||
| render "replica_browses/show" | ||
| record_template_preview if @selected_build |
Comment on lines
+15
to
+16
| update_event_constraint(EXISTING_TYPES + NEW_TYPES) do | ||
| add_column :notifications, :analytics_opened, :boolean, null: false, default: false |
Comment on lines
+20
to
+24
| def down | ||
| update_event_constraint(EXISTING_TYPES) do | ||
| remove_column :notifications, :analytics_opened | ||
| end | ||
| end |
Comment on lines
+79
to
+83
| { value: "share_link_created", label: "Public share link created" }, | ||
| { value: "shared_preview_opened", label: "Public preview opened" }, | ||
| { value: "template_previewed", label: "Template preview opened" }, | ||
| { value: "canvas_pairing_approved", label: "Canvas pairing approved" }, | ||
| { value: "review_reaction_added", label: "Review reaction added" }, |
Comment on lines
+71
to
+73
| get notification_path(@notification) | ||
| assert_response :success | ||
| assert_equal event, events.sole |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Why
Repository administrators can already measure publishing and review activity. This change lets them measure more of what users actually do in Hub without tracking browser clicks.
What changes
share_link_createdshared_preview_openedtemplate_previewedcanvas_pairing_approvedreview_reaction_addedreview_mention_addednotification_openedlearning_run_requestedlearning_decision_recordedStable source keys prevent duplicate records. Analytics write failures do not interrupt template previews, shared previews, or notification opens. The event payload still contains only the existing allowed IDs, with pseudonymous IDs for signed-in actors.
The SQLite migration expands the list of accepted events without backfilling history or changing saved destination selections. It preserves existing events and queued deliveries. New destinations still start with every event type selected. Focused coverage checks event attribution, deduplication, refused actions, and destination selection. The local run also surfaced an existing Puma gem-audit advisory and npm registry TLS failures, neither introduced by this change.
Storybook screenshots
Screenshot evidence for the expanded event list in Hub/Pages/Repositories/Analytics is incomplete. The browser canvas screenshot request timed out.