Skip to content

Conversation

@MananTank
Copy link
Member

@MananTank MananTank commented Sep 18, 2025


PR-Codex overview

This PR focuses on enhancing analytics tracking by adding a new component, ChainPageView, to report page views for specific chains, and integrating it into the ChainPageLayout. It also introduces additional reporting functionality for swap widgets.

Detailed summary

  • Added ChainPageView component to report chain page views.
  • Integrated ChainPageView in ChainPageLayout.
  • Implemented reportChainPageview function in report.ts for analytics.
  • Enhanced BuyAndSwapEmbed to report when the swap widget is shown.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • Chores
    • Added one-time telemetry when the Swap widget is displayed to improve usage insights.
    • Tracks the page context (asset, bridge, or chain) when the widget first appears.
    • Added one-time telemetry to record chain pageviews (captures the chain identifier) when visiting chain pages.
    • Integrated with existing UI; no impact on behavior, user action, or performance.

@vercel
Copy link

vercel bot commented Sep 18, 2025

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

Project Deployment Preview Comments Updated (UTC)
thirdweb-www Ready Ready Preview Comment Sep 18, 2025 9:10pm
4 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
docs-v2 Skipped Skipped Sep 18, 2025 9:10pm
nebula Skipped Skipped Sep 18, 2025 9:10pm
thirdweb_playground Skipped Skipped Sep 18, 2025 9:10pm
wallet-ui Skipped Skipped Sep 18, 2025 9:10pm

@vercel vercel bot temporarily deployed to Preview – docs-v2 September 18, 2025 20:17 Inactive
@vercel vercel bot temporarily deployed to Preview – nebula September 18, 2025 20:17 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground September 18, 2025 20:17 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-ui September 18, 2025 20:17 Inactive
@changeset-bot
Copy link

changeset-bot bot commented Sep 18, 2025

⚠️ No Changeset found

Latest commit: f3b3b89

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@MananTank MananTank marked this pull request as ready for review September 18, 2025 20:17
@MananTank MananTank requested review from a team as code owners September 18, 2025 20:17
@github-actions github-actions bot added the Dashboard Involves changes to the Dashboard. label Sep 18, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 18, 2025

Walkthrough

Adds two analytics reporters—reportSwapWidgetShown and reportChainPageview—and instruments the UI to emit those events once: BuyAndSwapEmbed reports the swap widget being shown on first mount, and ChainPageView reports a chain pageview on mount; layout mounts ChainPageView.

Changes

Cohort / File(s) Summary
Analytics reporters
apps/dashboard/src/@/analytics/report.ts
Adds reportSwapWidgetShown(properties: { pageType: "asset" | "bridge" | "chain" }) and reportChainPageview(properties: { chainId: number }), both calling posthog.capture with their respective payloads.
Swap widget mount telemetry
apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
Imports and invokes reportSwapWidgetShown({ pageType }) once on initial mount using useEffect + useRef guard.
Chain pageview component
apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/chain-pageview.tsx
Adds export function ChainPageView(props: { chainId: number }) — a client component that calls reportChainPageview({ chainId }) once on mount and returns null.
Layout instrumentation
apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/layout.tsx
Imports and renders <ChainPageView chainId={chain.chainId} /> as the first child in the chain page layout (additive).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant R as React (BuyAndSwapEmbed)
  participant AR as reportSwapWidgetShown
  participant PH as PostHog

  R->>R: mount()
  Note over R: useEffect runs once (guarded by isMounted)
  R->>AR: reportSwapWidgetShown({ pageType })
  AR->>PH: posthog.capture("swap widget shown", { pageType })
  PH-->>AR: ack
