Metric for mixpanel whether it was own profile or someone elses#2106
Metric for mixpanel whether it was own profile or someone elses#2106GelatoGenesis merged 2 commits intomainfrom
Conversation
Signed-off-by: GelatoGenesis <tarmokalling@gmail.com>
📝 WalkthroughWalkthroughAdds helpers to determine profile ownership and viewer context, gates Mixpanel page-view tracking while profile data is loading, propagates fetchingProfile through auth usage, migrates components to the useAuth hook, and expands tests to cover ownership/visibility and analytics behavior. Changes
Sequence DiagramsequenceDiagram
participant User
participant Page
participant MixpanelSetup
participant ProfileHelpers
participant Mixpanel
User->>Page: Navigate to profile route
Page->>MixpanelSetup: Initialize with route & auth state
MixpanelSetup->>MixpanelSetup: Extract first path segment (handleOrWallet)
MixpanelSetup->>MixpanelSetup: Check fetchingProfile
alt fetchingProfile is true
MixpanelSetup->>MixpanelSetup: Skip tracking until profile loads
else fetchingProfile is false
MixpanelSetup->>ProfileHelpers: getProfileViewerContext(connectedProfile, handleOrWallet)
ProfileHelpers-->>MixpanelSetup: "self" / "other" / "anonymous"
MixpanelSetup->>Mixpanel: trackPageView(payload with profile_viewer_context)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@components/user/layout/UserPageTabs.tsx`:
- Around line 83-90: The ownership check currently treats ownership as false
while auth is still loading because isOwnProfileRoute({ connectedProfile,
handleOrWallet }) runs before profile fetch completes; update the logic to avoid
a false-negative by either (A) include fetchingProfile from useAuth and compute
isOwnProfile only when fetchingProfile === false (e.g., return undefined/null
while fetching), or (B) change the useMemo to depend on fetchingProfile and call
isOwnProfileRoute only when fetchingProfile is false, and then ensure any
redirect/hidden-tab logic that reads isOwnProfile only runs when fetchingProfile
=== false; reference the useAuth hook values (connectedProfile,
fetchingProfile), the isOwnProfile useMemo, and isOwnProfileRoute function to
implement the guard.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d2ace9eb-0485-4179-bb15-dbec64ee5fba
📒 Files selected for processing (6)
__tests__/components/providers/MixpanelSetup.test.tsx__tests__/components/user/layout/UserPageTabs.test.tsx__tests__/helpers/ProfileHelpers.extra.test.tscomponents/providers/MixpanelSetup.tsxcomponents/user/layout/UserPageTabs.tsxhelpers/ProfileHelpers.ts
Signed-off-by: GelatoGenesis <tarmokalling@gmail.com>
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
components/providers/MixpanelSetup.tsx (1)
17-19: Use the[user]route param instead of splittingpathname.This duplicates route parsing and bypasses Next’s param decoding, so
profile_viewer_contextcan drift for encoded handles or if the profile URL shape ever gains an extra prefix.components/user/layout/UserPageTabs.tsxalready readsparams.user; reusing that here keeps analytics aligned with the UI ownership logic.♻️ Proposed refactor
-import { usePathname, useSearchParams } from "next/navigation"; +import { useParams, usePathname, useSearchParams } from "next/navigation"; import { useEffect, useRef } from "react"; - -const getProfileRouteTarget = (pathname: string): string | null => { - return pathname.split("/").find((segment) => segment.length > 0) ?? null; -}; export default function MixpanelSetup() { + const params = useParams(); const pathname = usePathname(); const searchParams = useSearchParams(); const { connectedProfile, fetchingProfile } = useAuth(); + const handleOrWallet = params?.["user"]?.toString(); const profileViewerContext = pageView.logicalPage.startsWith("profile_") ? getProfileViewerContext({ connectedProfile, - handleOrWallet: getProfileRouteTarget(pathname), + handleOrWallet, }) : null;Also applies to: 33-37
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@components/providers/MixpanelSetup.tsx` around lines 17 - 19, The current getProfileRouteTarget function parses the pathname by splitting it, which duplicates routing logic and can mis-handle encoded usernames; replace this by using Next's decoded [user] route param (params.user) instead: stop splitting pathname in getProfileRouteTarget (or remove it) and change callers in MixpanelSetup (and the other occurrence at lines 33-37) to receive and use the decoded params.user value coming from components/user/layout/UserPageTabs.tsx (or the page params) when building profile_viewer_context so analytics always use the canonical decoded route param.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@components/providers/MixpanelSetup.tsx`:
- Around line 17-19: The current getProfileRouteTarget function parses the
pathname by splitting it, which duplicates routing logic and can mis-handle
encoded usernames; replace this by using Next's decoded [user] route param
(params.user) instead: stop splitting pathname in getProfileRouteTarget (or
remove it) and change callers in MixpanelSetup (and the other occurrence at
lines 33-37) to receive and use the decoded params.user value coming from
components/user/layout/UserPageTabs.tsx (or the page params) when building
profile_viewer_context so analytics always use the canonical decoded route
param.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e83bab38-529b-4b85-8416-d5a117d4700f
📒 Files selected for processing (3)
__tests__/components/user/layout/UserPageTabs.test.tsxcomponents/providers/MixpanelSetup.tsxcomponents/user/layout/UserPageTabs.tsx



Summary by CodeRabbit
New Features
Refactor
Tests