Skip to content

Commit f445982

Browse files
committed
feat: add accounts, cloud billing and native analytics workflows
1 parent c52918f commit f445982

217 files changed

Lines changed: 18205 additions & 5734 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.env.example‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ GA4_CLIENT_EMAIL=
33
# Private key from the JSON key (private_key). Keep the double quotes and the \n sequences.
44
GA4_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
55

6+
# Optional real multi-step Journeys from GA4 BigQuery export. Leave unset until export is enabled.
7+
# Dataset is always analytics_<property ID>. Location must match the dataset (US, EU or a region).
8+
# GA4_BIGQUERY_SOURCES={"123456789":{"projectId":"my-ga4-project","location":"US"}}
9+
# Optional billingProjectId on each mapping overrides the query billing project.
10+
# Reuses GA4 service-account credentials through a separate BigQuery client; optional separate account:
11+
# BIGQUERY_CLIENT_EMAIL=
12+
# BIGQUERY_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
13+
# Hard query cap and per-billing-project UTC-day application budgets (bytes / query jobs).
14+
# BIGQUERY_MAX_BYTES_BILLED=1073741824
15+
# BIGQUERY_DAILY_BYTES=10737418240
16+
# BIGQUERY_DAILY_QUERIES=100
17+
618
# Optional Google Search Console service account (webmasters.readonly).
719
# Reuse an existing account with access to your GSC sites; values stay in env, never a key file.
820
# GSC_CLIENT_EMAIL=
@@ -15,6 +27,40 @@ GA4_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
1527
# Optional. Default 5483.
1628
# PORT=5483
1729

30+
# Public browser origin. Required when using a reverse proxy or non-default port.
31+
# BASE_URL=https://analytics.example.com
32+
# Optional; otherwise a random stable auth secret is stored inside SQLite.
33+
# BETTER_AUTH_SECRET=
34+
# SQLite application database (users, sessions, organizations, teams, property grants, saved definitions).
35+
# DATABASE_PATH=/app/.data/metribee.sqlite
36+
# Set true after creating your first administrator to allow only invited registrations.
37+
# DISABLE_SIGNUP=true
38+
# Trust forwarding headers only when running behind your own trusted proxy.
39+
# TRUST_PROXY=true
40+
# Additional trusted browser origins, comma separated.
41+
# AUTH_TRUSTED_ORIGINS=
42+
43+
# Optional website sign-in providers, independent of supplemental GA4 read access below.
44+
# Redirect URIs: <BASE_URL>/api/auth/callback/google and <BASE_URL>/api/auth/callback/github.
45+
# GOOGLE_CLIENT_ID=
46+
# GOOGLE_CLIENT_SECRET=
47+
# GITHUB_CLIENT_ID=
48+
# GITHUB_CLIENT_SECRET=
49+
50+
# Mail enables invitations, account recovery, property transfers and weekly reports.
51+
# Cloudflare Email Sending: onboard your domain, then use a token with Email Sending: Edit.
52+
# CLOUDFLARE_EMAIL_API_TOKEN=
53+
# Or use Resend:
54+
# RESEND_API_KEY=
55+
# Or use any SMTP provider:
56+
# SMTP_URL=smtps://user:password@smtp.example.com:465
57+
# Alternatively set SMTP_HOST, SMTP_PORT, SMTP_SECURE, SMTP_USER, SMTP_PASSWORD.
58+
# MAIL_FROM=MetriBee <analytics@example.com>
59+
# Weekly reports run on Monday UTC when mail is configured; users can unsubscribe in Account settings.
60+
# WEEKLY_REPORTS_ENABLED=false
61+
# PDF export uses Chromium (included in the Docker image). For source installs:
62+
# PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
63+
1864
# MCP is served by the dashboard at http://localhost:5483/mcp.
1965
# Optional standalone server (pnpm mcp); independent of PORT/HOST.
2066
# MCP_HOST=127.0.0.1
@@ -35,3 +81,11 @@ GA4_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
3581
# GA4_OAUTH_PROPERTY_IDS=
3682
# Written by pnpm oauth:login after browser consent; never commit or paste this token.
3783
# GA4_OAUTH_REFRESH_TOKEN=
84+
85+
# Self-hosted by default: no billing pages, payment endpoints or payment worker.
86+
CLOUD=false
87+
# Set CLOUD=true explicitly only for a MetriBee Cloud deployment.
88+
# WAFFO_MODE=test
89+
# WAFFO_MERCHANT_ID=MER_xxx
90+
# WAFFO_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"
91+
# Only the merchant ID and private key are payment credentials. Catalog IDs live in SQLite.

‎AGENTS.md‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55

