From 33ac132c6cd3f7ac6211c4e1a786d80d02498295 Mon Sep 17 00:00:00 2001 From: Mux Dev Date: Sat, 30 May 2026 17:07:51 +0100 Subject: [PATCH] feat: add rule editing analytics hook point (no-op stub) - Add lib/useAnalytics.ts with typed trackEvent stub and AnalyticsEventName/AnalyticsEventProperties types - Add optional onRulesChanged prop to RuleBuilder for per-rule add/update/remove callbacks - Fix missing editingIndex useState declaration in RuleBuilder (pre-existing bug) - Wire trackEvent in ContractDetailPage at rule_edit_opened, rule_edit_saved, rule_added, rule_removed - All trackEvent calls are no-ops until a real provider is configured Closes #100 --- app/contracts/[id]/page.tsx | 15 ++++++++++++++- components/RuleBuilder.tsx | 20 ++++++++++++++++++-- lib/useAnalytics.ts | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 lib/useAnalytics.ts diff --git a/app/contracts/[id]/page.tsx b/app/contracts/[id]/page.tsx index b09818e..1a3d986 100644 --- a/app/contracts/[id]/page.tsx +++ b/app/contracts/[id]/page.tsx @@ -11,9 +11,11 @@ import AlertRuleBadge from '@/components/AlertRuleBadge' import WebhookLog from '@/components/WebhookLog' import RuleBuilder from '@/components/RuleBuilder' import CopyButton from '@/components/CopyButton' +import { useAnalytics } from '@/lib/useAnalytics' export default function ContractDetailPage({ params }: { params: { id: string } }) { const router = useRouter() + const { trackEvent } = useAnalytics() const [contract, setContract] = useState(null) const [alerts, setAlerts] = useState([]) const [mounted, setMounted] = useState(false) @@ -39,6 +41,7 @@ export default function ContractDetailPage({ params }: { params: { id: string } setEditedRules(contract!.rules) setRulesError(null) setShowEditRules(true) + trackEvent('rule_edit_opened', { contractId: params.id, ruleCount: contract!.rules.length }) } function saveRules() { @@ -47,6 +50,7 @@ export default function ContractDetailPage({ params }: { params: { id: string } saveContract(updated) setContract(updated) setShowEditRules(false) + trackEvent('rule_edit_saved', { contractId: params.id, ruleCount: editedRules.length }) } if (!mounted || !contract) return null @@ -166,7 +170,16 @@ export default function ContractDetailPage({ params }: { params: { id: string }

Edit Alert Rules

- + + trackEvent(action === 'remove' ? 'rule_removed' : 'rule_added', { + contractId: params.id, + ruleCount: rules.length, + }) + } + /> {rulesError &&

{rulesError}

}