Skip to content

Track ip#602

Merged
goldflag merged 3 commits intomasterfrom
track-ip
Sep 23, 2025
Merged

Track ip#602
goldflag merged 3 commits intomasterfrom
track-ip

Conversation

@goldflag
Copy link
Copy Markdown
Collaborator

@goldflag goldflag commented Sep 23, 2025

Summary by CodeRabbit

  • New Features

    • Added an optional IP address tracking setting in Site Settings (Privacy & Security).
    • When enabled, IP addresses are shown in user profiles and session details.
  • UI Improvements

    • Refined user page header layout and avatar placement.
    • Renamed “Screen Size” to “Screen” in device info.
  • Documentation

    • Simplified embedding of the analytics script in the docs layout.

- Introduced a new `trackIp` boolean property in the site configuration to enable tracking of user IP addresses.
- Updated relevant components and API endpoints to support the new `trackIp` feature, ensuring it is properly integrated into site settings and analytics payloads.
- Enhanced the database schema and request validation to accommodate the new tracking option, improving overall analytics capabilities.
- Updated the analytics API and response types to include the user's IP address in session details.
- Enhanced the SessionDetails component to display the IP address when available, improving transparency in user session data.
- Modified database queries to retrieve and return the IP address associated with each session, ensuring comprehensive analytics capabilities.
- Updated UserInfo type to include an optional IP address field.
- Enhanced UserPage component to conditionally display the user's IP address using a Badge component.
- Modified getUserInfo API to retrieve and return the user's IP address, ensuring comprehensive analytics data is available.
@vercel
Copy link
Copy Markdown

vercel bot commented Sep 23, 2025

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

Project Deployment Preview Comments Updated (UTC)
rybbit Building Building Preview Comment Sep 23, 2025 5:59am

@goldflag goldflag merged commit 0829c47 into master Sep 23, 2025
5 of 6 checks passed
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 23, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds IP tracking capability: database schema updates (Postgres sites.trackIp, ClickHouse events.ip), server-side config/types and tracker pipeline changes (site config propagation, payload shape, conditional IP storage), API responses extended with ip fields, and client UI updates to toggle trackIp and display IP in session/user views. Minor docs formatting.

Changes

Cohort / File(s) Summary
Client API types
client/src/api/admin/sites.ts, client/src/api/analytics/userInfo.ts, client/src/api/analytics/userSessions.ts
Add optional trackIp?: boolean to SiteResponse; add ip to UserInfo (optional) and to session response shapes (required on session items/details).
Client UI: user/session display
client/src/app/[site]/user/[userId]/page.tsx, client/src/components/Sessions/SessionDetails.tsx
Render IP badge/row when available; header layout adjusted; label tweak (“Screen Size” → “Screen”).
Client UI: site settings toggle
client/src/components/SiteSettings/SiteConfiguration.tsx
Add “Track IP Address” toggle wired to siteMetadata.trackIp and update flow.
Docs formatting
docs-v2/src/app/layout.tsx
Collapse Simple Analytics <Script> to single-line self-closing form.
Server analytics APIs
server/src/api/analytics/getSession.ts, server/src/api/analytics/getSessions.ts, server/src/api/analytics/getUserInfo.ts
Surface ip in session details, session list items, and user info; SQL updated to select/aggregate IP (any(ip), argMax(ip, timestamp)).
Server site config surfaces
server/src/api/sites/getSite.ts, server/src/api/sites/updateSiteConfig.ts, server/src/lib/siteConfig.ts, server/src/db/postgres/schema.ts
Add trackIp column (Postgres), expose in getSite, include in SiteConfigData (exported), enable updating via API schema and return updated config.
DB: ClickHouse init
server/src/db/clickhouse/clickhouse.ts
Add ip Nullable(String) column to events via ALTER TABLE step.
Tracker pipeline and types
server/src/services/tracker/pageviewQueue.ts, server/src/services/tracker/trackEvent.ts, server/src/services/tracker/utils.ts
Replace local payload type with TotalTrackingPayload; createBasePayload now receives full SiteConfigData, adds storeIp from trackIp; compute emitted ip as ipAddress when storeIp true, else null; extend public tracking payload fields.
Tests
server/src/services/shared/requestValidation.test.ts
Update test fixtures/types to include trackIp.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant Tracker as Tracker Endpoint
  participant Utils as createBasePayload
  participant Queue as pageviewQueue
  participant DB as ClickHouse/Postgres

  Client->>Tracker: Tracking request (pageview/event)
  Tracker->>Utils: createBasePayload(request, type, payload, siteConfiguration)
  Utils-->>Tracker: Base payload (includes storeIp = siteConfiguration.trackIp)
  Tracker->>Queue: Enqueue TotalTrackingPayload
  Queue->>Queue: Build pageview record<br/>ip = storeIp ? ipAddress : null
  Queue->>DB: Insert event (ip nullable)
  Note over DB: ip persisted only when storeIp is true
Loading
sequenceDiagram
  autonumber
  participant UI
  participant API as Server APIs
  participant CH as ClickHouse
  participant PG as Postgres

  UI->>API: GET sessions / session / userInfo
  API->>CH: Query events (select argMax(ip,...), any(ip))
  CH-->>API: Rows with ip
  API-->>UI: JSON including ip fields

  UI->>API: GET/PUT site config (trackIp)
  API->>PG: Read/Update sites.trackIp
  PG-->>API: site config with trackIp
  API-->>UI: Response including trackIp
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • fix tracking events #589 — Also changes tracker utilities (utils.ts) and createBasePayload handling, overlapping with this PR’s signature and payload updates.
  • Exclude ips #527 — Introduces IP-related config (excludedIPs/isIPExcluded) in similar site config and tracking surfaces; closely related to adding trackIp.
  • Track outbound events #536 — Modifies session API types and aggregations in getSessions, intersecting with this PR’s addition of ip to session responses.

Poem

A rabbit taps the keys—tip-tap, tip-tap, hooray!
New tracks for tiny hops: an IP on the way.
Toggle on, toggle off, secrets kept neat,
ClickHouse burrows deeper, Postgres keeps the beat.
Sessions show their footprints, softly in the snow—
With care, we store them only when you say so.
(_/) 🌙

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch track-ip

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b6d1bec and 45c6355.

📒 Files selected for processing (19)
  • client/src/api/admin/sites.ts (1 hunks)
  • client/src/api/analytics/userInfo.ts (1 hunks)
  • client/src/api/analytics/userSessions.ts (2 hunks)
  • client/src/app/[site]/user/[userId]/page.tsx (3 hunks)
  • client/src/components/Sessions/SessionDetails.tsx (1 hunks)
  • client/src/components/SiteSettings/SiteConfiguration.tsx (2 hunks)
  • docs-v2/src/app/layout.tsx (1 hunks)
  • server/src/api/analytics/getSession.ts (2 hunks)
  • server/src/api/analytics/getSessions.ts (2 hunks)
  • server/src/api/analytics/getUserInfo.ts (3 hunks)
  • server/src/api/sites/getSite.ts (1 hunks)
  • server/src/api/sites/updateSiteConfig.ts (5 hunks)
  • server/src/db/clickhouse/clickhouse.ts (1 hunks)
  • server/src/db/postgres/schema.ts (1 hunks)
  • server/src/lib/siteConfig.ts (4 hunks)
  • server/src/services/shared/requestValidation.test.ts (5 hunks)
  • server/src/services/tracker/pageviewQueue.ts (2 hunks)
  • server/src/services/tracker/trackEvent.ts (1 hunks)
  • server/src/services/tracker/utils.ts (4 hunks)

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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.

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.

1 participant