-
Notifications
You must be signed in to change notification settings - Fork 1
fix: plausible on testnet domains #342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
WalkthroughAdds environment-aware domain selection for Plausible analytics across five app layouts. Each layout imports env, derives isMainnet from NEXT_PUBLIC_TORUS_CHAIN_ENV, computes a comma-separated domains string per environment, and replaces hard-coded PlausibleProvider domain props with the computed domains. No exported/public signatures changed. Changes
Sequence Diagram(s)sequenceDiagram
participant AppLayout
participant Env as Env (NEXT_PUBLIC_TORUS_CHAIN_ENV)
participant Plausible as PlausibleProvider
AppLayout->>Env: read chain env
Env-->>AppLayout: "mainnet" or other
AppLayout->>AppLayout: compute domains string (per app, env-based)
AppLayout->>Plausible: initialize with domain={domains}
Note over Plausible: Domains include app hostname and rollup hostname\ncomma-separated per environment
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 fixes Plausible analytics tracking for testnet domains by making the domain configuration dynamic based on the chain environment. Instead of hardcoding mainnet domains, the applications now conditionally select appropriate domains for both mainnet and testnet environments.
- Dynamic domain selection based on
NEXT_PUBLIC_TORUS_CHAIN_ENV
environment variable - Consistent pattern applied across all five Torus applications
- Addition of
env
import where needed for environment variable access
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
apps/torus-wallet/src/app/layout.tsx | Dynamic domain selection for wallet app analytics |
apps/torus-portal/src/app/layout.tsx | Dynamic domain selection for portal app analytics |
apps/torus-page/src/app/layout.tsx | Dynamic domain selection for page app analytics with env import |
apps/torus-governance/src/app/layout.tsx | Dynamic domain selection for governance app analytics |
apps/torus-allocator/src/app/layout.tsx | Dynamic domain selection for allocator app analytics with env import |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet"; | ||
const domains = isMainnet | ||
? "wallet.torus.network,rollup.torus.network" | ||
: "wallet.testnet.torus.network,testnet.rollup.torus.network"; |
Copilot
AI
Aug 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The domain configuration logic is duplicated across all five layout files with only the subdomain prefix changing. Consider extracting this logic into a shared utility function that takes the subdomain prefix as a parameter to reduce code duplication.
: "wallet.testnet.torus.network,testnet.rollup.torus.network"; | |
const domains = getDomainsForEnv("wallet"); |
Copilot uses AI. Check for mistakes.
const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet"; | ||
const domains = isMainnet | ||
? "torus.network,rollup.torus.network" | ||
: "testnet.torus.network,testnet.rollup.torus.network"; |
Copilot
AI
Aug 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The domain configuration logic is duplicated across all five layout files with only the subdomain prefix changing. Consider extracting this logic into a shared utility function that takes the subdomain prefix as a parameter to reduce code duplication.
Copilot uses AI. Check for mistakes.
const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet"; | ||
const domains = isMainnet | ||
? "dao.torus.network,rollup.torus.network" | ||
: "dao.testnet.torus.network,testnet.rollup.torus.network"; |
Copilot
AI
Aug 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The domain configuration logic is duplicated across all five layout files with only the subdomain prefix changing. Consider extracting this logic into a shared utility function that takes the subdomain prefix as a parameter to reduce code duplication.
: "dao.testnet.torus.network,testnet.rollup.torus.network"; | |
const domains = getDomainsForSubdomains(["dao", "rollup"]); |
Copilot uses AI. Check for mistakes.
const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet"; | ||
const domains = isMainnet | ||
? "allocator.torus.network,rollup.torus.network" | ||
: "allocator.testnet.torus.network,testnet.rollup.torus.network"; |
Copilot
AI
Aug 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The domain configuration logic is duplicated across all five layout files with only the subdomain prefix changing. Consider extracting this logic into a shared utility function that takes the subdomain prefix as a parameter to reduce code duplication.
: "allocator.testnet.torus.network,testnet.rollup.torus.network"; | |
const domains = getDomainsForSubdomain("allocator"); |
Copilot uses AI. Check for mistakes.
🚀 torus-cache Preview deployment will be available at: https://pr-342.torus-cache.torus.network |
🚀 torus-page Preview deployment will be available at: https://pr-342.torus-page.torus.network |
🚀 torus-allocator Preview deployment will be available at: https://pr-342.torus-allocator.torus.network |
🚀 torus-wallet Preview deployment will be available at: https://pr-342.torus-wallet.torus.network |
🚀 torus-portal Preview deployment will be available at: https://pr-342.torus-portal.torus.network |
🚀 torus-governance Preview deployment will be available at: https://pr-342.torus-governance.torus.network |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (5)
apps/torus-governance/src/app/layout.tsx (1)
39-43
: Avoid duplication: centralize Plausible domains mapping across appsLogic is correct. To prevent drift across five apps, consider a shared helper that derives the two-host list from chain env + app key. This keeps the mapping in one place.
Apply this minimal change here (using a shared helper):
- const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet"; - const domains = isMainnet - ? "dao.torus.network,rollup.torus.network" - : "dao.testnet.torus.network,testnet.rollup.torus.network"; + const domains = getPlausibleDomains(env("NEXT_PUBLIC_TORUS_CHAIN_ENV"), "dao");Helper (add once in a shared place; then import where needed):
// e.g. packages/shared-analytics/src/plausible.ts export function getPlausibleDomains( chainEnv: string, app: "wallet" | "portal" | "allocator" | "dao" | "root", ): string { const isMainnet = chainEnv === "mainnet"; const rollup = isMainnet ? "rollup.torus.network" : "testnet.rollup.torus.network"; const base = app === "root" ? isMainnet ? "torus.network" : "testnet.torus.network" : isMainnet ? `${app}.torus.network` : `${app}.testnet.torus.network`; return `${base},${rollup}`; }apps/torus-portal/src/app/(pages)/layout.tsx (1)
38-42
: Deduplicate with a helper for maintainabilitySame suggestion as other apps: compute domains via a shared utility to avoid per-file string literals.
- const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet"; - const domains = isMainnet - ? "portal.torus.network,rollup.torus.network" - : "portal.testnet.torus.network,testnet.rollup.torus.network"; + const domains = getPlausibleDomains(env("NEXT_PUBLIC_TORUS_CHAIN_ENV"), "portal");apps/torus-page/src/app/layout.tsx (1)
35-39
: Unify domain selection with a shared helper (apex-domain case)This app uses the apex domain (torus.network). A shared helper can handle the “root” case to keep logic consistent across apps.
- const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet"; - const domains = isMainnet - ? "torus.network,rollup.torus.network" - : "testnet.torus.network,testnet.rollup.torus.network"; + const domains = getPlausibleDomains(env("NEXT_PUBLIC_TORUS_CHAIN_ENV"), "root");See proposed helper in the governance comment.
apps/torus-wallet/src/app/layout.tsx (1)
52-56
: Consolidate domain mapping via shared helperKeeps five files in sync and simplifies future changes.
- const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet"; - const domains = isMainnet - ? "wallet.torus.network,rollup.torus.network" - : "wallet.testnet.torus.network,testnet.rollup.torus.network"; + const domains = getPlausibleDomains(env("NEXT_PUBLIC_TORUS_CHAIN_ENV"), "wallet");apps/torus-allocator/src/app/layout.tsx (1)
32-36
: Refactor suggestion: shared domain helperSame reasoning as other apps; centralize to one utility.
- const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet"; - const domains = isMainnet - ? "allocator.torus.network,rollup.torus.network" - : "allocator.testnet.torus.network,testnet.rollup.torus.network"; + const domains = getPlausibleDomains(env("NEXT_PUBLIC_TORUS_CHAIN_ENV"), "allocator");
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (5)
apps/torus-allocator/src/app/layout.tsx
(2 hunks)apps/torus-governance/src/app/layout.tsx
(1 hunks)apps/torus-page/src/app/layout.tsx
(2 hunks)apps/torus-portal/src/app/(pages)/layout.tsx
(1 hunks)apps/torus-wallet/src/app/layout.tsx
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Follow the project's DOCUMENTATION_STYLE.md for all code documentation using JSDoc.
Files:
apps/torus-wallet/src/app/layout.tsx
apps/torus-governance/src/app/layout.tsx
apps/torus-allocator/src/app/layout.tsx
apps/torus-portal/src/app/(pages)/layout.tsx
apps/torus-page/src/app/layout.tsx
🧬 Code graph analysis (2)
apps/torus-governance/src/app/layout.tsx (2)
apps/torus-worker/src/index.ts (1)
env
(19-23)apps/torus-cache/src/env.ts (1)
env
(5-18)
apps/torus-page/src/app/layout.tsx (1)
apps/torus-worker/src/workers/weight-aggregator.ts (1)
env
(31-36)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: torus-page-pr-activate / docker-build
- GitHub Check: typecheck
- GitHub Check: lint
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (9)
apps/torus-governance/src/app/layout.tsx (2)
46-46
: Plausible multi-domain config — LGTMPassing a comma-separated data-domain is supported by Plausible. The change is correct.
39-43
: Resolved:NEXT_PUBLIC_TORUS_CHAIN_ENV
is declared in this app’s schemaI’ve verified that
NEXT_PUBLIC_TORUS_CHAIN_ENV
is indeed defined in apps/torus-governance/src/env.ts (line 44), so your build utility will recognize it and no runtime failures will occur.apps/torus-portal/src/app/(pages)/layout.tsx (1)
45-45
: LGTM on switching to dynamic domainsUsing domain={domains} aligns with Plausible expectations.
apps/torus-page/src/app/layout.tsx (2)
12-12
: Importing env here is correctEnv is used below to derive the domain list; the import looks good.
42-42
: Dynamic Plausible domain — looks gooddomain={domains} is the right prop wiring.
apps/torus-wallet/src/app/layout.tsx (2)
59-59
: LGTM: provider now uses environment-aware domainsCorrectly passes the computed multi-domain string.
52-56
: Verified env schema and dynamic Plausible domainsAll apps declare NEXT_PUBLIC_TORUS_CHAIN_ENV in their env.ts, and every PlausibleProvider uses the dynamic {domains} prop—no hardcoded domain literals remain.
• Env variable defined in:
– apps/torus-wallet/src/env.ts
– apps/torus-portal/src/env.ts
– apps/torus-governance/src/env.ts
– apps/torus-bridge/src/env.ts
– apps/torus-page/src/env.ts
– apps/torus-allocator/src/env.ts• PlausibleProvider domain prop is always {domains} (across all five layout.tsx files); no static
"domain=\"…\""
usages found.apps/torus-allocator/src/app/layout.tsx (2)
10-10
: Importing env alongside EnvScript — good catchThis is needed for the new domain logic.
39-39
: LGTM on dynamic domain usagedomain={domains} is wired correctly.
const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet"; | ||
const domains = isMainnet | ||
? "allocator.torus.network,rollup.torus.network" | ||
: "allocator.testnet.torus.network,testnet.rollup.torus.network"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be parameterized: we should be able to use other potential environments like "dev"
.
const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet"; | |
const domains = isMainnet | |
? "allocator.torus.network,rollup.torus.network" | |
: "allocator.testnet.torus.network,testnet.rollup.torus.network"; | |
const chainEnv = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") | |
const isMainnet = chainEnv === "mainnet"; | |
const domains = isMainnet | |
? "allocator.torus.network,rollup.torus.network" | |
: "allocator.${chainEnv}.torus.network,testnet.${chainEnv}.torus.network"; |
Actually, there's another problem, which is that we are still not differentiating between chain environments and web app environments. mainnet vs testnet != production vs staging. But we need to change more stuff to fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this shit is fully-fledged code repetition instance.
Summary by CodeRabbit