Skip to content

Metric for mixpanel whether it was own profile or someone elses#2106

Merged
GelatoGenesis merged 2 commits intomainfrom
b-17733152543
Mar 12, 2026
Merged

Metric for mixpanel whether it was own profile or someone elses#2106
GelatoGenesis merged 2 commits intomainfrom
b-17733152543

Conversation

@GelatoGenesis
Copy link
Copy Markdown
Collaborator

@GelatoGenesis GelatoGenesis commented Mar 12, 2026

Summary by CodeRabbit

  • New Features

    • Analytics now distinguish self vs. other profile views and include viewer context; page view tracking defers until profile ownership data is available.
  • Refactor

    • Switched authentication usage from context wrapper to hook-based approach; ownership checks centralized into a reusable helper.
  • Tests

    • Expanded tests for profile ownership, viewer context, conditional tracking, tab visibility during ownership loading, and related routing behavior.

Signed-off-by: GelatoGenesis <tarmokalling@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Profile Helpers
helpers/ProfileHelpers.ts
Adds isOwnProfileRoute and getProfileViewerContext to normalize handle/wallet targets and determine viewer context ("self", "other", "anonymous").
Analytics / Mixpanel
components/providers/MixpanelSetup.tsx
Compute profile viewer context for profile pages, include profile_viewer_context in analytics payload, and skip tracking while fetchingProfile is true.
User Tabs & Ownership
components/user/layout/UserPageTabs.tsx
Switches from AuthContext to useAuth, delegates ownership checks to isOwnProfileRoute, changes visibility logic to preserve PROXY tab while ownership loads, and uses USER_PAGE_TAB_IDS-based tab handling.
Tests — Mixpanel & Auth
__tests__/components/providers/MixpanelSetup.test.tsx
Adds richer connectedProfile mock (normalized handle, wallets), fetchingProfile flag propagation, and tests for anonymous/signed-in views, self vs other detection, and deferred tracking while ownership data loads.
Tests — UserPageTabs
__tests__/components/user/layout/UserPageTabs.test.tsx
Replaces AuthContext.Provider with direct useAuth mock, refactors render helper to accept options including fetchingProfile, and adds tests for ownership-loading visibility and redirect behavior.
Tests — Profile Helpers & Mapping
__tests__/helpers/ProfileHelpers.extra.test.ts
Adds tests for isOwnProfileRoute and getProfileViewerContext, expands mapping tests for profileAndConsolidationsToProfileMin to validate field transformations and undefined/null expectations.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • analyticsflowee
  • prxt6529
  • ragnep

Poem

🐰 I hop where profiles bloom and hide,

self, other, anonymous—what's inside?
I sniff the handle, check each wallet clue,
then whisper to Mixpanel what the viewer knew.
Hooray for clearer hops and analytics too!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding a metric to track whether a Mixpanel page view was for the user's own profile or someone else's profile, which aligns with the core functionality implemented across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch b-17733152543

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.

❤️ Share

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

Copy link
Copy Markdown

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6fe7734 and 4549da1.

📒 Files selected for processing (6)
  • __tests__/components/providers/MixpanelSetup.test.tsx
  • __tests__/components/user/layout/UserPageTabs.test.tsx
  • __tests__/helpers/ProfileHelpers.extra.test.ts
  • components/providers/MixpanelSetup.tsx
  • components/user/layout/UserPageTabs.tsx
  • helpers/ProfileHelpers.ts

Comment thread components/user/layout/UserPageTabs.tsx Outdated
Signed-off-by: GelatoGenesis <tarmokalling@gmail.com>
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
components/providers/MixpanelSetup.tsx (1)

17-19: Use the [user] route param instead of splitting pathname.

This duplicates route parsing and bypasses Next’s param decoding, so profile_viewer_context can drift for encoded handles or if the profile URL shape ever gains an extra prefix. components/user/layout/UserPageTabs.tsx already reads params.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

📥 Commits

Reviewing files that changed from the base of the PR and between 4549da1 and 967e502.

📒 Files selected for processing (3)
  • __tests__/components/user/layout/UserPageTabs.test.tsx
  • components/providers/MixpanelSetup.tsx
  • components/user/layout/UserPageTabs.tsx

@GelatoGenesis GelatoGenesis merged commit ad964dd into main Mar 12, 2026
7 checks passed
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.

2 participants