Skip to content

fix: add complementary GA code backup#969

Open
devsparrow5 wants to merge 2 commits intomainfrom
feat/add-secondary-ga-stream
Open

fix: add complementary GA code backup#969
devsparrow5 wants to merge 2 commits intomainfrom
feat/add-secondary-ga-stream

Conversation

@devsparrow5
Copy link
Collaborator

No description provided.

@vercel
Copy link

vercel bot commented Mar 2, 2026

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

Project Deployment Actions Updated (UTC)
defuse-widget Ready Ready Preview, Comment Mar 2, 2026 3:17pm

Request Review

@supabase
Copy link

supabase bot commented Mar 2, 2026

Updates to Preview Branch (feat/add-secondary-ga-stream) ↗︎

Deployments Status Updated
Database Mon, 02 Mar 2026 15:16:25 UTC
Services Mon, 02 Mar 2026 15:16:25 UTC
APIs Mon, 02 Mar 2026 15:16:25 UTC

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

Tasks Status Updated
Configurations Mon, 02 Mar 2026 15:16:31 UTC
Migrations Mon, 02 Mar 2026 15:16:32 UTC
Seeding Mon, 02 Mar 2026 15:16:36 UTC
Edge Functions Mon, 02 Mar 2026 15:16:36 UTC

View logs for this Workflow Run ↗︎.
Learn more about Supabase for Git ↗︎.

@coderabbitai
Copy link

coderabbitai bot commented Mar 2, 2026

Walkthrough

A new Google Analytics ID constant is added and an additional GoogleAnalytics component is injected into the RootLayout in src/app/layout.tsx. The new component renders unconditionally, creating a second GA instance independent of template conditions.

Changes

Cohort / File(s) Summary
Google Analytics Configuration
src/app/layout.tsx
Added new GA_NEAR_COM_ID constant and injected an additional GoogleAnalytics component to RootLayout, enabling dual GA instance loading.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • feat: add GA for omniswap #842 — Also modifies src/app/layout.tsx's GoogleAnalytics setup and GA ID constants, making structural changes to GA instance handling.

Suggested reviewers

  • santerisarle
  • selfbalance
  • silent-shipper

Poem

🐰 A second tracker hops along,
Analytics song grows twice as strong,
GA_NEAR_COM_ID takes its place,
Data flows with faster pace!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No description was provided by the author, making it impossible to assess relevance to the changeset. Add a description explaining why the complementary GA tracking is needed and what problem it solves.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: add complementary GA code backup' accurately describes the main change: adding a secondary Google Analytics component as a backup.