Loading
sequenceDiagram
  autonumber
  participant L as Layout (chain page)
  participant C as ChainPageView
  participant AR2 as reportChainPageview
  participant PH as PostHog

  L->>C: render with chainId
  C->>C: mount()
  C->>AR2: reportChainPageview({ chainId })
  AR2->>PH: posthog.capture("chain pageview", { chainId })
  PH-->>AR2: ack
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description contains the repository's commented template and a PR-Codex overview summarizing the code changes, but it does not populate the required template sections such as "Notes for the reviewer" and "How to test," leaving reviewers without explicit testing instructions or reviewer notes. Please populate the template before merge: add the issue tag or Linear ID if applicable, fill "Notes for the reviewer" with rationale and any risks or deployment considerations, and provide a "How to test" section with concrete manual steps, commands to run unit/integration tests, and the expected telemetry events so reviewers can validate the changes.
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Dashboard: Add tracking for SwapWidget impression, chain pageview" is concise and directly describes the primary changes — adding analytics for Swap widget impressions and chain pageviews — and matches the functions and components added in the changeset.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 09-19-dashboard_add_tracking_for_swapwidget_impression

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codecov
Copy link

codecov bot commented Sep 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.35%. Comparing base (4482692) to head (f3b3b89).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8071   +/-   ##
=======================================
  Coverage   56.35%   56.35%           
=======================================
  Files         906      906           
  Lines       59168    59168           
  Branches     4172     4172           
=======================================
  Hits        33342    33342           
  Misses      25720    25720           
  Partials      106      106           
Flag Coverage Δ
packages 56.35% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 18, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 63.96 KB (0%) 1.3 s (0%) 1.7 s (+7.32% 🔺) 3 s
thirdweb (cjs) 361.44 KB (0%) 7.3 s (0%) 13.7 s (-0.55% 🔽) 20.9 s
thirdweb (minimal + tree-shaking) 5.73 KB (0%) 115 ms (0%) 113 ms (+39.12% 🔺) 228 ms
thirdweb/chains (tree-shaking) 526 B (0%) 11 ms (0%) 84 ms (+142.55% 🔺) 94 ms
thirdweb/react (minimal + tree-shaking) 19.14 KB (0%) 383 ms (0%) 186 ms (+91.56% 🔺) 569 ms

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
apps/dashboard/src/@/analytics/report.ts (1)

266-270: Reuse existing PageType union and add an explicit return type.

Keep types DRY and meet the “explicit return type” guideline.

Apply this diff:

-export function reportSwapWidgetShown(properties: {
-  pageType: "asset" | "bridge" | "chain";
-}) {
-  posthog.capture("swap widget shown", properties);
-}
+export function reportSwapWidgetShown(properties: {
+  pageType: TokenSwapParams["pageType"];
+}): void {
+  posthog.capture("swap widget shown", properties);
+}
apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx (1)

31-43: Gate the impression to when the Swap tab is actually visible; drop the lint suppression.

Currently this fires on initial mount even if the tab default changes later. Track once when Swap is shown and remove the eslint disable.

Apply this diff:

-  const isMounted = useRef(false);
-
-  // eslint-disable-next-line no-restricted-syntax
-  useEffect(() => {
-    if (isMounted.current) {
-      return;
-    }
-    isMounted.current = true;
-    reportSwapWidgetShown({
-      pageType: props.pageType,
-    });
-  }, [props.pageType]);
+  const hasTrackedSwapShown = useRef(false);
+
+  useEffect(() => {
+    if (hasTrackedSwapShown.current || tab !== "swap") {
+      return;
+    }
+    hasTrackedSwapShown.current = true;
+    reportSwapWidgetShown({ pageType: props.pageType });
+  }, [tab, props.pageType]);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4482692 and 7db060a.

📒 Files selected for processing (2)
  • apps/dashboard/src/@/analytics/report.ts (1 hunks)
  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity
Re-use shared types from @/types or local types.ts barrels
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial, Pick, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose

