Create clicks table and tracking #36
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type
Feature
Lineage
From spike
ldraney/palinks #16(Keycloak auth integration design).Prerequisite for
ldraney/palinks #40(canvas view with activity-based card sizing).Repo
ldraney/palinksUser Story
As a palinks user
I want my link clicks to be recorded
So that usage data can drive the canvas layout sizing and surface my most valuable links
Context
The architecture and auth spike docs define a
clickstable for tracking link usage. Originally scoped under the auth-roles story for analytics, this table is now also the data foundation for the canvas layout story — card sizing on the canvas scales proportionally to click count.Schema from
docs/auth.md:Key design decisions (from spike):
user_idfor authenticated clicks,session_idfor anonymous. Both nullable individually, at least one present (model-level validation, not DB constraint).userstable doesn't exist yet (#32). Adduser_idas a plain bigint column; FK constraint added in a later migration when users table lands.click_trackingflag is the target gate, but thefeature_flagstable (#34) doesn't exist yet either. For now, clicks always record. The flag gate is additive — wired in when #34 ships.File Targets
Files the agent should modify or create:
db/migrate/*_create_clicks.rb— create clicks table: link_id (FK to links), user_id (bigint, nullable, no FK yet), session_id (string, nullable), clicked_at (datetime, not null)app/models/click.rb— belongs_to :link, validates at least one of user_id/session_id present, scope for recent/by_linkapp/models/link.rb— has_many :clicks,#click_countmethod (or counter cache),#clicks_since(time)for decay calculationsapp/controllers/clicks_controller.rb— POST create action, sets session_id from session, redirects to link URLconfig/routes.rb— add click recording route (e.g.POST /links/:link_id/click)app/views/links/_link.html.erb— link clicks go through the tracking endpoint instead of directly to URLapp/views/links/show.html.erb— update the direct link to URL to also route through click tracking endpointtest/models/click_test.rb— model validationstest/controllers/clicks_controller_test.rb— recording and redirect testsFiles the agent should NOT touch:
app/javascript/controllers/sortable_controller.js— unrelated drag-and-dropapp/models/concerns/— no concerns needed for this scopeFeature Flag
Flag: none
Rationale: The target flag is
click_trackingbut the feature_flags table (#34) doesn't exist yet. Click recording ships ungated; flag gate added when #34 lands.Acceptance Criteria
Link#click_countreturns total clicks for that linkTest Expectations
bin/rails testConstraints
clicks.countor a method; counter cache is an optimization for later when click volume warrants itChecklist
Related
palinks— project this affects#40— canvas view depends on this for card sizing data#41— link groups depends on this transitivelyScope Review: NEEDS_REFINEMENT
Review note:
review-1400-2026-06-09Spec is thorough and well-structured -- all template sections present, file targets verified, acceptance criteria testable. Two items need attention before READY:
app/views/links/show.html.erbline 4 also links directly tolink.urlbut is not listed in File Targets. Add it to the modify list (for click tracking consistency) or to the "should NOT touch" list with rationale.arch-palinksarchitecture note exists in pal-e-docs. This is a cross-cutting gap affecting all palinks board items -- create the note to complete the traceability triangle.Scope refinement (2026-06-09):
Issue body populated from spike docs (
docs/auth.md,docs/architecture.md) and updated after first scope review.Changes from review feedback:
app/views/links/show.html.erbto file targets — the show page also links directly tolink.urland needs to route through click trackingReviewer also flagged missing
arch-palinksnote in pal-e-docs — that's a cross-cutting gap across all palinks board items, not specific to this ticket. Tracked separately.Scope Review: APPROVED
Review note:
review-1400-2026-06-09-rerevRe-review after refinement. Both items from the previous NEEDS_REFINEMENT review are resolved:
All 9 file targets verified against codebase. All 7 acceptance criteria are agent-verifiable. Standard Rails resource pattern -- no decomposition needed. Ready for next_up.
Validation: PASS
Tiers executed: Tier 1 (local tests), Tier 3 (production)
Validation note:
validation-36-2026-06-137 checks: 7 PASS, 0 FAIL
Evidence:
palinks-6b8fbf884f-qb5ssrunning imagee5352d7f..., 0 restarts/links/6/clickreturns 302, redirects to correct URL