NouanceLabs

payload dashboard analytics

by NouanceLabs
Analytics
v1
^1.6.16
MIT

Overview

Summary generated from the README

Connects Plausible or Google Analytics 4 to the Payload admin and adds chart, info and report widgets. Widgets can be placed on the dashboard, on collection and global edit views, and a live visitors indicator can be added to the sidebar. An optional cache collection stores results to avoid API limits. Targets Payload 1.x.

Features

  • Chart and info widgets on collections and globals matched to pages by a custom idMatcher
  • Dashboard widgets for a views chart and top pages
  • Live visitors indicator in the navigation
  • Metrics for views, visitors, sessions, session duration and bounce rate
  • Timeframes from 7 days to 12 months or current month
  • Optional cache collection with configurable per-route durations and an access function for the API routes

Use cases

  • Display page traffic stats next to a blog post while editing it in the admin
  • Give editors a dashboard overview of views and top pages
  • Monitor live visitor counts from the admin sidebar

From the author

Dashboard analytics integration plugin for Payload CMS

Installation

npm i @nouance/payload-dashboard-analytics

190

Stars

6

Forks

18

Open Issues

3 years ago

Last Updated

40

Weekly Downloads

v0.3.0

npm Version

264.8 KB

Unpacked Size

2

Dependencies

GitHub stars

190+9 since Sep 6

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 2026190
Dec 4, 2026190
Dec 3, 2026190
Dec 2, 2026190
Dec 1, 2026190
Nov 30, 2026190
Nov 29, 2026190
Nov 28, 2026190
Nov 27, 2026190
Nov 26, 2026190
Nov 25, 2026190
Nov 24, 2026190
Nov 23, 2026190
Nov 22, 2026190
Nov 21, 2026190
Nov 20, 2026190
Nov 19, 2026190
Nov 18, 2026190
Nov 17, 2026190
Nov 16, 2026190
Nov 15, 2026190
Nov 14, 2026190
Nov 13, 2026189
Nov 12, 2026188
Nov 11, 2026188
Nov 10, 2026188
Nov 9, 2026188
Nov 8, 2026188
Nov 7, 2026188
Nov 6, 2026188
Nov 5, 2026187
Nov 4, 2026187
Nov 3, 2026186
Nov 2, 2026186
Nov 1, 2026186
Oct 31, 2026186
Oct 30, 2026186
Oct 29, 2026186
Oct 28, 2026186
Oct 27, 2026186
Oct 26, 2026185
Oct 25, 2026185
Oct 24, 2026185
Oct 23, 2026185
Oct 22, 2026185
Oct 21, 2026184
Oct 20, 2026184
Oct 19, 2026184
Oct 18, 2026184
Oct 17, 2026184
Oct 16, 2026184
Oct 15, 2026184
Oct 14, 2026184
Oct 13, 2026184
Oct 12, 2026184
Oct 11, 2026183
Oct 10, 2026183
Oct 9, 2026183
Oct 8, 2026183
Oct 7, 2026183
Oct 6, 2026183
Oct 5, 2026183
Oct 4, 2026183
Oct 3, 2026182
Oct 2, 2026182
Oct 1, 2026182
Sep 30, 2026182
Sep 29, 2026182
Sep 28, 2026182
Sep 27, 2026182
Sep 26, 2026182
Sep 25, 2026182
Sep 24, 2026182
Sep 23, 2026181
Sep 22, 2026181
Sep 21, 2026181
Sep 20, 2026181
Sep 19, 2026181
Sep 18, 2026181
Sep 17, 2026181
Sep 16, 2026181
Sep 15, 2026181
Sep 14, 2026181
Sep 13, 2026181
Sep 12, 2026181
Sep 11, 2026181
Sep 10, 2026181
Sep 9, 2026181
Sep 8, 2026181
Sep 7, 2026181
Sep 6, 2026181
npm weekly downloads

48+22 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 202648
Dec 4, 202630
Dec 3, 202634
Dec 2, 202624
Dec 1, 202625
Nov 30, 202626
Nov 29, 202631
Nov 28, 202625
Nov 27, 202627
Nov 26, 202625
Nov 25, 202624
Nov 24, 202622
Nov 23, 202623
Nov 22, 202618
Nov 21, 202630
Nov 20, 202628
Nov 19, 202627
Nov 18, 202639
Nov 17, 202637
Nov 16, 202639
Nov 15, 202644
Nov 14, 202646
Nov 13, 202650
Nov 12, 202649
Nov 11, 202636
Nov 10, 202646
Nov 9, 202643
Nov 8, 202644
Nov 7, 202631
Nov 6, 202625
Nov 5, 202626
Nov 4, 202626
Nov 3, 202620
Nov 2, 202620
Nov 1, 202623
Oct 31, 202621
Oct 30, 202622
Oct 29, 202620
Oct 28, 202620
Oct 27, 202636
Oct 26, 202643
Oct 25, 202646
Oct 24, 202648
Oct 23, 202646
Oct 22, 202647
Oct 21, 202672
Oct 20, 202665
Oct 19, 202670
Oct 18, 202666
Oct 17, 202672
Oct 16, 202675
Oct 15, 202678
Oct 14, 202686
Oct 13, 202676
Oct 12, 202669
Oct 11, 202659
Oct 10, 202654
Oct 9, 202653
Oct 8, 202652
Oct 7, 202622
Oct 6, 202627
Oct 5, 202623
Oct 4, 202626
Oct 3, 202626
Oct 2, 202625
Oct 1, 202624
Sep 30, 202640
Sep 29, 202634
Sep 28, 202632
Sep 27, 202630
Sep 26, 202630
Sep 25, 202630
Sep 24, 202640
Sep 23, 202632
Sep 22, 202650
Sep 21, 202662
Sep 20, 202661
Sep 19, 202658
Sep 18, 202657
Sep 17, 202646
Sep 16, 202636
Sep 15, 202618
Sep 14, 20266
Sep 13, 20266
Sep 12, 20267
Sep 11, 202610
Sep 10, 202612
Sep 9, 202617
Sep 8, 202626
Sep 7, 202628
Sep 6, 202626

Each point is npm's rolling 7-day download count.

Health Score

42/100Fair

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/619101028-root.svg)](https://payloaddirectory.dev/plugins/619101028-root)
HTML
<a href="https://payloaddirectory.dev/plugins/619101028-root"><img src="https://payloaddirectory.dev/badge/619101028-root.svg" alt="Payload Directory"></a>
Updated Aug 28, 2023Created Mar 26, 2023Published May 25, 2023

README

Payload Dashboard Analytics Plugin

A plugin for Payload CMS to connect analytics data to your Payload dashboard.

Features:

  • Chart widgets on collections, globals and dashboard
  • Live users indicator in sidebar
  • Aggregate data widgets on collections and globals
  • Basic report widgets on dashboard
  • Support for Plausible and Google Analytics

Installation

  yarn add @nouance/payload-dashboard-analytics
  # OR
  npm i @nouance/payload-dashboard-analytics

Basic Usage

In the plugins array of your Payload config, call the plugin with options:

// ...
payloadDashboardAnalytics({
  provider: {
    source: "plausible",
    apiSecret: PLAUSIBLE_API_KEY,
    siteId: PLAUSIBLE_SITE_ID,
    host: PLAUSIBLE_HOST, // optional, for self-hosted instances
  },
  cache: true,
  access: (user: any) => {
    return Boolean(user);
  },
  navigation: {
    afterNavLinks: [
      {
        type: "live",
      },
    ],
  },
  dashboard: {
    beforeDashboard: ["viewsChart"],
    afterDashboard: ["topPages"],
  },
  globals: [
    {
      slug: "homepage",
      widgets: [
        {
          type: "info",
          label: "Page data",
          metrics: ["views", "sessions", "sessionDuration"],
          timeframe: "currentMonth",
          idMatcher: () => `/`,
        },
      ],
    },
  ],
  collections: [
    {
      slug: Posts.slug,
      widgets: [
        {
          type: "chart",
          label: "Views and visitors",
          metrics: ["views", "visitors", "sessions"],
          timeframe: "30d",
          idMatcher: (document: any) => `/articles/${document.slug}`,
        },
      ],
    },
  ],
}),

// ...

Configuration

  • provider | required

    Configuration for a supported provider.

  • access | optional

    Accepts a function that takes in the req.user object to determine access to the API routes. By default the routes are unprotected.

    Example to allow only authenticated users:

    access: (user: any) => Boolean(user);
    
  • cache | optional

    Accepts a boolean or a configuration object for cache management. Defaults to false.
    This creates a new collection type that will store cached data so that you don't get limited by the API.

    cache: true;
    
    • slug | optional

      You can customise the slug of this new collection to avoid conflicts. Defaults to analyticsData.

    • routes | optional

      By default all routes are cached to one day. This is because for most analytics platforms the data report is about one day out anyway. Live data is cached to 5 minutes.

      Object with any of these keys globalAggregate globalChart pageAggregate pageChart report live set to a number in minutes.

      routes?: {
        globalAggregate: 1440;
        globalChart: 1440;
        pageAggregate: 1440;
        pageChart: 1440;
        report: 1440;
        live: 5;
      };
      
  • navigation | optional

    Object of either beforeNavLinks afterNavLinks which are arrays of navigation widgets.

  • dashboard | optional

    Object of either beforeDashboard afterDashboard which are arrays of dashboard widgets.

  • globals | optional

    Array of global configurations requiring a slug and an array of page widgets.

  • collections | optional

    Array of collection configurations requiring a slug and an array of page widgets.

Widgets

A full list of supported widgets. Due to some time limitations or API constraints the selection may be limited.

Navigation

Navigation widgets have no configuration.

Live visitors

Screenshot from 2023-04-12 18-12-58

type live

{
  type: "live";
}

Dashboard

Dashboard widgets have no configuration.

Views chart

Screenshot from 2023-04-12 18-13-28

type viewsChart

["viewsChart"];
Top pages

Screenshot from 2023-04-12 18-13-36

type topPages

["topPages"];

Page

Page widgets have more configuration available with custom timeframes and metrics. These are usable on both globals and collections.

Page chart

Screenshot from 2023-04-12 18-13-08

  • type | chart | required

  • label | string or hidden | optional
    Sets a custom label for the component in the frontend, defaults to a list of metrics and it's accompanied by the timeframe.
    If hidden then the label is not displayed.

  • metrics | metric[] | required
    Array of metrics to fetch data for. See list of available metrics.

  • timeframe | timeframe | optional
    Defaults to 30d. See list of available timeframes.

  • idMatches | function | required A function that takes in the published document from the React hook useDocument and returns a string that matches the current page to a page in the analytics data.

{
  type: "chart",
  label: "Views and visitors",
  metrics: ["views", "visitors", "sessions"],
  timeframe: "30d",
  idMatcher: (document: any) => `/blog/${document.slug}`,
}
Page info

Screenshot from 2023-04-12 18-13-17

  • type | info | required

  • label | string or hidden | optional
    Sets a custom label for the component in the frontend, defaults to a list of metrics and it's accompanied by the timeframe.
    If hidden then the label is not displayed.

  • metrics | metric[] | required
    Array of metrics to fetch data for. See list of available metrics.

  • timeframe | timeframe | optional
    Defaults to 30d. See list of available timeframes.

  • idMatches | function | required A function that takes in the published document from the React hook useDocument and returns a string that matches the current page to a page in the analytics data.

{
  type: "info",
  label: "Views and visitors",
  metrics: ["views", "visitors", "sessions"],
  timeframe: "7d",
  idMatcher: (document: any) => `/blog/${document.slug}`,
}

Timeframes

Currently supported timeframes.

  • 12mo
  • 6mo
  • 30d
  • 7d
  • currentMonth limits the data period to the current month

Metrics

A full list of currently supported metrics, each provider will map these on their own internally to the API they communicate with.

  • views
  • visitors
  • sessions
  • sessionDuration
  • bounceRate

Properties

Properties are used to generate reports, currently the widgets are limited in configuration but these should be fully supported via the API routes.

  • page
  • source
  • entryPoint
  • exitPoint
  • country

Providers

Plausible

We support Plausible's Stats API, more information on their website.

  • source | "plausible" | required

  • apiSecret | string | required You can generate an API secret in the admin panel of Plausible.

  • siteId | string | required

  • host | string | optional

    Set this value to the full domain host including protocol if you're self hosting Plausible, eg. https://plausible.example.com

Example

const plausibleProvider: PlausibleProvider = {
  source: "plausible",
  apiSecret: PLAUSIBLE_API_KEY,
  siteId: PLAUSIBLE_SITE_ID,
  host: PLAUSIBLE_HOST,
};

Google Analytics

We support the GA4 Analytics API only. You will need to get a credentials file from Google here, and follow the initial setup instructions so that these credentials have the correct read access to your analytics data.

  • source | "google" | required

  • propertyId | string | required The id of your target property, you can find this information in the GA property settings panel.

  • credentials | string | optional Path to your credentials.json file, make sure the filesystem has access to this, alternatively, set an environment variable named GOOGLE_APPLICATION_CREDENTIALS with the path to the credentials file.

Example

const googleProvider: GoogleProvider = {
  source: "google",
  credentials: GOOGLE_CREDENTIALS_FILE,
  propertyId: GOOGLE_PROPERTY_ID,
};

API

To do, add API documentation.

Known issues

Multi-metric charts have a floating tooltip in the wrong position, this is a problem upstream.

Development

For development purposes, there is a full working example of how this plugin might be used in the demo of this repo. Then:

git clone [email protected]:NouanceLabs/payload-dashboard-analytics.git \
  cd payload-dashboard-analytics && yarn \
  cd demo && yarn \
  cp .env.example .env \
  vim .env \ # add your API creds to this file
  yarn dev

Add custom provider

Tbd

Similar plugins