**/*.{ts,tsx}: Use explicit function declarations and explicit return types in TypeScript
Limit each file to one stateless, single‑responsibility function
Re‑use shared types from @/types where applicable
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics when possible
Prefer composition over inheritance; use utility types (Partial, Pick, etc.)
Lazy‑import optional features and avoid top‑level side‑effects to reduce bundle size

Files:

  • apps/dashboard/src/@/analytics/report.ts
  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)

Files:

  • apps/dashboard/src/@/analytics/report.ts
  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
apps/{dashboard,playground-web}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

apps/{dashboard,playground-web}/**/*.{ts,tsx}: Import UI primitives from @/components/ui/* (Button, Input, Select, Tabs, Card, Sidebar, Badge, Separator) in dashboard and playground apps
Use NavLink for internal navigation with automatic active states in dashboard and playground apps
Use Tailwind CSS only – no inline styles or CSS modules
Use cn() from @/lib/utils for conditional class logic
Use design system tokens (e.g., bg-card, border-border, text-muted-foreground)
Server Components (Node edge): Start files with import "server-only";
Client Components (browser): Begin files with 'use client';
Always call getAuthToken() to retrieve JWT from cookies on server side
Use Authorization: Bearer header – never embed tokens in URLs
Return typed results (e.g., Project[], User[]) – avoid any
Wrap client-side data fetching calls in React Query (@tanstack/react-query)
Use descriptive, stable queryKeys for React Query cache hits
Configure staleTime/cacheTime in React Query based on freshness (default ≥ 60s)
Keep tokens secret via internal API routes or server actions
Never import posthog-js in server components

Files:

  • apps/dashboard/src/@/analytics/report.ts
  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
apps/{dashboard,playground}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

apps/{dashboard,playground}/**/*.{ts,tsx}: Import UI primitives from @/components/ui/_ (e.g., Button, Input, Tabs, Card)
Use NavLink for internal navigation to get active state handling
Use Tailwind CSS for styling; no inline styles
Merge class names with cn() from @/lib/utils for conditional classes
Stick to design tokens (e.g., bg-card, border-border, text-muted-foreground)
Server Components must start with import "server-only"; use next/headers, server‑only env, heavy data fetching, and redirect() where appropriate
Client Components must start with 'use client'; handle interactivity with hooks and browser APIs
Server-side data fetching: call getAuthToken() from cookies, send Authorization: Bearer <token> header, and return typed results (avoid any)
Client-side data fetching: wrap calls in React Query with descriptive, stable queryKeys and set sensible staleTime/cacheTime (≥ 60s default); keep tokens secret via internal routes or server actions
Do not import posthog-js in server components (client-side only)

Files:

  • apps/dashboard/src/@/analytics/report.ts
  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
apps/{dashboard,playground}/src/@/analytics/report.ts

📄 CodeRabbit inference engine (AGENTS.md)

apps/{dashboard,playground}/src/@/analytics/report.ts: Check report.ts before adding a new analytics event to avoid duplicates
Analytics naming: event name as <subject> <verb>; helper function as report<Subject><Verb> (PascalCase)
Each analytics helper must include a JSDoc header (Why/Owner), accept a single typed properties object, and forward it unchanged to posthog.capture

Files:

  • apps/dashboard/src/@/analytics/report.ts
apps/{dashboard,playground}/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

Expose a className prop on the root element of every component

Files:

  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
🧠 Learnings (12)
📚 Learning: 2025-08-29T15:37:38.513Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: AGENTS.md:0-0
Timestamp: 2025-08-29T15:37:38.513Z
Learning: Applies to apps/{dashboard,playground}/src/@/analytics/report.ts : Check `report.ts` before adding a new analytics event to avoid duplicates

Applied to files:

  • apps/dashboard/src/@/analytics/report.ts
📚 Learning: 2025-08-29T15:37:38.513Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: AGENTS.md:0-0
Timestamp: 2025-08-29T15:37:38.513Z
Learning: Applies to apps/{dashboard,playground}/src/@/analytics/report.ts : Each analytics helper must include a JSDoc header (Why/Owner), accept a single typed `properties` object, and forward it unchanged to `posthog.capture`

Applied to files:

  • apps/dashboard/src/@/analytics/report.ts
📚 Learning: 2025-07-18T19:19:55.613Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to src/@/analytics/report.ts : Review `src/@/analytics/report.ts` before adding analytics events to check for duplicates

Applied to files:

  • apps/dashboard/src/@/analytics/report.ts
  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
