Counts users by role, position and other select, radio or relationship fields, plus new-account totals and post-count bands. Results appear on a dashboard card, an admin view and a GET endpoint, visible only to users your required access function allows. Responses contain only configured labels and numbers, never names, emails or IDs, and counts below a minimum are hidden. Requires Payload 3.80 or later; count bands need the MongoDB adapter.
Stats for Payload: counts of users by role, position and other fields, shown to whoever your access function allows, with no names, emails or IDs, and small groups hidden.
Installation
npm i @extantape/payload-plugin-stats0
Stars
0
Forks
0
Open Issues
1 weeks ago
Last Updated
80
Weekly Downloads
v0.1.0
npm Version
67.4 KB
Unpacked Size
0
Dependencies
00 since Nov 22
| Date | Stars |
|---|---|
| Dec 6, 2026 | 0 |
| Dec 5, 2026 | 0 |
| Dec 4, 2026 | 0 |
| Dec 3, 2026 | 0 |
| Dec 2, 2026 | 0 |
| Dec 1, 2026 | 0 |
| Nov 30, 2026 | 0 |
| Nov 29, 2026 | 0 |
| Nov 28, 2026 | 0 |
| Nov 27, 2026 | 0 |
| Nov 26, 2026 | 0 |
| Nov 25, 2026 | 0 |
| Nov 24, 2026 | 0 |
| Nov 23, 2026 | 0 |
| Nov 22, 2026 | 0 |
84+84 since Nov 28
| Date | Weekly downloads |
|---|---|
| Dec 6, 2026 | 84 |
| Dec 5, 2026 | 250 |
| Dec 4, 2026 | 242 |
| Dec 3, 2026 | 240 |
| Dec 2, 2026 | 232 |
| Dec 1, 2026 | 223 |
| Nov 30, 2026 | 200 |
| Nov 29, 2026 | 178 |
| Nov 28, 2026 | 0 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1472518754-root)<a href="https://payloaddirectory.dev/plugins/1472518754-root"><img src="https://payloaddirectory.dev/badge/1472518754-root.svg" alt="Payload Directory"></a>README
Stats for Payload: counts of users by role, position and other fields, shown to whoever your access function allows, with no names, emails or IDs, and small groups hidden.
Status: 0.1.0, the first release. 175 tests pass against a real Payload 3.92 and a real MongoDB 8: the counts, the hiding rules and every refusal. The dashboard card and the admin view have been rendered to HTML in tests and have not been opened in a browser inside a running admin yet. It has not run on a site with real data yet.
access function allows, in three places: a card on the dashboard, an admin view at /admin/stats, and a JSON endpoint at GET /api/stats.A user with several values in a field is counted in each of them. An admin who also holds another role counts in both rows, so admin accounts can stay in the numbers. For such a field the counts also show how many users hold two values at once; see the limits below.
GET endpoint and no collection.No count from 1 to 4 is ever shown (with the default minimum of 5). A zero shows as 0, because a zero is nobody.
Hiding one number is often not enough. If 40 users split into 30, 7 and a hidden 3, anyone can subtract. Hiding a second number, picked by size, is not enough either: this code is public, so which number got picked tells a careful reader about the one it protects. So the plugin hides by table. What it hides depends on how the report is laid out and never on which numbers are large:
A hidden count says nothing about its own size. It may be small or large.
The total is always shown, even when it is under the minimum. Anyone who can see the stats can usually read the number of users off the users list, so the plugin treats the total as public and hides everything else against a reader who knows it.
Limits, stated plainly:
hasMany fields and to fields inside arrays. What a reader gets is the overlap and what follows from it. In a field with three values and a roll-up, for example, the number of users holding at most one value can be bounded, though never pinned to one number. If that is sensitive on your site, leave the field out. Each row, each roll-up, and the users with some value who lack one particular value are still protected.access function must let in only people who are allowed to know that number. This matters most on a site with several tenants, where a tenant's admin may see only their own users in the admin panel. Every other count is taken the same way, across all users.categories or in bands. Category titles are read, and documents are counted, past those rules. Field-level rules are different: a field kept from readers is refused, as listed below.minimum shows more, and it cannot go below 2.On its own: Stats needs only Payload and your access function. It counts fields on your users collection and adds one endpoint, an admin view and a dashboard card. It doesn't depend on any other plugin.
Needs: Payload ^3.80.0, @payloadcms/next ^3.80.0, @payloadcms/ui ^3.80.0 and React ^19.0.0 as peer dependencies. No other EXTANT APE plugin is required.
Works with:
tenants.roles, the layout Roles uses by default, as the Install example does.Color Theory: no direct link. The report uses Payload's --theme-elevation-* colors, so it follows Color Theory's admin colors when its applyToAdmin option is on.
npm install @extantape/payload-plugin-stats
Needs Payload 3.80 or later, Node 22 or later, and ESM. Count bands need the MongoDB adapter; the other counts use Payload's own count and have only been tested on MongoDB.
import { stats } from '@extantape/payload-plugin-stats'
export default buildConfig({
// ...
plugins: [
stats({
// Required. Who may see the stats. The whole check is yours: collection, role, tenant.
access: ({ req }) => req.user?.collection === 'users' && req.user.roles?.includes('admin') === true,
// Collections whose titles are categories, never people.
categories: ['positions'],
fields: [
{ path: 'roles', label: 'Roles', groups: [{ label: 'Staff', values: ['admin', 'editor'] }] },
{ path: 'position', label: 'Positions' },
'tenants.roles',
],
bands: [{ collection: 'posts', field: 'author', thresholds: [1, 5, 10, 25, 50], label: 'Posts per user' }],
}),
],
})
Then run payload generate:importmap, so the admin can find the card and the view.
| Option | Default | What it does |
|---|---|---|
users | 'users' | The auth collection to count. |
access | none, required | Who may see the stats: ({ req }) => boolean. Only an exact true allows. Anything else, or a throw, refuses. |
categories | [] | Collection slugs whose document titles are categories, such as ['positions']. A relationship field can be counted only when it points at one of these. |
allowCollectionReadHooks | [] | Slugs of the users collection or of band collections that have a collection-level afterRead or beforeRead hook you have checked. See below. |
minimum | 5 | Counts from 1 to one under this never show. A whole number, 2 or more. |
fields | [] | Fields on the users collection to count by. A path, or { path, label, groups, maxValues }. |
bands | [] | { collection, field, thresholds, label }: users with more than N documents in collection, where field is a relationship to the users collection. One band per field. |
path | '/stats' | Path of the endpoint (under the API route) and of the view (under the admin route). |
admin | { card: true, view: true } | Set either to false to leave it out. |
Access is a required function, and there is no default. The plugin refuses to start without one, and it refuses anything that is not a function (true, 'yes', 1, {}, false, null). It does not fall back to the users collection's access.admin: in Payload that rule decides who may open the admin panel, and on many sites editors can. Write the check for the people who should see the numbers. If the site has more than one auth collection, check req.user.collection too, as the example does.
The check of who someone is belongs to your access function. The plugin itself only turns away signed-out requests, before your function runs. It does not look at roles, at which auth collection the user is from, or at tenants. A signed-in user from any auth collection reaches your function, and whoever it answers true for sees every count.
Fields can be select, radio or relationship fields, at the top level or inside groups, tabs, rows and arrays (tenants.roles). hasMany works, with the overlap limit above. groups are roll-ups for select and radio fields: users holding any of the listed values.
A relationship field needs its collection listed in categories. A relationship is broken down by the related document's title, up to maxValues documents (default 50), and every title shows as a row label even when its count is hidden. The titles are read past access control. A collection with one document per person, such as profiles titled by full name, would put names in the report, and only you know which collections are like that. So nothing is counted by relationship until you name the collection.
An upload collection with no useAsTitle is titled by its file names, because Payload makes filename its title. A file name like jane-doe.jpg is a name. List an upload collection in categories only when its file names are categories too, or give it a useAsTitle that is.
Bands are "more than N", so 1 means two or more. Use 0 for "at least one". Documents whose user has been deleted are left out.
The plugin checks all of this when Payload starts and stops the boot on a mistake. It refuses:
access, or one that is not a function;categories;access.read, a truthy hidden, or an afterRead hook, which can strip or change the value. A count would show what those hide. The same goes for the title field of a categories collection;virtual is a path such as 'profile.isMinor'. It takes its value through a relationship from another field, which may itself be kept from readers. A plain virtual: true field with no hook is accepted;afterRead or beforeRead hook, unless its slug is in allowCollectionReadHooks;Collection-level read hooks need an opt-in. A collection's own afterRead or beforeRead hook can strip or change documents for readers, and a count reads past it. The plugin cannot tell what a hook does, so it refuses a users collection or a band collection that has one until you list the slug: allowCollectionReadHooks: ['users']. Listing it says you have checked that the hook hides nothing about the fields counted here. Collections in categories need no opt-in, because their titles are read with payload.find, which runs those hooks.
The checks run twice. Once when the plugin is set up, and again when Payload has started, against the config it actually runs. A plugin listed after this one can hide a field or add a hook, and the first check cannot see that. When it passes, the endpoint, the view and the card all work from what that second check resolved, so a title field or a relationship that a later plugin changed is the one used. If the second check fails, Payload still starts, the reason is logged as an error at start-up, and the endpoint answers 503 without counting anything. The view and the card show no numbers either. The same happens if onInit never runs, for example with disableOnInit.
Count only by fields whose values are categories. A select option or a related document's title appears in the report as a row label.
GET /api/stats, signed in as someone the access function allows. Logged out gets 401. Anyone else gets 403. If the second start-up check did not pass, someone the access function allows gets 503; logged out is still 401 and anyone else still 403. Responses are never cached.
{
"generatedAt": "2026-11-25T18:00:00.000Z",
"minimum": 5,
"totals": {
"all": { "value": 40, "text": "40" },
"newYesterday": { "value": null, "hidden": "protected", "text": "hidden" },
"new7Days": { "value": 9, "text": "9" },
"new30Days": { "value": 20, "text": "20" }
},
"fields": [
{
"path": "roles",
"label": "Roles",
"multiple": true,
"any": { "value": 40, "text": "40" },
"none": { "value": 0, "text": "0" },
"groups": [{ "label": "Staff", "count": { "value": null, "hidden": "protected", "text": "hidden" } }],
"values": [{ "label": "admin", "count": { "value": null, "hidden": "protected", "text": "hidden" } }]
}
],
"bands": [
{ "collection": "posts", "field": "author", "label": "Posts per user", "rows": [{ "moreThan": 1, "count": { "value": 20, "text": "20" } }] }
]
}
A hidden count has "value": null. The real number is not in the response. "hidden": "protected" is a count hidden with its table, and it may be any size, zero included.
buildReport(payload, optionsOf(payload.config)) gives the same report to server code. It does no access check at all, so call allowed(options, req) first.
npm install
npm test
The tests start their own MongoDB in a throwaway Docker container on a free local port, keep its data in memory, and remove that container when the run ends, including when the run is stopped with Ctrl-C or killed. Set STATS_TEST_MONGO_URL to use a MongoDB you already have; the tests drop the database named in that URL, and a second one with -late added to its name.
MIT. Copyright (c) 2026 EXTANT APE.
payload plugin analytics
GA4-backed analytics dashboard in the Payload admin with a client-side tracking layer for Next.js front ends
70821/wk37v3
tracking
Tracking global and React providers for PostHog, Google Tag Manager and Vercel Analytics
6132/wk37v3
payload plugin google analytics
Google Analytics 4 dashboard widgets for the Payload admin panel
57621/wk8v3 v4
payload plugin ga4 ecommerce
GA4 reporting dashboards and per-record analytics tabs inside the Payload admin panel
44115/wk10v3
payload dashboard analytics
Show Plausible or Google Analytics data as widgets on the Payload dashboard, collections and globals
4240/wk190v1
payload posthog
Native PostHog integration for Payload Admin covering analytics, session replay, error tracking, logs and feature flags
791.7k/wk0v3