You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Organizer analytics: views, referrers and conversion per campaign #252
JOY (2026-11-19) asked for parity with GoFundMe and Kickstarter. Organizers cannot see how their campaign performs. docs/Give-Technical-Design.md §0.1 keeps organizer analytics from the old design; nothing exists today.
Scope
Count campaign page views without storing personal data: no IP, no user id; a daily per-campaign counter plus referrer host (direct, facebook.com, zalo, google, other) and share-button clicks. Bots filtered by user agent. Writes through a SECURITY DEFINER RPC or a route handler with the service role, rate limited.
An "Thống kê" tab on /me/campaigns/[id]: views per day, top referrers, number of contributions and amount per day (from the ledger, never stored counters), conversion (contributions / views), share clicks.
DB changes in DOS/DOS.Me migrations with RLS (only the organizer and admins read) and pgTAP.
On beta: opening a campaign page raises its view count once per day per browser at most; the organizer sees the tab, another user cannot read it; tests pass.
Campaigns PO (line:campaigns): filed the DOS/DOS.Me database prerequisite as #263 (line:platform -> Give Product Owner). Ready to build the apps/web tracking route & /me/campaigns/[id] "Thống kê" tab as soon as #263 lands on DOS.Medev.
DB prerequisite #263 has merged into DOS/DOS.Medev via https://github.com/DOS/DOS.Me/pull/1852 (merge commit db6ccf74fa34c409822d045b8176f9469695d9f1, migration 20261129120000_give_campaign_analytics.sql).
Call via dbAs(session.accessToken).rpc('get_campaign_analytics', { p_campaign_id, p_days }).
Restricted strictly to the campaign organizer (organizer_id = auth.uid()) and give staff (give.is_admin(): moderator, finance, admin).
Money series is computed strictly from give.ledger_entries (never stored money counters):
give campaigns: unreversed received + unmatched_in posts bucketed by bank booked_at date (Asia/Ho_Chi_Minh), excluding other_in; cross-day split transfers for a single donation count once in contributions_count on its earliest booked date in the window while keeping each transfer's amount on its own booked_at day.
back campaigns: net-positive pledged contributions bucketed by initial positive pledge date (Asia/Ho_Chi_Minh), excluding cancelled/lapsed pledges.
checkpoint: session=b3d8a837-d38f-4fd9-a5bc-a376463a6212 PR #295 opened (#295) at commit 535c086 against dev. Local format:check, lint, typecheck, build, and Vitest passed; independent review and CI checks running.
Done: Implemented organizer campaign analytics in apps/web (privacy-safe, bot-filtered, same-origin-checked, IPv6-/64 rate-limited POST /api/analytics/event route; client-side daily-deduplicated view beacon and share-click tracking; organizer /me/campaigns/[id]?tab=analyticsThống kê tab with 7/30/90-day switcher, KPI strip, daily trend chart & responsive breakdown, referrer breakdown, empty/error states, and full test suite). Merged via PR #295 (#295) into DOS/Givedev at merge commit 8ff173ee18d6c514965615b27dd3ba1df05eee19 (checkpoint #issuecomment-7067695598).
Evidence: Required CI checks Lint (1m15s) and Build all apps (40s) passed on accepted head fdd47fe62946ecd7792eb893d85e4268d5d5cf3c; fresh-context independent review completed with all 3 Important and 6 Minor findings resolved before merge; Vercel dev deployment succeeded (https://vercel.com/metados/give/BKFXW2Kcz9e8ta3JuBZUhoHL5hFG -> https://beta.give.vn).
Remaining: Live beta smoke verification (optional) and Production promotion (dev -> main / give.vn) after DB prerequisite DOS/DOS.Me#1852 (20261129120000_give_campaign_analytics.sql) reaches DOS/DOS.Memain, which is Give Product Owner (Claude PO) exclusive step with JOY approval. Keep #252 open until Production promotion completes.
Next step: Campaigns PO records dev completion and coordinates Production promotion handoff with Give Product Owner once DOS/DOS.Me#1852 lands on main.
Blockers: Production promotion requires DOS/DOS.Me#1852 on main and JOY approval via Give Product Owner (Claude PO).
Branch: merged into dev at 8ff173ee18d6c514965615b27dd3ba1df05eee19 (feature branch antigravity/252-campaign-analytics merged and local worktree removed).
claim: executor=Antigravity session=83b36fa6-8c08-49d6-aeec-63bab02a5e52 scope="Production steps, waiting for Claude PO (Give Product Owner) DOS/DOS.Me#1852 + #295 dev -> main promotion" branch=antigravity/252-campaign-analytics target=2026-11-28
checkpoint: session=83b36fa6-8c08-49d6-aeec-63bab02a5e52 waiting for Production promotion (DOS/DOS.Me main then DOS/Give main / give.vn) by Give Product Owner (Claude Code) after JOY approval; #295 merged at 8ff173e and deployed to https://beta.give.vn (Vercel success).
Activity
JOY commentedon Nov 18, 2026
Campaigns PO (
line:campaigns): filed theDOS/DOS.Medatabase prerequisite as #263 (line:platform->Give Product Owner). Ready to build theapps/webtracking route &/me/campaigns/[id]"Thống kê" tab as soon as#263lands onDOS.Medev.JOY commentedon Nov 21, 2026
DB prerequisite #263 has merged into
DOS/DOS.Medevvia https://github.com/DOS/DOS.Me/pull/1852 (merge commitdb6ccf74fa34c409822d045b8176f9469695d9f1, migration20261129120000_give_campaign_analytics.sql).RPC Contract
1. Write RPC (
service_roleonly)dbService().rpc('record_campaign_event', { p_campaign_id, p_event, p_referrer })from a rate-limited, bot-filtered Next.js route handler.give.is_public_status:live,settling,succeeded,failed,closed).give.campaign_daily_analyticsstores only aggregate daily counters).p_referrer: null(or'direct') for same-origin navigation (give.vn/beta.give.vn); unknown external hosts map to'other'.2. Read RPC (
authenticatedonly)dbAs(session.accessToken).rpc('get_campaign_analytics', { p_campaign_id, p_days }).organizer_id = auth.uid()) andgivestaff (give.is_admin():moderator,finance,admin).give.ledger_entries(never stored money counters):givecampaigns: unreversedreceived+unmatched_inposts bucketed by bankbooked_atdate (Asia/Ho_Chi_Minh), excludingother_in; cross-day split transfers for a single donation count once incontributions_counton its earliest booked date in the window while keeping each transfer's amount on its ownbooked_atday.backcampaigns: net-positivepledgedcontributions bucketed by initial positive pledge date (Asia/Ho_Chi_Minh), excluding cancelled/lapsed pledges.Returned
jsonbPayload Shape{ "campaign_id": "uuid", "campaign_type": "give | back", "days": 30, "start_date": "YYYY-MM-DD", "end_date": "YYYY-MM-DD", "totals": { "views": 0, "share_clicks": 0, "contributions_count": 0, "contributions_amount": 0, "conversion_rate": 0 }, "daily": [ { "date": "YYYY-MM-DD", "views": 0, "share_clicks": 0, "contributions_count": 0, "contributions_amount": 0 } ], "referrers": [ { "bucket": "direct | facebook.com | zalo | google | other", "views": 0 } ] }daily: chronological (date ASC), zero-filled for every Vietnam date fromstart_datetoend_dateinclusive (length =days).referrers:viewbuckets withviews > 0sorted byviews DESC, bucket ASC(empty array[]when no views; never includes'none'fromshare_click).totals.conversion_rate:round(contributions_count / views, 6)whenviews > 0, else0.Error Codes
GIVE_ANALYTICS_EVENT_INVALID23514(check_violation)record_campaign_event:p_eventis NULL or not'view'/'share_click'GIVE_ANALYTICS_DAYS_INVALID23514(check_violation)get_campaign_analytics:p_days < 1orp_days > 365GIVE_CAMPAIGN_NOT_FOUNDP0002(no_data_found)givestaff (on read; no existence leak)GIVE_SIGN_IN_REQUIRED42501(insufficient_privilege)get_campaign_analytics:auth.uid()is NULLJOY commentedon Nov 21, 2026
claim: executor=Antigravity session=b3d8a837-d38f-4fd9-a5bc-a376463a6212 scope="apps/web campaign analytics tracking route + /me/campaigns/[id] Thong ke tab" branch=antigravity/252-campaign-analytics target=2026-11-22
JOY commentedon Nov 21, 2026
checkpoint: session=b3d8a837-d38f-4fd9-a5bc-a376463a6212 PR #295 opened (#295) at commit 535c086 against dev. Local format:check, lint, typecheck, build, and Vitest passed; independent review and CI checks running.
fix(web): harden analytics ingestion bounds, IPv6 rate limit, and hal…
feat(web): organizer campaign analytics tracking & Thống kê tab (#295)
JOY commentedon Nov 21, 2026
checkpoint: session=b3d8a837-d38f-4fd9-a5bc-a376463a6212 PR #295 (#295) squash-merged into DOS/Give dev at merge commit
8ff173ee18d6c514965615b27dd3ba1df05eee19(from accepted headfdd47fe62946ecd7792eb893d85e4268d5d5cf3c). Vercel dev/beta deployment completed with status success (https://vercel.com/metados/give/BKFXW2Kcz9e8ta3JuBZUhoHL5hFG -> https://beta.give.vn); PR preview also passed (https://give-git-antigravity-252-campaign-analytics-metados.vercel.app). Local worktree and branch cleaned up.JOY commentedon Nov 21, 2026
handoff: session=b3d8a837-d38f-4fd9-a5bc-a376463a6212 to=83b36fa6-8c08-49d6-aeec-63bab02a5e52
Done: Implemented organizer campaign analytics in
apps/web(privacy-safe, bot-filtered, same-origin-checked, IPv6-/64 rate-limitedPOST /api/analytics/eventroute; client-side daily-deduplicated view beacon and share-click tracking; organizer/me/campaigns/[id]?tab=analyticsThống kêtab with 7/30/90-day switcher, KPI strip, daily trend chart & responsive breakdown, referrer breakdown, empty/error states, and full test suite). Merged via PR #295 (#295) intoDOS/Givedevat merge commit8ff173ee18d6c514965615b27dd3ba1df05eee19(checkpoint #issuecomment-7067695598).Evidence: Required CI checks
Lint(1m15s) andBuild all apps(40s) passed on accepted headfdd47fe62946ecd7792eb893d85e4268d5d5cf3c; fresh-context independent review completed with all 3 Important and 6 Minor findings resolved before merge; Verceldevdeployment succeeded (https://vercel.com/metados/give/BKFXW2Kcz9e8ta3JuBZUhoHL5hFG -> https://beta.give.vn).Remaining: Live beta smoke verification (optional) and Production promotion (
dev->main/give.vn) after DB prerequisiteDOS/DOS.Me#1852(20261129120000_give_campaign_analytics.sql) reachesDOS/DOS.Memain, which is Give Product Owner (Claude PO) exclusive step with JOY approval. Keep#252open until Production promotion completes.Next step: Campaigns PO records
devcompletion and coordinates Production promotion handoff with Give Product Owner onceDOS/DOS.Me#1852lands onmain.Blockers: Production promotion requires
DOS/DOS.Me#1852onmainand JOY approval via Give Product Owner (Claude PO).Branch: merged into
devat8ff173ee18d6c514965615b27dd3ba1df05eee19(feature branchantigravity/252-campaign-analyticsmerged and local worktree removed).JOY commentedon Nov 21, 2026
claim: executor=Antigravity session=83b36fa6-8c08-49d6-aeec-63bab02a5e52 scope="Production steps, waiting for Claude PO (Give Product Owner) DOS/DOS.Me#1852 + #295 dev -> main promotion" branch=antigravity/252-campaign-analytics target=2026-11-28
JOY commentedon Nov 21, 2026
checkpoint: session=83b36fa6-8c08-49d6-aeec-63bab02a5e52 waiting for Production promotion (DOS/DOS.Me main then DOS/Give main / give.vn) by Give Product Owner (Claude Code) after JOY approval; #295 merged at 8ff173e and deployed to https://beta.give.vn (Vercel success).
JOY commentedon Nov 22, 2026
done: session=83b36fa6-8c08-49d6-aeec-63bab02a5e52
Promoted to Production and verified live: