Skip to content

feat(analytics): add OneDollarStats custom events - #487

Merged
leoisadev1 merged 1 commit into
mainfrom
feat/analytics-events
Jan 7, 2026
Merged

feat(analytics): add OneDollarStats custom events#487
leoisadev1 merged 1 commit into
mainfrom
feat/analytics-events

Conversation

@leoisadev1

Copy link
Copy Markdown
Member

Summary

Adds OneDollarStats custom event tracking for key user interactions.

Events Tracked

Event Properties When
Model Switched model (model ID) User selects a different model
Message Sent model (model ID) User sends a message
Chat Created - New chat is created
Signed In - User completes OAuth sign-in
Thinking Mode Changed effort (none/low/medium/high) User changes reasoning effort
Search Toggled enabled (true/false) User enables/disables web search

Changes

  • Added apps/web/src/lib/analytics.ts - utility wrapper for OneDollarStats events
  • Integrated analytics calls in:
    • stores/model.ts - model switch, thinking mode
    • stores/provider.ts - search toggle
    • hooks/use-persistent-chat.ts - message sent, chat created
    • lib/auth-client.tsx - sign in

Testing

  • Type check passes

Track key user interactions:
- Model switched (with model ID)
- Message sent (with model ID)
- Chat created
- Signed in (after OAuth)
- Thinking mode changed (with effort level)
- Search toggled (enabled/disabled)
@railway-app

railway-app Bot commented Jan 6, 2026

Copy link
Copy Markdown

🚅 Deployed to the openchat-pr-487 environment in OpenChat

Service Status Web Updated (UTC)
web ❌ Build Failed (View Logs) Web Jan 6, 2026 at 11:57 pm

@railway-app
railway-app Bot temporarily deployed to OpenChat / openchat-pr-487 January 6, 2026 23:56 Destroyed
@github-actions

github-actions Bot commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

🚀 Preview Deployment Ready

Environment URL
Frontend https://web-openchat-pr-487.up.railway.app
Convex Dashboard Dashboard

Convex Preview Backend

  • Cloud URL: https://cautious-manatee-406.convex.cloud
  • Site URL: https://cautious-manatee-406.convex.site

🤖 Deployed automatically by GitHub Actions

@greptile-apps

greptile-apps Bot commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds OneDollarStats custom event tracking for key user interactions. A new analytics utility module (analytics.ts) provides a clean wrapper for the OneDollarStats API, with six tracked events: Model Switched, Message Sent, Chat Created, Signed In, Thinking Mode Changed, and Search Toggled. The implementation integrates seamlessly into existing stores and hooks with minimal code changes. All events are triggered at appropriate moments in the user flow, and the code safely handles the optional nature of the OneDollarStats library with proper existence checks.

Confidence Score: 5/5

  • This PR is safe to merge. The analytics implementation is well-designed, properly integrated, and introduces no breaking changes or security concerns.
  • The PR demonstrates excellent code quality: (1) The analytics wrapper properly handles the optional nature of window.stonks with existence checks, preventing runtime errors if the library fails to load; (2) All six events are triggered at semantically correct moments in user flows (after state changes, after successful operations); (3) Integration into existing stores and hooks is minimal and non-intrusive; (4) Event naming follows a consistent, user-friendly pattern; (5) Data types are correctly handled (booleans converted to strings for OneDollarStats API); (6) No timing issues or race conditions detected; (7) Follows the codebase's TypeScript and file naming conventions; (8) Type safety is maintained throughout.
  • No files require special attention. All implementations are solid and follow established patterns in the codebase.

Important Files Changed

Filename Overview
apps/web/src/lib/analytics.ts New analytics wrapper for OneDollarStats custom events. Safely wraps window.stonks.event with existence checks and handles both string and boolean properties correctly. Well-structured with clean API.
apps/web/src/stores/model.ts Analytics integration for model selection and reasoning effort changes. Events are correctly triggered before state updates, ensuring accurate tracking of user interactions.
apps/web/src/stores/provider.ts Analytics integration for web search toggle in both toggleWebSearch() and setWebSearchEnabled() methods. Correctly tracks state changes and converts boolean to string format expected by OneDollarStats.
apps/web/src/hooks/use-persistent-chat.ts Analytics events for chat creation and message sending are properly integrated. Events fire at correct times: chat creation after successful API call, message send before streaming. No timing or race condition issues detected.
apps/web/src/lib/auth-client.tsx Sign-in analytics event properly triggered after one-time token verification succeeds. Placed correctly in the promise chain to ensure analytics only fires after authentication is confirmed.

Sequence Diagram

sequenceDiagram
    actor User
    participant UI as UI/Components
    participant Store as Zustand Store
    participant Analytics as analytics.ts
    participant Window as window.stonks

    User->>UI: Switch Model
    UI->>Store: setSelectedModel(modelId)
    Store->>Analytics: analytics.modelSwitched(modelId)
    Analytics->>Window: window.stonks.event("Model Switched", {model})

    User->>UI: Change Reasoning Effort
    UI->>Store: setReasoningEffort(effort)
    Store->>Analytics: analytics.thinkingModeChanged(effort)
    Analytics->>Window: window.stonks.event("Thinking Mode Changed", {effort})

    User->>UI: Toggle Web Search
    UI->>Store: toggleWebSearch() or setWebSearchEnabled(enabled)
    Store->>Analytics: analytics.searchToggled(enabled)
    Analytics->>Window: window.stonks.event("Search Toggled", {enabled})

    User->>UI: Create New Chat & Send Message
    UI->>Store: createChat()
    Store->>Analytics: analytics.chatCreated()
    Analytics->>Window: window.stonks.event("Chat Created")
    UI->>Store: sendMessage(text)
    Store->>Analytics: analytics.messageSent(modelId)
    Analytics->>Window: window.stonks.event("Message Sent", {model})

    User->>UI: Sign In with GitHub
    UI->>AuthClient: verify one-time token
    AuthClient->>Analytics: analytics.signedIn()
    Analytics->>Window: window.stonks.event("Signed In")
Loading

@leoisadev1
leoisadev1 merged commit 5ba7484 into main Jan 7, 2026
5 checks passed
@leoisadev1
leoisadev1 deleted the feat/analytics-events branch January 7, 2026 00:01
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