66
Every UI change (views/, public/css, new components) MUST follow DESIGN.md: colors, type, radii, spacing tokens. No ad hoc palette or font choices.
77

8+
Account, organization, teams, administrator, login and signup pages must preserve the local Rybbit reference's complete page composition, widths, spacing, sidebars, tabs and auth form/step layouts. Import the original pages and layouts; do not replace them with custom page shells. Limit adaptations to MetriBee branding, GA4/SQLite data and the required map-boundary source.
9+
10+
Property organization moves and person-to-person transfers live in the native Site Settings dialog's General tab, reachable from the property sidebar and Home cards. Preserve its original desktop shell, settings sections and move confirmation; GA4 names/domains are read-only and unsupported collector controls are omitted. Legacy `/property-access` links open this dialog on the matching analytics page. Footer retains Rybbit's 1100px content width, 140px logo, three columns, support-action area and bottom-bar layout with MetriBee branding and valid project links.
11+
812
## Stack
913

10-
Express serves GA4 APIs and the analytics workspace. Following the owner's October 22, 2026 instruction, all user-facing pages use the native Rybbit React UI in `frontend/`, built by Vite into `public/ui/`. Reuse imported `frontend/rybbit/src/components/ui`, site, journeys and retention components; do not recreate controls in Handlebars or mix in the legacy panel palette. GA4 controllers and quota/auth logic remain on the server. Home (including Sites report views), Globe, quota, connection and GA4-specific reports compose those same components in `frontend/adapter/`. Preserve every GA4 data capability when adapting presentation. Do not add user-account or Documentation menus.
14+
Fastify serves GA4 APIs, Better Auth and the analytics workspace. SQLite stores application and authentication data; Express is not used. Following the owner's October 22, 2026 instruction, all user-facing pages use the native Rybbit React UI in `frontend/`, built by Vite into `public/ui/`. Reuse imported `frontend/rybbit/src/components/ui`, site, journeys and retention components; do not recreate controls in Handlebars or mix in the legacy panel palette. GA4 controllers and quota/auth logic remain on the server. Home (including Sites report views), Globe, quota, connection and GA4-specific reports compose those same components in `frontend/adapter/`. Preserve every GA4 data capability when adapting presentation. Reuse native Rybbit account, organization, team and system-admin controls. Do not add a Documentation menu.
1115

1216
Home combines the original Rybbit site cards with Status, Table and Heatmap tabs. All four views share search, tag/team filters, date selection and comparison periods. Keep the view tabs, update time and date controls in one desktop toolbar row. Status, Table and Heatmap query the shared GA4 report cache for the selected dates; saved AdSense values appear only when they fully cover the selected period. Home offers optional account grouping across all four views; Realtime stays ungrouped. Property names/account metadata refresh every five minutes independently of report caches, with a manual Sync properties action on Home. Legacy `/sites` links redirect to the matching Home tab.
1317

@@ -21,19 +25,29 @@ Widgets are managed on their own property-scoped `/widgets?prop=ID` page, reacha
2125

2226
Run `pnpm build:ui` after changing frontend source, `pnpm dev:ui` to watch, and `pnpm typecheck:ui` to check it. `pnpm build` builds both server TypeScript and UI. Imported code and modifications retain their Rybbit AGPL license and attribution in `frontend/third-party/`.
2327

