feat: add organization ID to MAU stats in Cloudflare Analytics Engine#1223
Conversation
- Add org_id parameter to trackDeviceUsageCF function - Include org_id in Cloudflare Analytics indexes alongside app_id - Update createStatsMau to accept and pass org_id - Modify update.ts to pass appOwner.owner_org to MAU tracking - Update DeviceUsageCF interfaces to include org_id field - Modify readDeviceUsageCF query to retrieve org_id from index2 - Enable organization-level MAU analytics and activity detection This change allows for organization-level queries and filtering of MAU statistics in Cloudflare Analytics Engine, enabling future features like activity detection for organizations with recent MAU stats.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughExtended device-usage tracking to include org_id across Cloudflare analytics. Updated function signatures, interfaces, and MAU aggregation to carry org identifiers. Propagated org_id from update flow into stats collection. Adjusted analytics indexes and read path to handle org_id. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Client
participant Update as updateWithPG
participant Stats as createStatsMau
participant CF as trackDeviceUsageCF (Cloudflare)
participant Analytics as CF Analytics Store
Client->>Update: Request triggering update
Update->>Stats: createStatsMau(c, device_id, app_id, org_id)
alt DEVICE_USAGE enabled
Stats->>CF: trackDeviceUsageCF(c, device_id, app_id, org_id)
CF->>Analytics: Write usage {device_id, app_id, org_id, ...}
CF-->>Stats: ack
else DEVICE_USAGE disabled
Stats-->>Update: no-op for CF path
end
Update-->>Client: Response
note over Analytics: Reads/grouping now include org_id in MAU aggregation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
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. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
supabase/functions/_backend/utils/cloudflare.ts (1)
45-47: Confirm Analytics Engine dataset supports the extra index
writeDataPointnow emits two indexes. Please double-check thedevice_usagedataset was recreated or pre-provisioned with a second index slot—otherwise Cloudflare rejects the write with a schema mismatch.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
supabase/functions/_backend/utils/cloudflare.ts(4 hunks)supabase/functions/_backend/utils/stats.ts(1 hunks)supabase/functions/_backend/utils/update.ts(1 hunks)
🔇 Additional comments (2)
supabase/functions/_backend/utils/update.ts (1)
145-145: Org context propagation looks goodPassing
appOwner.owner_orghere keeps the MAU write path aligned with the new Cloudflare schema while still tolerating missing orgs downstream.supabase/functions/_backend/utils/stats.ts (1)
10-15: Signature update stays backward-compatibleOptional
org_idparameter keeps existing call sites compiling while letting the Cloudflare path enrich its payload—nice tidy extension.
| c.env.DEVICE_USAGE.writeDataPoint({ | ||
| blobs: [device_id], | ||
| indexes: [app_id], | ||
| indexes: [app_id, org_id || ''], |
There was a problem hiding this comment.
Ca ne crée pas de problèmes de créer un indexe sur une potentielle chaîne vide ?
|
@WcaleNieWolny this change make Cloudflare change but forget Supabase both systems are iso with your change only in CF they unsync |
|
@riderx You have previously agreed that the system will be Cloudflare only. I have been working under this assumption |
…-go/capgo into include_org_id_in_cf_mau_usage_table
|
|
All what we do is use in prod in cloudflare but we never let the code desync |
|
We have test, we have many thing who rely on this code .... |



This change allows for organization-level queries and filtering of MAU statistics in Cloudflare Analytics Engine, enabling future features like activity detection for organizations with recent MAU stats.
Summary by CodeRabbit