Skip to content

[Docs] [Feat] Enabling client side events for non internal projects, updating docs for payments and analytics#1250

Merged
N2D4 merged 3 commits intodevfrom
docs-payments-analytics
Mar 13, 2026
Merged

[Docs] [Feat] Enabling client side events for non internal projects, updating docs for payments and analytics#1250
N2D4 merged 3 commits intodevfrom
docs-payments-analytics

Conversation

@nams1570
Copy link
Copy Markdown
Collaborator

@nams1570 nams1570 commented Mar 13, 2026

Summary of Changes

Updating docs for analytics and payments to be descriptive. Also enabling analytics client side events for non-internal projects.

Summary by CodeRabbit

Release Notes

  • Documentation
    • Added comprehensive Analytics app guide covering dashboard overview, event tracking configuration, and best practices
    • Expanded Payments documentation with detailed setup flows, product management, and transaction procedures
    • Analytics app now integrated into the apps directory

Copilot AI review requested due to automatic review settings March 13, 2026 18:47
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 13, 2026

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

Project Deployment Actions Updated (UTC)
stack-auth-hosted-components Ready Ready Preview, Comment Mar 13, 2026 6:48pm
stack-backend Ready Ready Preview, Comment Mar 13, 2026 6:48pm
stack-dashboard Ready Ready Preview, Comment Mar 13, 2026 6:48pm
stack-demo Ready Ready Preview, Comment Mar 13, 2026 6:48pm
stack-docs Building Building Preview, Comment Mar 13, 2026 6:48pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 13, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR introduces a new Analytics app documentation guide and enhances the Payments documentation with expanded sections. It updates the documentation navigation to include Analytics and modifies event tracking initialization to operate in browser environments for any projectId.

Changes

Cohort / File(s) Summary
Analytics Documentation
docs/content/docs/(guides)/apps/analytics.mdx
New comprehensive guide covering Analytics dashboard sections (Tables, Queries, Replays), data flow architecture, tracked events, quick start instructions, SDK configuration with TypeScript examples, masking behavior, and best practices.
Payments Documentation
docs/content/docs/(guides)/apps/payments.mdx
Expanded documentation with new sections: Quick Setup, How Payments Works, Core Concepts, and restructured dashboard guidance. Added product lifecycle workflows, Stripe integration details, refined test mode descriptions, and extended payouts/settings coverage.
Documentation Navigation
docs/content/docs/(guides)/meta.json, docs/content/docs/(guides)/overview.mdx
Updated navigation metadata and overview grid to include the new Analytics app in the Apps section.
Event Tracking Implementation
packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts
Modified analytics event tracking initialization to run in browser environments for any projectId, removing previous internal project restriction.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • N2D4

Poem

🐰 Analytics hops in with charts so fine,
Events now tracked across the line,
Payments guide blooms in detail divine,
Documentation shines, a grand design! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main changes: documentation updates for analytics and payments, plus a feature enabling client-side events for non-internal projects.
Description check ✅ Passed The description addresses the key changes but lacks detail about scope, testing, and breaking changes. However, it covers the essential intent and is not incomplete enough to fail.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 docs-payments-analytics
📝 Coding Plan
  • Generate coding plan for human review comments

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
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enables client-side analytics event tracking for all projects (previously restricted to the internal project only) and adds/updates documentation for the Analytics and Payments apps.

Changes:

  • Removes the projectId === "internal" guard so all projects get client-side event tracking
  • Adds a new Analytics documentation page and registers it in the docs navigation
  • Expands the Payments documentation with setup guides, concept explanations, and dashboard management details

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts Removes internal-only restriction for event tracking
docs/content/docs/(guides)/apps/analytics.mdx New Analytics app documentation page
docs/content/docs/(guides)/apps/payments.mdx Expanded Payments documentation with setup, concepts, and dashboard sections
docs/content/docs/(guides)/meta.json Adds analytics entry to docs navigation
docs/content/docs/(guides)/overview.mdx Adds analytics to the AppGrid on the overview page

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 13, 2026

Greptile Summary

This PR adds a new analytics documentation page, enriches the payments docs with Quick Setup and Core Concepts sections, and removes the projectId === "internal" guard in client-app-impl.ts so that the EventTracker (client-side $page-view / $click capture) runs for all non-internal projects — not just Stack's own internal project.