28+
UI builds retain previous hashed assets so open tabs can keep importing their scripts. Do not clean `public/ui` while serving existing pages. HTML shells use `Cache-Control: no-store` and provide a startup/reload fallback. Authentication browser QA must use a separate database and a different hostname from the user's preview (for example `127.0.0.1` versus `localhost`); different ports alone do not isolate login cookies.
29+
2430
## Credentials
2531
Env only, never a key file. Both the app and `mcp-server/` read `GA4_CLIENT_EMAIL` and `GA4_PRIVATE_KEY` (quoted, `\n` escaped) from the root `.env` through `lib/credentials.js`. Optional: `PSI_API_KEY`, `PORT`.
26-
- Until both are set (or `DEMO=1`), pages redirect to `/setup` and `/api/*` returns 503 `not_configured` (gate in `app.js`). The server re-reads `.env` on each check, so no restart is needed.
32+
- Until both are set (or `DEMO=1`), pages redirect to `/setup` and `/api/*` returns 503 `not_configured` (authenticated setup gate in `app.js`). The server re-reads `.env` on each check, so no restart is needed.
2733
- Check: `pnpm setup:check` (exit 0 connected, 1 env missing, 2 key rejected, 3 no properties, 4 GA4 request failed), `GET /api/setup/status`, `GET /healthz`.
2834
- Setup prompt, manual steps and MCP prompt live in `SETUP.md` between markers; `/setup` reads them from there. Edit text there, not in the view.
2935
- One `pnpm install` at the root covers the MCP server (`pnpm mcp`).
30-
- MCP uses the stable v2 SDK and Streamable HTTP only. The dashboard mounts `/mcp` before its setup/boot gates; `pnpm mcp` serves the same tools separately on `MCP_HOST`/`MCP_PORT` (default `127.0.0.1:5484`). Client configs use an HTTP URL, never a node/stdio command. Keep the per-request server factory and shared cache/quota modules.
36+
- MCP uses the stable v2 SDK and Streamable HTTP only. The dashboard registers `/mcp` independently of its setup/boot gates; MCP requires a scoped API key or OAuth bearer token (or a same-origin signed-in session); `pnpm mcp` serves the same tools separately on `MCP_HOST`/`MCP_PORT` (default `127.0.0.1:5484`). Client configs use an HTTP URL, never a node/stdio command. Keep the per-request server factory and shared cache/quota modules.
3137
- High-level MCP tools in `mcp-server/lib/dashboard.js` reuse native dashboard controllers, caches, funnel/widget stores and GA4 clients. New analytics features should be reflected in the MCP capability catalog and tools. Guard every uncached GA4 call, keep each analysis on one property, and never bypass quota protection through native helpers. Results include structured content and explicit truncation; local definition writes need read/write annotations. Demo MCP data must not read/write live quota or mix with live tool caches. Sharing keys and enablement are not MCP operations.
3238

3339
Optional supplemental user OAuth lives in lib/supplementalAuth.js and is shared by the dashboard,
3440
MCP server and snapshot script. Credentials stay in .env. Only explicit numeric account/property
3541
allowlists use OAuth; its only scope is analytics.readonly. See SETUP.md.
3642

43+
## Users and SQLite
44+
45+
Better Auth 1.7.3 owns authentication at `/api/auth`; `lib/auth.mjs` generates its SQLite schema. `lib/database.js` applies idempotent application migrations. The first registered user becomes a system administrator and owner of the default organization; connected GA4 properties are assigned there initially. New organizations receive no properties automatically. Reuse Rybbit's five roles and scope taxonomy in `lib/permissions.js` and `lib/scopes.js`. All HTTP and MCP entry points must enforce the same organization/property grants, including legacy APIs and aggregate caches. Never trust browser role, organization or property claims. Private links and explicitly enabled embeds retain their separate public read guards.
46+
47+
`DATABASE_PATH` defaults to `.data/metribee.sqlite` (demo: `.data/metribee-demo.sqlite`). Funnels, Widgets and private-link settings are transactionally stored in SQLite; valid legacy JSON documents migrate automatically without deleting originals or changing IDs/keys. Report caches, GA4 quota ledgers and supplemental Google credentials keep their existing formats and guards. Use `pnpm db:migrate`, `pnpm db:check` and `pnpm db:backup`; an online backup includes WAL contents. Persist `.data`, run one app database on a local filesystem, and do not store GA4 service-account credentials in it. Mail uses SMTP or Resend; browser login OAuth credentials are separate from supplemental GA4 OAuth.
48+
49+
Public Analytics is an opt-in property setting in Site Settings → General. Its SQLite flag is independent of private links and widget publishing. Anonymous access uses the report allowlist in `lib/publicDashboard.js`, checks enablement before cached reports, filters metadata to one property, hides private segments/annotations and workspace identities, and never grants organization, management, GSC or MCP access. Keep public browser report caches separate from signed-in workspace persistence.
50+
3751
## Tests
3852
`pnpm test` runs mocha on `test/**/*.test.js`. Run once before commit, not after every edit.
3953

‎CHANGELOG.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
55

66
## [Unreleased]
77

8+
### Added
9+
10+
- Add optional GA4 BigQuery export support for real two-to-ten-step Journeys, path sessions, event timelines and MCP reports, with property-scoped configuration and scan/daily budgets.
11+
- Add Rybbit's Public Analytics switch, shareable public dashboard URLs and property-scoped anonymous reports, with immediate revocation and existing private links preserved.
12+
- Align saved segments, chart annotations, Goals, custom Dashboards, PDF exports and weekly email reports with Rybbit’s native UI, with SQLite persistence, GA4 adapters, scoped permissions and MCP tools.
13+
- Add Better Auth accounts, sessions, email verification and recovery, optional Google/GitHub sign-in, organizations, invitations, teams, five access roles, property grants, administrator tools and scoped personal/organization API keys.
14+
- Connect MCP clients through OAuth with PKCE and explicit consent; enforce the same property permissions across dashboard and MCP requests.
15+
- Store accounts and saved definitions in SQLite, automatically import legacy JSON without changing existing share/widget links, and provide online backup and integrity checks.
16+
- Add opt-in Cloud organization subscriptions through Waffo Pancake, with hosted checkout, plan changes, cancellation and invoices; self-hosted deployments keep billing disabled by default.
17+
18+
### Changed
19+
20+
- Replace Express with Fastify for the dashboard and standalone MCP server while preserving GA4 report caches and quota safeguards.
21+
- Preserve native Rybbit account, organization, administrator and authentication layouts, restore Site Settings property moves, and retain previous UI assets with a startup/reload fallback for open tabs.
22+
23+
### Fixed
24+
25+
- Open the available GA4 page-transitions report directly on Journeys instead of showing unavailable session controls and a source-required screen.
26+
827
## [2.2.1] - 2026-10-25
928

