Skip to content

feat: send the analytics events through the first party proxy behind a kill switch - #3497

Open
braianj wants to merge 1 commit into
masterfrom
feat/segment-events-through-first-party-proxy
Open

feat: send the analytics events through the first party proxy behind a kill switch#3497
braianj wants to merge 1 commit into
masterfrom
feat/segment-events-through-first-party-proxy

Conversation

@braianj

@braianj braianj commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Builder already loads analytics.js and its Segment settings from our first party proxy, but the events it produced still went to api.segment.io, which ad blockers drop just like cdn.segment.com. For a blocked user nothing was actually recovered: the bundle loaded and every event was then thrown away.

decentraland-dapps@29.8.0 adds apiHost to the analytics snippet options (the ingestion host, no protocol, shaped host/basePath; it validates and normalizes the value and falls back to Segment's own ingestion when it is invalid). This passes SEGMENT_API_HOST alongside the existing SEGMENT_ANALYTICS_URL, so the events reach Segment through the same first party host. The value is api.e.decentraland.org/v1 in the three environments, the same one decentraland.org has been running in production since Aug 19 without a regression (the client IP still reaches Segment, so context_ip is unaffected).

The whole proxy sits behind a kill switch shared with the other dapps: the dapps-seg-alt feature flag. On means send the analytics straight to Segment, ignoring both the proxy bundle URL and the proxy api host. Off or unknown means use the configured proxy, so merging this while the flag is off changes nothing about today's behaviour. Because the analytics middleware is created while the store is built and the flags only arrive later, the last known value is persisted in localStorage under dcl-analytics-seg-alt ('1' on, '0' off) every time the flags are fetched, and the next boot decides with it. Nothing is persisted on a fetch failure and every storage access is guarded, so a flag service outage or an unavailable storage can never disable the tracking.

How to test:

  • With the flag off (its normal state), open the builder and check in the network tab that analytics.js is fetched from evs.e.decentraland.org and that the events are posted to api.e.decentraland.org/v1/t, not to api.segment.io. Confirm the events land in Segment.
  • Enable dapps-seg-alt for the dapps application, reload twice (the first load persists the value, the second one applies it) and check the events go to api.segment.io again and the bundle to cdn.segment.com.
  • Repeat the first step with an ad blocker enabled: the events should still be delivered.
  • npm run lint, npx tsc --noEmit and npm test pass locally.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KDE5NS3oeKPcJWXbTTqSBx

@vercel

vercel Bot commented Sep 2, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
builder Ready Ready Preview Sep 2, 2026 10:47am UTC

Request Review

…a kill switch

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KDE5NS3oeKPcJWXbTTqSBx
@braianj
braianj force-pushed the feat/segment-events-through-first-party-proxy branch from b00ba3a to ab0c226 Compare September 2, 2026 10:44
@coveralls

coveralls commented Sep 2, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 33621041934

Coverage increased (+0.1%) to 53.843%

Details

  • Coverage increased (+0.1%) from the base build.
  • Patch coverage: 30 of 30 lines across 5 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 13419
Covered Lines: 7829
Line Coverage: 58.34%
Relevant Branches: 6032
Covered Branches: 2644
Branch Coverage: 43.83%
Branches in Coverage %: Yes
Coverage Strength: 37.3 hits per line

💛 - Coveralls

@decentraland-bot

Copy link
Copy Markdown
Contributor

✅ Approved by Claude, approved by Codex — route Segment analytics through the first-party proxy with a feature-flag kill switch

Checked: all 13 changed files reviewed in full context — proxy logic with localStorage guards and safe defaults, saga persistence on success only, env config consistency across dev/stg/prod, selector and type registration, test coverage for kill switch on/off/absent/invalid/storage-error and saga success/failure paths, CI (test, audit, Vercel deploy all green), security (no secrets, no injection vectors, no auth changes).


Cross-model review by Jarvis 🤖 · head ab0c226 · Claude + Codex · Requested by Braian Mellor (<@U03ACDWNHR8>) via Slack

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