Skip to content

analytics: use anonymous users#1211

Merged
BilalG1 merged 4 commits intoanalytics-replays-event-markersfrom
analytics-anon-users
Feb 19, 2026
Merged

analytics: use anonymous users#1211
BilalG1 merged 4 commits intoanalytics-replays-event-markersfrom
analytics-anon-users

Conversation

@BilalG1
Copy link
Copy Markdown
Collaborator

@BilalG1 BilalG1 commented Feb 18, 2026

No description provided.

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 18, 2026

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

Project Deployment Actions Updated (UTC)
stack-backend Ready Ready Preview, Comment Feb 19, 2026 3:18am
stack-dashboard Ready Ready Preview, Comment Feb 19, 2026 3:18am
stack-demo Ready Ready Preview, Comment Feb 19, 2026 3:18am
stack-docs Ready Ready Preview, Comment Feb 19, 2026 3:18am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 18, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch analytics-anon-users

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.

@BilalG1 BilalG1 requested a review from N2D4 February 18, 2026 19:18
@BilalG1 BilalG1 assigned N2D4 and unassigned BilalG1 Feb 18, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 18, 2026

Greptile Summary

This PR ensures analytics events and session replays are always associated with a user by auto-creating anonymous users when no authenticated session exists. The shared getAnalyticsAccessToken helper in client-app-impl.ts first tries the current session token, then falls back to creating an anonymous user via _signUpAnonymously(). As a consequence, pre-auth buffer caps and cross-user event leakage guards are removed from both EventTracker and SessionRecorder.

Additionally, a switch/case bug in useUser is fixed: the return-null / undefined / anonymous-if-exists[deprecated] cases now explicitly set crud = null and break, correcting a scenario where a non-null anonymous/restricted user could leak through.

  • Cross-user event leakage: The removed _wasAuthenticated logout guard previously cleared event buffers on user transitions. With anonymous fallback, events from a logged-in user may be flushed under a newly created anonymous identity after logout.
  • Unbounded buffer growth: If _hasPersistentTokenStore() returns false, getAnalyticsAccessToken returns null and events accumulate without any cap (the old MAX_PREAUTH_BUFFER_* constants were removed).
  • Bug fix: The useUser switch/case now correctly nullifies crud for the return-null path.

Confidence Score: 2/5

  • The removal of cross-user event leakage guards introduces a data isolation concern that should be evaluated before merging.
  • The core idea of using anonymous users for pre-login analytics is sound, but the PR removes two important safety mechanisms (cross-user buffer clearing on logout and pre-auth buffer size caps) without replacing them. The cross-user leakage concern is the most significant: events from one user session could be attributed to a different anonymous identity after logout.
  • Pay close attention to event-tracker.ts and session-replay.ts where cross-user event leakage guards and buffer caps were removed.

Important Files Changed

Filename Overview
packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts Extracts shared getAnalyticsAccessToken that auto-creates anonymous users for pre-login analytics. Also fixes a switch/case bug where crud wasn't explicitly nulled for the return-null path.
packages/template/src/lib/stack-app/apps/implementations/event-tracker.ts Removes pre-auth buffer caps and cross-user event leakage protection. Without the buffer cap, events can grow unbounded if no token store is available. Without the logout guard, events may be flushed under a different identity.
packages/template/src/lib/stack-app/apps/implementations/session-replay.ts Same concerns as event-tracker.ts: removes pre-auth buffer limits and cross-user replay leakage protection, relying on the anonymous user fallback which may not always be available.

Sequence Diagram

sequenceDiagram
    participant Tick as _tick() (every 5-10s)
    participant GAT as getAnalyticsAccessToken
    participant Session as Session Store
    participant API as Backend API

    Tick->>GAT: getAccessToken()
    GAT->>Session: getOrFetchLikelyValidTokens()
    alt Token exists (user logged in)
        Session-->>GAT: accessToken
        GAT-->>Tick: token
        Tick->>API: flush events with token
    else No token
        GAT->>GAT: _hasPersistentTokenStore()?
        alt Has token store
            GAT->>API: _signUpAnonymously()
            API-->>GAT: anonymous user tokens
            GAT->>Session: getOrFetchLikelyValidTokens()
            Session-->>GAT: new accessToken
            GAT-->>Tick: anonymous token
            Tick->>API: flush events with anonymous token
        else No token store
            GAT-->>Tick: null
            Note over Tick: Events buffered indefinitely (no cap)
        end
    end
Loading

Last reviewed commit: e545adc

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 18, 2026

Additional Comments (1)

packages/template/src/lib/stack-app/apps/implementations/event-tracker.ts
Unbounded buffer growth when token store is absent

The removed pre-auth buffer cap (MAX_PREAUTH_BUFFER_EVENTS / MAX_PREAUTH_BUFFER_BYTES) previously prevented unbounded memory growth when no access token was available. The new getAnalyticsAccessToken only creates an anonymous user when _hasPersistentTokenStore() is true. If the token store is absent (returns null), events will accumulate without any limit. Consider adding a buffer cap as a fallback, or documenting that analytics trackers should only be initialized when a persistent token store is guaranteed.

Copy link
Copy Markdown

@vercel vercel bot left a comment

Choose a reason for hiding this comment

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

Additional Suggestion:

Cross-user session replay data leakage on logout due to removed buffer clearing code

Fix on Vercel

@github-actions github-actions bot assigned BilalG1 and unassigned N2D4 Feb 18, 2026
@BilalG1 BilalG1 merged commit d590207 into analytics-replays-event-markers Feb 19, 2026
26 checks passed
@BilalG1 BilalG1 deleted the analytics-anon-users branch February 19, 2026 03:33
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