1029
### Improvements

‎DESIGN.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,12 @@ This system is **flat by default**. There is no resting shadow vocabulary; depth
232232

233233
## MetriBee integration
234234

235+
Site settings reuse Rybbit's native dialog shell and General-tab sections, including organization moves and their confirmation dialog. Do not introduce a separate Property access page; keep old URLs compatible by opening the native dialog. GA4 metadata is read-only and unsupported collector controls are omitted. Keep Widgets standalone. The Footer preserves the original 1100px width, 140px logo slot, three-column grid, support-action area and bottom-bar alignment; adapt only branding and destinations to real MetriBee resources.
236+
237+
Account, organization, team, administrator, login and signup pages retain Rybbit's original complete page layouts and native controls. Keep the original content widths, margins, navigation composition, administrator tab order, two-column login and stepped signup. Use data adapters for GA4/SQLite and the approved map source, rather than redesigning these pages.
238+
235239
Search Console belongs in the existing Analytics page, country and device tables. Expose search metrics in the native column-header menu and alongside GA4 columns in the same expanded table; keywords use the existing Sources card. Main places search clicks, impressions, CTR and average position in the top native metric card, with selected-state tiles and sparklines that switch the existing main chart. Pages retains the four native StatBand summary cells alongside its integrated table.
236240

237241
Widget management lives on the standalone property-scoped Widgets page. Reuse the native sidebar, compact list rows, controls and shared Funnels editor; keep badges, metrics-only components and trend cards within one custom builder, without separate legacy embed tabs.
238242

239-
The owner requested native Rybbit UI reuse on October 22, 2026. The analytics workspace uses the original Rybbit theme and React components in `frontend/`, with GA4 data adapters. Main, Pages, Events, Journeys and Retention share one shell and control system. Retain original Radix keyboard behavior and motion presets. Do not add the legacy Instrument Panel palette or Handlebars controls to these pages. The default Home retains the original Rybbit Home/SiteCards and adds Status, Table and Heatmap tabs with shared search, dates and comparison periods. Keep tabs, update time and date controls in one desktop toolbar row. The site overview at `/analytics` merges GA4 reports into the native main chart and topical panels: reuse existing source, page, geography and technology panels rather than adding duplicate reports. Revenue, traffic quality and visitor segments use the same native tabbed cards. All historical panels share the overview's dates and filters. `/analytics/reports` is only a compatibility redirect. Sites reports live in Home; legacy `/sites` links redirect to the matching Home tab. Keep `/realtime`, Globe, quota and connection as distinct screens. No user menu or Documentation entry. The former design is archived at `docs/legacy-panel-design.md`. Imported source and license notices are in `frontend/third-party/`.
243+
The owner requested native Rybbit UI reuse on October 22, 2026. The analytics workspace uses the original Rybbit theme and React components in `frontend/`, with GA4 data adapters. Main, Pages, Events, Journeys and Retention share one shell and control system. Retain original Radix keyboard behavior and motion presets. Do not add the legacy Instrument Panel palette or Handlebars controls to these pages. The default Home retains the original Rybbit Home/SiteCards and adds Status, Table and Heatmap tabs with shared search, dates and comparison periods. Keep tabs, update time and date controls in one desktop toolbar row. The site overview at `/analytics` merges GA4 reports into the native main chart and topical panels: reuse existing source, page, geography and technology panels rather than adding duplicate reports. Revenue, traffic quality and visitor segments use the same native tabbed cards. All historical panels share the overview's dates and filters. `/analytics/reports` is only a compatibility redirect. Sites reports live in Home; legacy `/sites` links redirect to the matching Home tab. Keep `/realtime`, Globe, quota and connection as distinct screens. Use the native Rybbit account, organization, team and administrator navigation and controls. No Documentation entry. The former design is archived at `docs/legacy-panel-design.md`. Imported source and license notices are in `frontend/third-party/`.

0 commit comments

Comments
 (0)