Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/pages/admin/dashboard/users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const globalStatsTrendData = ref<Array<{
plan_team: number
plan_enterprise: number
registers_today: number
demo_apps_created: number
devices_last_month: number
}>>([])

Expand Down Expand Up @@ -476,6 +477,7 @@ const onboardingFunnelTrendSeries = computed(() => {
return []

const trend = onboardingFunnelData.value.trend
const demoAppsCreatedByDate = new Map(globalStatsTrendData.value.map(item => [item.date, item.demo_apps_created]))
return [
{
label: 'New Organizations',
Expand Down Expand Up @@ -509,6 +511,14 @@ const onboardingFunnelTrendSeries = computed(() => {
})),
color: '#10b981', // green
},
{
label: 'Demo Apps Created',
data: trend.map(item => ({
date: item.date,
value: demoAppsCreatedByDate.get(item.date) ?? 0,
})),
color: '#ef4444', // red
},
]
})

Expand Down
3 changes: 3 additions & 0 deletions src/types/supabase.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@ export type Database = {
credits_bought: number
credits_consumed: number
date_id: string
demo_apps_created: number
devices_last_month: number | null
devices_last_month_android: number | null
devices_last_month_ios: number | null
Expand Down Expand Up @@ -1157,6 +1158,7 @@ export type Database = {
credits_bought?: number
credits_consumed?: number
date_id: string
demo_apps_created?: number
devices_last_month?: number | null
devices_last_month_android?: number | null
devices_last_month_ios?: number | null
Expand Down Expand Up @@ -1216,6 +1218,7 @@ export type Database = {
credits_bought?: number
credits_consumed?: number
date_id?: string
demo_apps_created?: number
devices_last_month?: number | null
devices_last_month_android?: number | null
devices_last_month_ios?: number | null
Expand Down
18 changes: 18 additions & 0 deletions supabase/functions/_backend/triggers/logsnag_insights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { MiddlewareKeyVariables } from '../utils/hono.ts'
import type { Database } from '../utils/supabase.types.ts'
import { Hono } from 'hono/tiny'
import { getPluginBreakdownCF, readActiveAppsCF, readLastMonthDevicesByPlatformCF, readLastMonthDevicesCF, readLastMonthUpdatesCF } from '../utils/cloudflare.ts'
import { DEMO_APP_PREFIX } from '../utils/demo.ts'
import { BRES, middlewareAPISecret } from '../utils/hono.ts'
import { cloudlog, cloudlogErr } from '../utils/logging.ts'
import { logsnag, logsnagInsights } from '../utils/logsnag.ts'
Expand Down Expand Up @@ -64,6 +65,7 @@ interface GlobalStats {
upgraded_orgs: PromiseLike<number>
credits_bought: PromiseLike<number>
credits_consumed: PromiseLike<number>
demo_apps_created: PromiseLike<number>
plugin_breakdown: PromiseLike<PluginBreakdownResult>
build_stats: PromiseLike<BuildStats>
}
Expand Down Expand Up @@ -511,6 +513,18 @@ function getStats(c: Context): GlobalStats {
}
return (res.data || []).reduce((sum, row) => sum + (Number(row.credits_used) || 0), 0)
}),
demo_apps_created: supabase
.from('apps')
.select('id', { count: 'exact', head: true })
.gte('created_at', last24h)
.like('app_id', `${DEMO_APP_PREFIX}%`)
Comment on lines +517 to +520
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

This query counts demo apps using a UTC calendar-day window (created_at >= todayStartIso and < tomorrowStartIso). The migration/comment/PR text describe "last 24 hours" and other metrics here use the rolling last24h window, so the semantics are inconsistent (and can be a partial-day count depending on when the cron runs). Either switch to gte('created_at', last24h) or rename/document this as "created today (UTC)" end-to-end.

Copilot uses AI. Check for mistakes.
.then((res) => {
if (res.error) {
cloudlog({ requestId: c.get('requestId'), message: 'demo_apps_created error', error: res.error })
return 0
}
return res.count ?? 0
}),
plugin_breakdown: getPluginBreakdownCF(c),
build_stats: getBuildStats(c),
}
Expand Down Expand Up @@ -544,6 +558,7 @@ app.post('/', middlewareAPISecret, async (c) => {
upgraded_orgs,
credits_bought,
credits_consumed,
demo_apps_created,
plugin_breakdown,
build_stats,
] = await Promise.all([
Expand All @@ -570,6 +585,7 @@ app.post('/', middlewareAPISecret, async (c) => {
res.upgraded_orgs,
res.credits_bought,
res.credits_consumed,
res.demo_apps_created,
res.plugin_breakdown,
res.build_stats,
])
Expand All @@ -590,6 +606,7 @@ app.post('/', middlewareAPISecret, async (c) => {
devices_last_month,
registers_today,
bundle_storage_gb,
demo_apps_created,
})
// cloudlog(c.get('requestId'), 'app', app.app_id, downloads, versions, shared, channels)
// create var date_id with yearn-month-day
Expand Down Expand Up @@ -643,6 +660,7 @@ app.post('/', middlewareAPISecret, async (c) => {
// Credits tracking (round to integers for bigint column)
credits_bought: Math.round(credits_bought),
credits_consumed: Math.round(credits_consumed),
demo_apps_created,
// Plugin version breakdown (percentage per version)
plugin_version_breakdown: plugin_breakdown.version_breakdown,
plugin_major_breakdown: plugin_breakdown.major_breakdown,
Expand Down
3 changes: 3 additions & 0 deletions supabase/functions/_backend/utils/pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@ export interface AdminGlobalStatsTrend {
plan_team: number
plan_enterprise: number
registers_today: number
demo_apps_created: number
devices_last_month: number
devices_last_month_ios: number
devices_last_month_android: number
Expand Down Expand Up @@ -1031,6 +1032,7 @@ export async function getAdminGlobalStatsTrend(
plan_team::int,
plan_enterprise::int,
registers_today::int,
COALESCE(demo_apps_created, 0)::int AS demo_apps_created,
devices_last_month::int,
COALESCE(devices_last_month_ios, 0)::int AS devices_last_month_ios,
COALESCE(devices_last_month_android, 0)::int AS devices_last_month_android,
Expand Down Expand Up @@ -1082,6 +1084,7 @@ export async function getAdminGlobalStatsTrend(
plan_team: Number(row.plan_team) || 0,
plan_enterprise: Number(row.plan_enterprise) || 0,
registers_today: Number(row.registers_today) || 0,
demo_apps_created: Number(row.demo_apps_created) || 0,
devices_last_month: Number(row.devices_last_month) || 0,
devices_last_month_ios: Number(row.devices_last_month_ios) || 0,
devices_last_month_android: Number(row.devices_last_month_android) || 0,
Expand Down
3 changes: 3 additions & 0 deletions supabase/functions/_backend/utils/supabase.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@ export type Database = {
credits_bought: number
credits_consumed: number
date_id: string
demo_apps_created: number
devices_last_month: number | null
devices_last_month_android: number | null
devices_last_month_ios: number | null
Expand Down Expand Up @@ -1157,6 +1158,7 @@ export type Database = {
credits_bought?: number
credits_consumed?: number
date_id: string
demo_apps_created?: number
devices_last_month?: number | null
devices_last_month_android?: number | null
devices_last_month_ios?: number | null
Expand Down Expand Up @@ -1216,6 +1218,7 @@ export type Database = {
credits_bought?: number
credits_consumed?: number
date_id?: string
demo_apps_created?: number
devices_last_month?: number | null
devices_last_month_android?: number | null
devices_last_month_ios?: number | null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE public.global_stats
ADD COLUMN demo_apps_created integer NOT NULL DEFAULT 0;

COMMENT ON COLUMN public.global_stats.demo_apps_created IS 'Number of demo apps created in the last 24 hours';
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

The column comment says this metric is for "the last 24 hours", but the implementation in logsnag_insights counts demo apps within the current UTC day window (00:00–24:00 UTC). Either update the comment to reflect the UTC-day semantics, or change the aggregation to use a rolling last-24h window for consistency with the column description.

Suggested change
COMMENT ON COLUMN public.global_stats.demo_apps_created IS 'Number of demo apps created in the last 24 hours';
COMMENT ON COLUMN public.global_stats.demo_apps_created IS 'Number of demo apps created during the current UTC day (00:00–24:00 UTC)';

Copilot uses AI. Check for mistakes.