📚 Learning: 2025-08-29T15:37:38.513Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: AGENTS.md:0-0
Timestamp: 2025-08-29T15:37:38.513Z
Learning: Applies to apps/{dashboard,playground}/src/@/analytics/report.ts : Analytics naming: event name as `<subject> <verb>`; helper function as `report<Subject><Verb>` (PascalCase)

Applied to files:

  • apps/dashboard/src/@/analytics/report.ts
📚 Learning: 2025-07-18T19:20:32.530Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-18T19:20:32.530Z
Learning: Applies to dashboard/src/@/analytics/report.ts : Typed properties: accept a single `properties` object and pass it unchanged to `posthog.capture`.

Applied to files:

  • apps/dashboard/src/@/analytics/report.ts
📚 Learning: 2025-07-18T19:19:55.613Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to src/@/analytics/report.ts : Analytics event name: human-readable `<subject> <verb>` (e.g., "contract deployed"); function: `report<Subject><Verb>` (PascalCase)

Applied to files:

  • apps/dashboard/src/@/analytics/report.ts
📚 Learning: 2025-07-18T19:20:32.530Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-18T19:20:32.530Z
Learning: Applies to dashboard/src/@/analytics/report.ts : Mandatory JSDoc: explain Why the event exists and Who owns it (`username`).

Applied to files:

  • apps/dashboard/src/@/analytics/report.ts
📚 Learning: 2025-07-18T19:20:32.530Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-18T19:20:32.530Z
Learning: Applies to dashboard/src/@/analytics/report.ts : Reporting helper: `report<Subject><Verb>` (PascalCase); all live in `src/@/analytics/report.ts`.

Applied to files:

  • apps/dashboard/src/@/analytics/report.ts
📚 Learning: 2025-07-18T19:20:32.530Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-18T19:20:32.530Z
Learning: Applies to dashboard/**/*client.tsx : Interactive UI that relies on hooks (`useState`, `useEffect`, React Query, wallet hooks).

Applied to files:

  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
📚 Learning: 2025-07-18T19:20:32.530Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-18T19:20:32.530Z
Learning: Applies to dashboard/**/*client.tsx : Anything that consumes hooks from `tanstack/react-query` or thirdweb SDKs.

Applied to files:

  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
📚 Learning: 2025-09-17T11:14:35.659Z
Learnt from: MananTank
PR: thirdweb-dev/js#8044
File: packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx:919-930
Timestamp: 2025-09-17T11:14:35.659Z
Learning: In the thirdweb codebase, useCustomTheme() hook can be used inside styled-components callbacks, contrary to the general React Rules of Hooks. This is a valid pattern in their implementation.

Applied to files:

  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
