Skip to content

Logical page views for mixpanel#2079

Merged
GelatoGenesis merged 3 commits intomainfrom
b-17730449643
Mar 9, 2026
Merged

Logical page views for mixpanel#2079
GelatoGenesis merged 3 commits intomainfrom
b-17730449643

Conversation

@GelatoGenesis
Copy link
Copy Markdown
Collaborator

@GelatoGenesis GelatoGenesis commented Mar 9, 2026

Summary by CodeRabbit

  • New Features

    • Enhanced analytics: page views now include logical page, page group, and route pattern metadata for finer reporting.
    • Tracks drop-detail views when a drop query is present, and re-tracks when the drop query changes.
  • Tests

    • Added comprehensive page-classification tests covering waves, drop details, profiles, and fallback routes.
    • Added test support for query-parameter-driven view differentiation.

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

coderabbitai Bot commented Mar 9, 2026

Warning

Rate limit exceeded

@GelatoGenesis has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 20 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 38515823-9b4a-4cc9-bab1-bdf3c4ed9882

📥 Commits

Reviewing files that changed from the base of the PR and between ea159aa and 0746f66.

📒 Files selected for processing (1)
  • services/analytics/pageClassification.ts
📝 Walkthrough

Walkthrough

Adds a new page classification service and integrates it into MixpanelSetup to produce richer page view metadata (logical_page, page_group, route_pattern, trackingKey) and to deduplicate tracking by trackingKey; updates tests to cover query-based (drop) view classification.

Changes

Cohort / File(s) Summary
Page Classification Service
services/analytics/pageClassification.ts
New classifier that maps pathname (+ optional searchParams) to PageViewClassification (logicalPage, pageGroup, routePattern, trackingKey).
Analytics Component
components/providers/MixpanelSetup.tsx
Switches deduplication from pathname to trackingKey, calls classifyPageView, includes logical_page, page_group, route_pattern in track payload, and uses useSearchParams.
Component Tests
__tests__/components/providers/MixpanelSetup.test.tsx
Mocks useSearchParams and wires URLSearchParams to simulate query states; adds tests for drop-detail tracking and searchParams-driven re-tracking.
Service Tests
__tests__/services/analytics/pageClassification.test.ts
New test suite validating classification for waves (index/detail/drop), profiles (root, tabs, subpages), reserved routes, and fallbacks with expected fields and trackingKey formats.

Sequence Diagram

sequenceDiagram
    participant User as User Navigation
    participant MixpanelSetup
    participant Classifier as classifyPageView
    participant Mixpanel as Mixpanel Service

    User->>MixpanelSetup: Navigate (pathname + searchParams)
    MixpanelSetup->>Classifier: classifyPageView({ pathname, searchParams })
    Classifier-->>MixpanelSetup: { logicalPage, pageGroup, routePattern, trackingKey }
    MixpanelSetup->>MixpanelSetup: Compare trackingKey vs lastTrackedPageKeyRef
    alt trackingKey differs
        MixpanelSetup->>Mixpanel: trackPageView(payload with logical_page, page_group, route_pattern)
        Mixpanel-->>MixpanelSetup: Ack
        MixpanelSetup->>MixpanelSetup: Update lastTrackedPageKeyRef
    else trackingKey unchanged
        MixpanelSetup-->>MixpanelSetup: Skip tracking
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • analyticsflowee
  • prxt6529

Poem

🐰 I hopped through paths and query light,

logical pages shining bright.
Drops and profiles, neatly tagged,
Tracking keys that never lagged.
Hooray — analytics done just right! ✨

🚥 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 'Logical page views for mixpanel' clearly and concisely summarizes the main change: implementing logical page view classification for Mixpanel analytics tracking.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch b-17730449643

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.

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

24-27: Memoize pageView to avoid unnecessary effect executions.

classifyPageView returns a new object on every render. Since pageView is in the dependency array at line 83, the effect runs on every render. While the trackingKey guard prevents duplicate tracking, the effect execution is wasteful.

♻️ Proposed fix using useMemo
-import { useEffect, useRef } from "react";
+import { useEffect, useMemo, useRef } from "react";
-  const pageView = classifyPageView({
-    pathname,
-    searchParams,
-  });
+  const pageView = useMemo(
+    () => classifyPageView({ pathname, searchParams }),
+    [pathname, searchParams]
+  );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/providers/MixpanelSetup.tsx` around lines 24 - 27, Memoize the
pageView object so the effect that depends on it doesn't run every render: wrap
the classifyPageView({ pathname, searchParams }) call in React's useMemo (e.g.,
const pageView = useMemo(() => classifyPageView({ pathname, searchParams }),
[pathname, searchParams])) so pageView only changes when pathname or
searchParams change; update imports if needed and keep the effect that
references pageView (the effect with trackingKey guard) unchanged so it only
executes when the actual pageView changes.
🤖 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 24-27: Memoize the pageView object so the effect that depends on
it doesn't run every render: wrap the classifyPageView({ pathname, searchParams
}) call in React's useMemo (e.g., const pageView = useMemo(() =>
classifyPageView({ pathname, searchParams }), [pathname, searchParams])) so
pageView only changes when pathname or searchParams change; update imports if
needed and keep the effect that references pageView (the effect with trackingKey
guard) unchanged so it only executes when the actual pageView changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8f5e8bef-4711-4059-b731-ab6bac5dfea4

📥 Commits

Reviewing files that changed from the base of the PR and between ec48edd and 55f741e.

📒 Files selected for processing (4)
  • __tests__/components/providers/MixpanelSetup.test.tsx
  • __tests__/services/analytics/pageClassification.test.ts
  • components/providers/MixpanelSetup.tsx
  • services/analytics/pageClassification.ts

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

sonarqubecloud Bot commented Mar 9, 2026

@GelatoGenesis GelatoGenesis merged commit 26ae428 into main Mar 9, 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