Update Impact Tab to use Cloudflare Edge Data#3551
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the Metabase/Redshift analytics pipeline with per-community analytics sourced directly from Cloudflare's edge data. Staged as "Impact2" alongside the existing Impact tab so nothing is removed while we test.
What this adds
Server
server/utils/cloudflareAnalytics.ts: Cloudflare GraphQL Analytics API client. Single combined query fetches daily traffic, top paths, countries, devices, and referrers per hostname. Includes date chunking (CF max ~31 days per query), contiguous span grouping, and per-day breakdown caching.server/analyticsDailyCache/model.ts: Sequelize model for Postgres-backed daily cache. Past days are cached permanently; today's data has a 1-hour TTL. Auto-prunes rows older than 90 days (hourly throttle).server/impact2/api.ts: API routes (GET /api/impact2,/test,/debug). Resolves the Cloudflare-facing hostname by querying the Community model directly (bypassesgetInitialData's localhost domain overwrite in dev). Debug endpoint is disabled in production.server/apiRoutes.ts,server/routes/index.ts,server/models.ts.Client
client/containers/DashboardImpact2/: React component + SCSS. Top row with stat cards (color-coded left border) and area chart side by side. Four-column data grid below: Top Pages (with clickable links), Countries, Referrers, Devices (as percentage table). Responsive down to single-column on mobile.client/containers/App/paths.ts,client/containers/index.ts,utils/dashboard.ts.ScopeDropdown.Filtering and noise reduction
Two layers of filtering to get numbers closer to real human readership:
/wp-*,/cdn-cgi/,/api/,/static/,/login,/robots.txt,.xml, etc. from Top Pages list. Subtracts noise path page views from totals and proportionally scales visits, countries, devices, referrers, and daily chart data to match.Raw (pre-adjustment) totals are included in the API response and shown in the footer for transparency.
Caching strategy
Env vars required
If missing, the server logs a warning and the client shows a "not available" message instead of erroring.