Skip to content

feat: instrument the delegation funnel with Vercel Web Analytics - #809

Open
Jipperism wants to merge 3 commits into
livepeer:mainfrom
Jipperism:feat/722-Implement-Instrumentation-Plan
Open

Jipperism wants to merge 3 commits into
livepeer:mainfrom
Jipperism:feat/722-Implement-Instrumentation-Plan

Conversation

@Jipperism

Copy link
Copy Markdown
Collaborator

Closes #722

Summary

  • Adds @vercel/analytics (<Analytics /> in _app.tsx) and a typed trackVercelAnalyticsEvent() helper in lib/analytics.ts. Event properties stay non-identifying: no addresses, ENS names, tx hashes or error text.
  • Instruments 11 of the 13 funnel events from the plan: Orchestrators nav click (desktop + mobile drawer), Orchestrators page view, orchestrator detail view, wallet connect (with a coarse surface property), delegation form start, delegation tx submitted/confirmed/failed, Delegating tab view, redelegation started, and unbonding started.
  • All transaction events go through useHandleTransaction. A "Move Delegated Stake" bond counts as redelegation_started only, so it stays out of the delegation submitted → confirmed/failed conversion.
  • delegation_form_started fires once per widget mount, on the first clean → dirty transition.
  • Not implemented: earn_entry_point_clicked and delegation_review_opened, because the UI they depend on doesn't exist yet.

Test plan

  • pnpm typecheck, pnpm lint, pnpm test pass
  • In dev (Vercel Analytics debug mode), confirmed each of these fires once: nav click, Orchestrators page view, orchestrator detail view, form start (including after clearing and re-entering an amount), Delegating tab view
  • Wallet connect and the transaction events (delegate, undelegate, redelegate, and "Move Delegated Stake" → redelegation_started) still need a check with a real wallet
  • After deploy, check that custom events show up in the Vercel Analytics dashboard

🤖 Generated with Claude Code

@vercel

vercel Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

@Jipperism is attempting to deploy a commit to the Livepeer Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@Jipperism
Jipperism force-pushed the feat/722-Implement-Instrumentation-Plan branch 7 times, most recently from b6b8be9 to cb374a4 Compare September 19, 2026 02:06
@Jipperism
Jipperism marked this pull request as ready for review September 19, 2026 02:10
Copilot AI lite review requested due to automatic review settings September 19, 2026 02:10
@Jipperism

Copy link
Copy Markdown
Collaborator Author

@ECWireless ready for review

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.

Copilot review overview

🟡 Changes recommended

There are a couple of confirmed instrumentation correctness/data-quality gaps (notably route hydration causing double-fires and missing surface property on wallet_connected despite the PR description) that should be fixed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 3 Medium severity · 1 Low severity

Open (4)
What changed in this PR

Adds Vercel Web Analytics to instrument the Explorer delegation funnel, including a typed analytics helper and event emission from key UI surfaces (nav, orchestrator pages, wallet connect, form start, and transaction lifecycle).

Changes:

  • Added @vercel/analytics with <Analytics beforeSend={...} /> and a new lib/analytics.ts helper to centralize event tracking/redaction.
  • Instrumented funnel events across Orchestrators pages, Account tabs, wallet connect, delegation form start, and transaction stages via useHandleTransaction.
  • Extended transaction args to flag “Move Delegated Stake” (transfer-stake) so it maps to redelegation events.
File Description
package.json Adds @vercel/analytics dependency.
pnpm-lock.yaml Locks @vercel/analytics and related dependency updates.
pages/​_app.tsx Mounts Vercel <Analytics /> and applies URL redaction via beforeSend.
lib/​analytics.ts Introduces typed funnel event names, tracking helpers, URL redaction, and transaction→event mapping.
layouts/​main.tsx Instruments wallet connect and Orchestrators nav click (desktop + drawer item).
pages/​orchestrators.tsx Tracks Orchestrators index page view.
pages/​accounts/​[account]/​orchestrating.tsx Tracks orchestrator detail view once per account per session.
pages/​accounts/​[account]/​delegating.tsx Tracks “Delegating” tab view once for the connected user’s account.
components/​Drawer/​index.tsx Wires drawer item onClick for nav click instrumentation.
components/​DelegatingWidget/​index.tsx Tracks delegation form start on first clean→dirty transition per mount.
components/​DelegatingWidget/​Delegate.tsx Passes isTransferStake into tx args for redelegation classification.
hooks/​useExplorerStore.tsx Adds isTransferStake?: boolean to transaction input data.
hooks/​useHandleTransaction.tsx Routes submitted/confirmed/failed stages into analytics transaction tracking.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread layouts/main.tsx
Comment thread pages/accounts/[account]/orchestrating.tsx
Comment thread pages/orchestrators.tsx Outdated
Comment thread lib/analytics.ts Outdated
@vercel

