Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat(admin-stats): active orgs per post creation source

Gilad Resisid0c5d7c8369f
diff --git a/apps/frontend/src/components/admin/admin-stats.component.tsx b/apps/frontend/src/components/admin/admin-stats.component.tsx
index 1b5a51659..2673eaa3b 100644
--- a/apps/frontend/src/components/admin/admin-stats.component.tsx
+++ b/apps/frontend/src/components/admin/admin-stats.component.tsx
@@ -27,6 +27,7 @@ interface StatsResponse {
scheduledAccounts?: StatsBlock;
publishingChannels?: StatsBlock;
scheduledChannels?: StatsBlock;
+ activeOrgsBySource?: StatsBlock;
}
const isoDaysAgo = (days: number) => {
@@ -280,6 +281,14 @@ export const AdminStatsComponent: FC = () => {
/>
</div>
)}
+ {data.activeOrgsBySource && (
+ <div className="flex-1 min-w-[220px] shrink-0">
+ <SummaryCard
+ label="Unique users - active (all sources combined)"
+ value={data.activeOrgsBySource.total}
+ />
+ </div>
+ )}
</div>
<div className="flex gap-[12px] items-start">
@@ -337,6 +346,14 @@ export const AdminStatsComponent: FC = () => {
/>
</div>
)}
+ {data.activeOrgsBySource && (
+ <div className="flex-1 min-w-[220px] shrink-0">
+ <PerSocialTable
+ title="Active users per source"
+ block={data.activeOrgsBySource}
+ />
+ </div>
+ )}
</div>
</div>
)}
diff --git a/libraries/nestjs-libraries/src/database/prisma/admin-stats/admin-stats.repository.ts b/libraries/nestjs-libraries/src/database/prisma/admin-stats/admin-stats.repository.ts
index 7e875f213..160825a52 100644
--- a/libraries/nestjs-libraries/src/database/prisma/admin-stats/admin-stats.repository.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/admin-stats/admin-stats.repository.ts
@@ -27,6 +27,7 @@ export interface StatsResponse {
scheduledAccounts: { total: number; perSocial: PerSocial[] };
publishingChannels: { total: number; perSocial: PerSocial[] };
scheduledChannels: { total: number; perSocial: PerSocial[] };
+ activeOrgsBySource: { total: number; perSocial: PerSocial[] };
}
const sortDesc = (list: PerSocial[]) =>
@@ -212,6 +213,43 @@ export class AdminStatsRepository {
};
}
+ // Distinct organizations with at least one top-level scheduled, published
+ // or failed post in the range, per creation source (web, API, MCP, ...).
+ // The total is distinct across all sources combined, not a summation.
+ private async sourceStats(params: StatsParams) {
+ const where: Prisma.PostWhereInput = {
+ parentPostId: null,
+ deletedAt: null,
+ publishDate: { gte: params.from, lte: params.to },
+ state: { in: ['QUEUE', 'PUBLISHED', 'ERROR'] },
+ };
+
+ const groups = await this._post.model.post.groupBy({
+ by: ['organizationId', 'creationMethod'],
+ where,
+ });
+
+ const allOrgs = new Set<string>();
+ const orgsBySource = new Map<string, Set<string>>();
+ for (const g of groups) {
+ if (!orgsBySource.has(g.creationMethod)) {
+ orgsBySource.set(g.creationMethod, new Set());
+ }
+ orgsBySource.get(g.creationMethod)!.add(g.organizationId);
+ allOrgs.add(g.organizationId);
+ }
+
+ return {
+ total: allOrgs.size,
+ perSocial: sortDesc(
+ [...orgsBySource.entries()].map(([provider, orgs]) => ({
+ provider,
+ count: orgs.size,
+ }))
+ ),
+ };
+ }
+
private async connectedStats(params: StatsParams) {
const where: Prisma.IntegrationWhereInput = {
deletedAt: null,
@@ -239,12 +277,14 @@ export class AdminStatsRepository {
}
async getStats(params: StatsParams): Promise<StatsResponse> {
- const [errors, posts, accounts, connected] = await Promise.all([
- this.errorStats(params),
- this.postStats(params),
- this.accountStats(params),
- this.connectedStats(params),
- ]);
+ const [errors, posts, accounts, connected, activeOrgsBySource] =
+ await Promise.all([
+ this.errorStats(params),
+ this.postStats(params),
+ this.accountStats(params),
+ this.connectedStats(params),
+ this.sourceStats(params),
+ ]);
return {
from: params.from.toISOString(),
@@ -256,6 +296,7 @@ export class AdminStatsRepository {
scheduledAccounts: accounts.scheduledAccounts,
publishingChannels: accounts.publishingChannels,
scheduledChannels: accounts.scheduledChannels,
+ activeOrgsBySource,
};
}
}