Key changes:

  • New analytics.mdx: Covers Tables, Queries, and Session Replays features with a flowchart diagram, SDK code snippet for replay recording, and best-practice guidance.
  • Updated payments.mdx: Adds a Quick Setup checklist, a Mermaid sequence diagram for the purchase flow, Core Concepts definitions, and new Product Lines / Payouts / Settings dashboard sections.
  • meta.json / overview.mdx: Registers the new analytics guide in the sidebar and the overview AppGrid.
  • client-app-impl.ts: Drops the if (... && this.projectId === "internal") guard, meaning EventTracker (DOM listeners + history patching) is now initialised for every StackClientApp running in a browser. The server still enforces ANALYTICS_NOT_ENABLED for projects that haven't opted in, but the client is unaware of this and will produce console.warn noise and waste network requests for those projects.

Confidence Score: 3/5

  • Safe to merge for the documentation half; the SDK change is functional but will cause console warnings and unnecessary network traffic for any project that hasn't enabled the Analytics app.
  • The docs additions are high quality and accurate. The SDK change achieves its stated goal (enabling events for non-internal projects), but the unconditional EventTracker initialization introduces observable side-effects — repeated console.warn messages and wasted HTTP calls — for every Stack Auth project that isn't using analytics. No data is leaked (server rejects events), but the developer experience degrades without a mitigation path (opt-out flag or silent failure for ANALYTICS_NOT_ENABLED).
  • packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts

Important Files Changed

Filename Overview
packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts Removes the projectId === "internal" guard, unconditionally starting the EventTracker (DOM listeners, history monkey-patching, periodic token fetches + server flushes) for all browser environments — projects without analytics enabled will receive console.warn noise and wasted network requests.
docs/content/docs/(guides)/apps/analytics.mdx New analytics guide covering Tables, Queries, Session Replays, the SDK config for analytics.replays.enabled, and best practices. Content is accurate and well-structured.
docs/content/docs/(guides)/apps/payments.mdx Extended with Quick Setup, How Payments Works sequence diagram, Core Concepts, Product Lines section, Payouts/Settings sections, and minor wording improvements. No technical issues.

Sequence Diagram

sequenceDiagram
    participant Browser as Browser (all projects)
    participant ET as EventTracker
    participant Server as Stack Auth Server

    Browser->>ET: start() — attach click/popstate/pagehide listeners,<br/>monkey-patch history.pushState/replaceState
    loop Every 10s (_tick)
        ET->>Server: getAccessToken()
        Server-->>ET: token (or null)
        alt User is authenticated AND events buffered
            ET->>Server: POST /analytics/events/batch
            alt Analytics app enabled
                Server-->>ET: 200 OK — events stored
            else Analytics app disabled
                Server-->>ET: 400 ANALYTICS_NOT_ENABLED
                ET-->>Browser: console.warn("EventTracker flush failed")
            end
        end
    end
Loading

Comments Outside Diff (1)

  1. packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts, line 553-562 (link)

    EventTracker initialized for all projects, not just analytics-enabled ones

    The guard was changed from projectId === "internal" to unconditionally starting the EventTracker for any browser environment. However, the server-side /analytics/events/batch route rejects requests with HTTP 400 / ANALYTICS_NOT_ENABLED when the analytics app is disabled for the project.

    This means for every project that hasn't enabled the Analytics app:

    1. DOM event listeners (click, pagehide, visibilitychange, popstate) are attached.
    2. history.pushState and history.replaceState are monkey-patched globally.
    3. Every 10 seconds getAccessToken() is called (via _tick()), and when a user is logged in, a flush is attempted.
    4. That flush hits the server, gets a 400 back, and surfaces a console.warn("EventTracker flush failed: …") in the developer's browser console.

    Because _networkRetry retries up to 5 times on error, each failed flush cycle can result in 5 round-trip requests before the console.warn fires. This produces noise in the console for every project that uses Stack Auth without enabling analytics.

    Consider guarding initialization on a client-side opt-in (e.g. analytics.events.enabled !== false) or, at minimum, suppress the console warning when the server explicitly returns ANALYTICS_NOT_ENABLED so that the failure is silent for disabled projects.

Last reviewed commit: ee0277a

@N2D4 N2D4 merged commit 59a65bb into dev Mar 13, 2026
34 of 36 checks passed
@N2D4 N2D4 deleted the docs-payments-analytics branch March 13, 2026 18:52
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.

3 participants