✏️ 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 feat/add-secondary-ga-stream

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

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/app/layout.tsx`:
- Line 212: The GoogleAnalytics call with GA_NEAR_COM_ID is being rendered
unconditionally; restrict it the same way NearComPromo is gated so only
production and approved templates (e.g., near-intents) load it to avoid
double-streaming and whitelabel leaks. Update the Layout (around where
GoogleAnalytics and per-template GA are used) to check isProduction (or
process/env flag) AND that the current template identifier (the prop/state used
to decide templates—e.g., templateName/templateSlug/selectedTemplate) is in an
allowlist before rendering <GoogleAnalytics gaId={GA_NEAR_COM_ID} />; leave the
existing per-template GA rendering (the GA for lines 209–211) unchanged. Ensure
the allowlist matches the templates that should report to near.com (likely only
"near-intents") and add a short comment explaining why the gate exists.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 492e701 and 795df7d.

📒 Files selected for processing (1)
  • src/app/layout.tsx

<GoogleAnalytics
gaId={tmpl === "omniswap" ? GA_OMNI_SWAP_ID : GA_NEAR_INTENTS_ID}
/>
<GoogleAnalytics gaId={GA_NEAR_COM_ID} />
Copy link

@coderabbitai coderabbitai bot Mar 2, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== GA wiring in root layout =="
rg -nP --type=tsx 'GA_[A-Z_]+_ID|GoogleAnalytics' src/app/layout.tsx

echo
echo "== Template branches currently defined in layout metadata/root =="
rg -nP --type=tsx 'templ\s*===\s*"[^"]+"|tmpl\s*===\s*"[^"]+"' src/app/layout.tsx

echo
echo "== Other GA/gtag instrumentation across repo =="
rg -nP --type=ts --type=tsx 'GoogleAnalytics|gtag\s*\(|page_view|send_page_view'

Repository: defuse-protocol/defuse-frontend

Length of output: 150


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Check if file exists
ls -la src/app/layout.tsx

echo
echo "== File size and content around line 212 =="
wc -l src/app/layout.tsx

echo
echo "== Reading content from line 200-220 =="
sed -n '200,220p' src/app/layout.tsx

echo
echo "== GA wiring in root layout (no type filter) =="
rg -n 'GA_[A-Z_]+_ID|GoogleAnalytics' src/app/layout.tsx

echo
echo "== Template variable references =="
rg -n 'tmpl|template' src/app/layout.tsx | head -20

echo
echo "== Other GA/gtag instrumentation across repo =="
rg -n 'GoogleAnalytics|gtag\s*\(|page_view|send_page_view' . --type ts 2>/dev/null | head -30

Repository: defuse-protocol/defuse-frontend

Length of output: 1722


🏁 Script executed:

#!/bin/bash
# Check for any documentation or comments about APP_ENV, template strategy, or GA management
echo "== Checking APP_ENV definition and usage context =="
rg -n 'APP_ENV\s*=' src/app/layout.tsx

echo
echo "== Context around line 156 (tmpl initialization) =="
sed -n '150,165p' src/app/layout.tsx

echo
echo "== Search for whitelabel or template documentation =="
rg -n 'whitelabel|WHITELABEL' . --type ts 2>/dev/null || echo "No whitelabel refs found"

Repository: defuse-protocol/defuse-frontend

Length of output: 8572


Gate GA_NEAR_COM_ID to intended templates only to prevent double-streaming and whitelabel boundary violations.

At Line 212, GA_NEAR_COM_ID renders unconditionally, meaning every template (omniswap, solswap, turboswap, dogecoinswap, trumpswap, rabitswap, near-intents) sends telemetry to this stream. This creates double-streaming—each template already has a dedicated GA stream routed at lines 209–211—and violates whitelabel boundaries for branded templates that should not report to near.com telemetry.

The codebase already gates template-specific content (e.g., NearComPromo only renders for near-intents), so apply the same pattern here. Restrict GA_NEAR_COM_ID to production + intended templates (likely near-intents only, or a defined allowlist):

Proposed guard
+  const shouldLoadNearComGa =
+    APP_ENV === "production" &&
+    tmpl === "near-intents"
+
   return (
     <html lang="en" suppressHydrationWarning className={`tmpl-${tmpl}`}>
@@
-      <GoogleAnalytics gaId={GA_NEAR_COM_ID} />
+      {shouldLoadNearComGa && <GoogleAnalytics gaId={GA_NEAR_COM_ID} />}
       {HELPSCOUT_BEACON_ID && <Helpscout />}
     </html>
   )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/layout.tsx` at line 212, The GoogleAnalytics call with GA_NEAR_COM_ID
is being rendered unconditionally; restrict it the same way NearComPromo is
gated so only production and approved templates (e.g., near-intents) load it to
avoid double-streaming and whitelabel leaks. Update the Layout (around where
GoogleAnalytics and per-template GA are used) to check isProduction (or
process/env flag) AND that the current template identifier (the prop/state used
to decide templates—e.g., templateName/templateSlug/selectedTemplate) is in an
allowlist before rendering <GoogleAnalytics gaId={GA_NEAR_COM_ID} />; leave the
existing per-template GA rendering (the GA for lines 209–211) unchanged. Ensure
the allowlist matches the templates that should report to near.com (likely only
"near-intents") and add a short comment explaining why the gate exists.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is intentional, the PR title is literally "complementary GA code backup."

Copy link

Choose a reason for hiding this comment

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

@devsparrow5, understood—thank you for clarifying. Since the backup GA stream is intentional, I'll defer to your design decision here. Just to confirm you're aware: this will send telemetry from all templates (omniswap, turboswap, dogecoinswap, etc.) to GA_NEAR_COM_ID in addition to their dedicated streams, which may affect analytics segmentation and whitelabel data isolation, but if that's acceptable for the backup strategy, no further changes are needed.

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