Skip to content

feat(hub): record feature usage events - #357

Draft
cmcnally wants to merge 1 commit into
mainfrom
cmcnally-hub-feature-usage-events
Draft

cmcnally wants to merge 1 commit into
mainfrom
cmcnally-hub-feature-usage-events

Conversation

@cmcnally

Copy link
Copy Markdown
Contributor

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

Event When Hub records it
share_link_created A signed-in user creates a public share link in Hub.
shared_preview_opened A public preview grant is issued. Fetching the share page alone does not count. Each new grant counts, with no actor recorded.
template_previewed A signed-in user opens an available template preview. Counts once per user, template, repository, and UTC day.
canvas_pairing_approved A signed-in user approves a canvas pairing.
review_reaction_added A user adds a new reaction. Repeating an existing reaction does not count.
review_mention_added A new mention is saved. Hub attributes it to the comment author and does not record the mentioned user's identity.
notification_opened A recipient opens a notification for the first time. It cannot count again after the event expires.
learning_run_requested An administrator queues a run or takes over a waiting scheduled run. Joining a run already requested or running does not count again.
learning_decision_recorded An administrator successfully accepts, rejects, or retires a learning. Each saved decision version counts once.

Stable 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.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI adaptive review requested due to automatic review settings November 24, 2026 18:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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
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
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