📚 Learning: 2025-07-18T19:20:32.530Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-18T19:20:32.530Z
Learning: Applies to dashboard/**/components/*.client.tsx : Client components must start with `'use client';` before imports.

Applied to files:

  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
🧬 Code graph analysis (1)
apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx (1)
apps/dashboard/src/@/analytics/report.ts (1)
  • reportSwapWidgetShown (266-270)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Size
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Lint Packages
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (4)
apps/dashboard/src/@/analytics/report.ts (2)

258-270: Event helper aligns with our analytics conventions.

  • Good JSDoc (Why/Owner), single typed properties object, correct naming ("swap widget shown"/reportSwapWidgetShown), forwards properties unchanged.

258-270: Duplicate check — no other "swap widget shown" events found

Only occurrences: apps/dashboard/src/@/analytics/report.ts (definition) and apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx (import + call).

apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx (2)

4-4: Import additions look correct.

useEffect/useRef are needed for the one-time impression guard.


11-11: Correct reporter import.

Matches the new helper and local usage.

@MananTank MananTank force-pushed the 09-19-dashboard_add_tracking_for_swapwidget_impression branch from 7db060a to ce6c4c6 Compare September 18, 2025 20:53
@MananTank MananTank changed the title Dashboard: Add tracking for SwapWidget impression Dashboard: Add tracking for SwapWidget impression, chain pageview Sep 18, 2025
@vercel vercel bot temporarily deployed to Preview – wallet-ui September 18, 2025 20:53 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground September 18, 2025 20:53 Inactive
@vercel vercel bot temporarily deployed to Preview – nebula September 18, 2025 20:53 Inactive
@vercel vercel bot temporarily deployed to Preview – docs-v2 September 18, 2025 20:53 Inactive
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx (2)

31-42: Replace manual mount guard with useEffectOnce; drop eslint-disable.

Cleaner and consistent with our hooks library. Avoids the local ref and linter override.

-import { useEffect, useRef, useState } from "react";
+import { useRef, useState } from "react";
+import { useEffectOnce } from "@/hooks/useEffectOnce";
@@
-  const isMounted = useRef(false);
-
-  // eslint-disable-next-line no-restricted-syntax
-  useEffect(() => {
-    if (isMounted.current) {
-      return;
-    }
-    isMounted.current = true;
-    reportSwapWidgetShown({
-      pageType: props.pageType,
-    });
-  }, [props.pageType]);
+  useEffectOnce(() => {
+    reportSwapWidgetShown({ pageType: props.pageType });
+  });

Also applies to: 4-4


33-42: Optional: Track only when the Swap tab is actually visible.

If “impression” means visible widget (not merely mount), gate on the active tab and fire once.

-  // eslint-disable-next-line no-restricted-syntax
-  useEffect(() => {
-    if (isMounted.current) {
-      return;
-    }
-    isMounted.current = true;
-    reportSwapWidgetShown({
-      pageType: props.pageType,
-    });
-  }, [props.pageType]);
+  const hasTrackedSwapShown = useRef(false);
+  useEffect(() => {
+    if (tab !== "swap" || hasTrackedSwapShown.current) return;
+    hasTrackedSwapShown.current = true;
+    reportSwapWidgetShown({ pageType: props.pageType });
+  }, [tab, props.pageType]);

Also applies to: 29-29

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/layout.tsx (1)

27-27: Mark this layout as server-only.

Prevents accidental client bundling per our guidelines for server components.

+import "server-only";
apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/chain-pageview.tsx (1)

1-13: Add explicit return type and a named props alias.

Aligns with our TS guidelines; improves readability.

 "use client";
-import { reportChainPageview } from "@/analytics/report";
+import { reportChainPageview } from "@/analytics/report";
+import type { ReactElement } from "react";
 import { useEffectOnce } from "@/hooks/useEffectOnce";
 
-export function ChainPageView(props: { chainId: number }) {
+type ChainPageViewProps = { chainId: number };
+
+export function ChainPageView(props: ChainPageViewProps): ReactElement | null {
   useEffectOnce(() => {
     reportChainPageview({
       chainId: props.chainId,
     });
   });
 
   return null;
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7db060a and ce6c4c6.

📒 Files selected for processing (4)
  • apps/dashboard/src/@/analytics/report.ts (2 hunks)
  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx (2 hunks)
  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/chain-pageview.tsx (1 hunks)
  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/layout.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/dashboard/src/@/analytics/report.ts
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity
Re-use shared types from @/types or local types.ts barrels
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial, Pick, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose

**/*.{ts,tsx}: Use explicit function declarations and explicit return types in TypeScript
Limit each file to one stateless, single‑responsibility function
Re‑use shared types from @/types where applicable
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics when possible
Prefer composition over inheritance; use utility types (Partial, Pick, etc.)
Lazy‑import optional features and avoid top‑level side‑effects to reduce bundle size

Files:

  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/chain-pageview.tsx
  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/layout.tsx
  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)

Files:

  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/chain-pageview.tsx
  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/layout.tsx
  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
apps/{dashboard,playground-web}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

