Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
feat: admin stats active users (#9857)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiejaoude authored Dec 7, 2023
1 parent b00c884 commit 29a142b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pages/admin/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ export default function Statistics({ stats }) {
{ id: 5, name: "Premium Profiles", value: stats.totalPremiumProfiles },
{ id: 6, name: "Changelogs", value: stats.totalChangelogs },
{ id: 6, name: "Custom Domains", value: stats.totalCustomDomains },
{
id: 7,
name: "Active in last 1 month",
value: stats.totalActiveProfiles["1month"],
},
{
id: 8,
name: "Active in last 6 month",
value: stats.totalActiveProfiles["6month"],
},
];

return (
Expand Down
21 changes: 21 additions & 0 deletions pages/api/admin/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ export async function getStatsApi() {
logger.error(e, "failed to load totalCustomDomains profiles");
}

let dateOneMonthAgo = new Date();
dateOneMonthAgo.setMonth(dateOneMonthAgo.getMonth() - 1); // 1 month ago
let dateSixMonthAgo = new Date();
dateSixMonthAgo.setMonth(dateSixMonthAgo.getMonth() - 6); // 6 month ago
let totalActiveProfiles = { "1month": 0, "6month": 0 };
try {
totalActiveProfiles["1month"] = await Profile.countDocuments({
updatedAt: { $gt: dateOneMonthAgo },
});
} catch (e) {
logger.error(e, "failed to load totalActiveProfiles profiles");
}
try {
totalActiveProfiles["6month"] = await Profile.countDocuments({
updatedAt: { $gt: dateSixMonthAgo },
});
} catch (e) {
logger.error(e, "failed to load totalActiveProfiles profiles");
}

return {
statusCode: 200,
stats: {
Expand All @@ -83,6 +103,7 @@ export async function getStatsApi() {
totalPremiumProfiles: totalPremiumProfiles || 0,
totalChangelogs: totalChangelogs || 0,
totalCustomDomains: totalCustomDomains || 0,
totalActiveProfiles: totalActiveProfiles,
},
};
}

0 comments on commit 29a142b

Please sign in to comment.