vercel Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
explorer-arbitrum-one Ready Ready Preview Sep 21, 2026 2:34pm UTC

Request Review

Copilot AI review requested due to automatic review settings September 21, 2026 03:25
@Jipperism
Jipperism force-pushed the feat/722-Implement-Instrumentation-Plan branch from cb374a4 to 2be4407 Compare September 21, 2026 03:25
Adds custom events for the delegation funnel (nav click, page views,
wallet connect, form start, transaction submit/confirm/fail) per the
instrumentation plan in livepeer#722, so delegator UX changes can be measured
against a baseline instead of guessed at.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

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.

Copilot review overview

🟡 Changes recommended

The current confirmed/failed analytics emitted from useHandleTransaction appear to be driven by useWriteContract submission state and pre-submission errors rather than on-chain receipt outcomes, which will skew the funnel metrics.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity · 1 Low severity

Open (3)
Resolved since last review (2)
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

Comment thread hooks/useHandleTransaction.tsx
Copilot AI review requested due to automatic review settings September 21, 2026 03:31
@Jipperism
Jipperism force-pushed the feat/722-Implement-Instrumentation-Plan branch from 2be4407 to 342de40 Compare September 21, 2026 03:31

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.

Copilot review overview

🟡 Changes recommended

layouts/main.tsx still sends wallet addresses in Google Analytics page paths, which conflicts with the PR/issue’s non-identifying analytics intent and should be redacted similarly.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity · 1 Low severity

Open (3)
Resolved since last review (1)
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

Comment thread layouts/main.tsx
delegation_transaction_confirmed fired as soon as the wallet returned a
hash, so a delegation that later reverted on chain still counted as
confirmed and the submitted -> confirmed rate always read ~100%. Await the
receipt instead, outside React so the result is still tracked when the
sending component unmounts.

Rejected signatures and failed sends no longer count as failures either,
since neither ever submits a transaction, which keeps failures within
submissions.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings September 21, 2026 03:57

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.

Copilot review overview

🟡 Changes recommended

delegation_form_started can currently fire before a wallet is connected, which breaks the intended funnel sequencing and interpretation.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Low severity

Open (2)
Resolved since last review (2)
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file
Previously missed (1)

In code that hasn't changed since last review

Medium severity Gate delegation_form_started tracking on wallet connection

components/​DelegatingWidget/​index.tsx:11

delegation_form_started is currently able to fire even when no wallet is connected because the amount input is still editable without useAccountAddress(). That breaks the intended funnel ordering (wallet_connected �0% delegation_form_started) and makes the event harder to interpret; gate the tracking on a connected wallet address.

This issue also appears on line 79 of the same file.

Comment thread lib/analytics.ts

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.

Copilot review overview

🟡 Changes recommended

Transaction success/failure analytics classification can be inaccurate due to treating any receipt-wait error as an on-chain failure, which can skew funnel metrics.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity · 2 Low severity

Open (3)
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

Comment thread lib/analytics.ts
Comment on lines +139 to +143
// Rejects when the transaction reverts on chain.
waitForTransactionReceipt(config, { hash }).then(
() => confirmed && trackVercelAnalyticsEvent(confirmed),
() => failed && trackVercelAnalyticsEvent(failed)
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agreed on the RPC-error case. A failed receipt lookup doesn't mean the delegation failed, so it shouldn't emit delegation_transaction_failed. Wagmi already rejects reverted receipts; the remaining issue is distinguishing those from lookup errors.

@ECWireless ECWireless left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just requesting the transaction outcome and form-start fixes before merging so we can trust the baseline.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we gate delegation_form_started on wallet connection and reset it for a new delegation attempt? Currently, typing while disconnected fires the event, but submitting and starting another delegation in the same widget doesn't. The ticket calls for once per attempt after connecting.

Comment thread lib/analytics.ts

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we handle cancelled/replaced transactions in trackTransaction? A wallet cancellation can return a successful replacement receipt and currently gets counted as a confirmed delegation. We should only count confirmation when the delegation itself succeeds.

This branch was successfully deployed

1 active deployment
Preview 8231aed9 Deployed Sep 21, 2026 by vercel[bot]
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.

Implement Instrumentation Plan

3 participants