apps/{dashboard,playground-web}/**/*.{ts,tsx}: Import UI primitives from @/components/ui/* (Button, Input, Select, Tabs, Card, Sidebar, Badge, Separator) in dashboard and playground apps
Use NavLink for internal navigation with automatic active states in dashboard and playground apps
Use Tailwind CSS only – no inline styles or CSS modules
Use cn() from @/lib/utils for conditional class logic
Use design system tokens (e.g., bg-card, border-border, text-muted-foreground)
Server Components (Node edge): Start files with import "server-only";
Client Components (browser): Begin files with 'use client';
Always call getAuthToken() to retrieve JWT from cookies on server side
Use Authorization: Bearer header – never embed tokens in URLs
Return typed results (e.g., Project[], User[]) – avoid any
Wrap client-side data fetching calls in React Query (@tanstack/react-query)
Use descriptive, stable queryKeys for React Query cache hits
Configure staleTime/cacheTime in React Query based on freshness (default ≥ 60s)
Keep tokens secret via internal API routes or server actions
Never import posthog-js in server components

Files:

  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/chain-pageview.tsx
  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/layout.tsx
  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
apps/{dashboard,playground}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

apps/{dashboard,playground}/**/*.{ts,tsx}: Import UI primitives from @/components/ui/_ (e.g., Button, Input, Tabs, Card)
Use NavLink for internal navigation to get active state handling
Use Tailwind CSS for styling; no inline styles
Merge class names with cn() from @/lib/utils for conditional classes
Stick to design tokens (e.g., bg-card, border-border, text-muted-foreground)
Server Components must start with import "server-only"; use next/headers, server‑only env, heavy data fetching, and redirect() where appropriate
Client Components must start with 'use client'; handle interactivity with hooks and browser APIs
Server-side data fetching: call getAuthToken() from cookies, send Authorization: Bearer <token> header, and return typed results (avoid any)
Client-side data fetching: wrap calls in React Query with descriptive, stable queryKeys and set sensible staleTime/cacheTime (≥ 60s default); keep tokens secret via internal routes or server actions
Do not import posthog-js in server components (client-side only)

Files:

  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/chain-pageview.tsx
  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/layout.tsx
  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
apps/{dashboard,playground}/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

Expose a className prop on the root element of every component

Files:

  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/chain-pageview.tsx
  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/layout.tsx
  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
🧠 Learnings (7)
📚 Learning: 2025-07-18T19:20:32.530Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-18T19:20:32.530Z
Learning: Applies to dashboard/**/*client.tsx : Interactive UI that relies on hooks (`useState`, `useEffect`, React Query, wallet hooks).

Applied to files:

  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/chain-pageview.tsx
  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
📚 Learning: 2025-08-29T23:44:47.512Z
Learnt from: MananTank
PR: thirdweb-dev/js#7951
File: apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/_layout/contract-page-layout.tsx:38-38
Timestamp: 2025-08-29T23:44:47.512Z
Learning: The ContractPageLayout component in apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/_layout/contract-page-layout.tsx is not the root layout - it's nested within the dashboard layout which already handles footer positioning with min-h-dvh and AppFooter placement. The ContractPageLayout needs flex flex-col grow to properly participate in the parent's flex layout.

Applied to files:

  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/layout.tsx
📚 Learning: 2025-07-18T19:20:32.530Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-18T19:20:32.530Z
Learning: Applies to dashboard/**/layout.tsx : Building layout shells (`layout.tsx`) and top-level pages that mainly assemble data.

Applied to files:

  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/layout.tsx
📚 Learning: 2025-07-18T19:20:32.530Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-18T19:20:32.530Z
Learning: Applies to dashboard/**/*.{tsx,jsx} : Layouts should reuse `SidebarLayout` / `FullWidthSidebarLayout` (`@/components/blocks/SidebarLayout`).

Applied to files:

  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/layout.tsx
📚 Learning: 2025-07-18T19:19:55.613Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to src/@/analytics/report.ts : Review `src/@/analytics/report.ts` before adding analytics events to check for duplicates

Applied to files:

  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
📚 Learning: 2025-07-18T19:20:32.530Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-18T19:20:32.530Z
Learning: Applies to dashboard/**/*client.tsx : Anything that consumes hooks from `tanstack/react-query` or thirdweb SDKs.

Applied to files:

  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
📚 Learning: 2025-09-17T11:14:35.659Z
Learnt from: MananTank
PR: thirdweb-dev/js#8044
File: packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx:919-930
Timestamp: 2025-09-17T11:14:35.659Z
Learning: In the thirdweb codebase, useCustomTheme() hook can be used inside styled-components callbacks, contrary to the general React Rules of Hooks. This is a valid pattern in their implementation.

Applied to files:

  • apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
🧬 Code graph analysis (3)
apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/chain-pageview.tsx (2)
apps/dashboard/src/@/hooks/useEffectOnce.ts (1)
  • useEffectOnce (5-14)
apps/dashboard/src/@/analytics/report.ts (1)
  • reportChainPageview (554-556)
apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/layout.tsx (1)
apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/chain-pageview.tsx (1)
  • ChainPageView (5-13)
apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx (1)
apps/dashboard/src/@/analytics/report.ts (1)
  • reportSwapWidgetShown (266-270)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Size
  • GitHub Check: Lint Packages
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (4)
apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx (2)

11-11: Import + usage look correct.

Event payload type aligns with reporter signature.


39-42: Event-name uniqueness verified — single "swap widget shown" reporter & single call

reportSwapWidgetShown is defined once (apps/dashboard/src/@/analytics/report.ts lines 266–269) using posthog.capture("swap widget shown") and is only invoked from apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx (line 39); no duplicate captures found.

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/layout.tsx (1)

27-27: LGTM: Client tracker is imported and rendered early.

Placing ChainPageView first ensures pageview fires on mount.

Also applies to: 75-75

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/chain-pageview.tsx (1)

5-10: LGTM: One-time pageview with useEffectOnce.

Matches the reporter’s contract; no UI side effects.

@graphite-app
Copy link
Contributor

graphite-app bot commented Sep 18, 2025

Merge activity

)

<!--

## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes"

If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000):

## Notes for the reviewer

Anything important to call out? Be sure to also clarify these in your comments.

## How to test

Unit tests, playground, etc.

-->

<!-- start pr-codex -->

---

## PR-Codex overview
This PR introduces analytics tracking for chain page views and enhances the reporting for swap widgets in the dashboard application.

### Detailed summary
- Added `ChainPageView` component to track impressions of chain pages.
- Integrated `reportChainPageview` function in the analytics module.
- Enhanced `BuyAndSwapEmbed` to report when the swap widget is shown.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- Chores
  - Added one-time telemetry when the Swap widget is displayed to improve usage insights.
  - Tracks the page context (asset, bridge, or chain) when the widget first appears.
  - Added one-time telemetry to record chain pageviews (captures the chain identifier) when visiting chain pages.
  - Integrated with existing UI; no impact on behavior, user action, or performance.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@graphite-app graphite-app bot force-pushed the 09-19-dashboard_add_tracking_for_swapwidget_impression branch from ce6c4c6 to f3b3b89 Compare September 18, 2025 21:03
@vercel vercel bot temporarily deployed to Preview – wallet-ui September 18, 2025 21:03 Inactive
@vercel vercel bot temporarily deployed to Preview – nebula September 18, 2025 21:03 Inactive
@vercel vercel bot temporarily deployed to Preview – docs-v2 September 18, 2025 21:03 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground September 18, 2025 21:03 Inactive
@graphite-app graphite-app bot merged commit f3b3b89 into main Sep 18, 2025
24 checks passed
@graphite-app graphite-app bot deleted the 09-19-dashboard_add_tracking_for_swapwidget_impression branch September 18, 2025 21:11
@vercel vercel bot temporarily deployed to Production – nebula September 18, 2025 21:11 Inactive
@vercel vercel bot temporarily deployed to Production – wallet-ui September 18, 2025 21:11 Inactive
@vercel vercel bot temporarily deployed to Production – docs-v2 September 18, 2025 21:11 Inactive
@vercel vercel bot temporarily deployed to Production – thirdweb_playground September 18, 2025 21:11 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dashboard Involves changes to the Dashboard.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants