akhrarovsaid

payload plugin pagespeed

by akhrarovsaid
Analytics
v3
^3.50.0
MIT

Overview

Summary generated from the README

Integrates the Google PageSpeed Insights API into Payload. Creating an entry with a URL in the added collection fetches a report and saves it, showing Performance, Accessibility, SEO and Best Practices metrics in the admin panel. Requires a PageSpeed Insights API key and works with Payload 3.50 or later.

Features

  • Adds a PageSpeed Insights collection that fetches a report when an entry with a URL is created
  • Stores full reports in a separate reports collection, optionally on a storage adapter
  • Exposes an HTTP endpoint to run a report by URL or by existing document id
  • Overrides for both collections, including access control
  • Custom functions for generating report file names and storage prefixes
  • Debug option reveals the hidden reports collection

Use cases

  • Track performance and accessibility scores of site pages from within the Payload admin
  • Keep a history of Lighthouse metrics for pages to compare over time
  • Trigger PageSpeed checks on demand through an API endpoint

From the author

A Payload CMS plugin that integrates PageSpeed Insights into your project.

Installation

npm i payload-plugin-pagespeed

51

Stars

1

Forks

0

Open Issues

1 years ago

Last Updated

0

Weekly Downloads

v0.2.1

npm Version

222.0 KB

Unpacked Size

0

Dependencies

GitHub stars

Trends appear after 7 days of data. Daily snapshots have not started yet.

npm weekly downloads

Trends appear after 7 days of data. Daily snapshots have not started yet.

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

Health Score

35/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/1033487453-root.svg)](https://payloaddirectory.dev/plugins/1033487453-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1033487453-root"><img src="https://payloaddirectory.dev/badge/1033487453-root.svg" alt="Payload Directory"></a>
Updated Aug 26, 2025Created Aug 6, 2025Published Aug 26, 2025

README

payload-plugin-pagespeed-banner

npm version npm downloads license GitHub stars

payload-plugin-pagespeed

A Payload CMS plugin that integrates Google PageSpeed Insights into your project. Use it to analyze pages and view performance metrics directly in your Payload admin ui.

Features

  • 🔍 Run PageSpeed Insights checks on demand
  • 📊 Store results in a Payload collection
  • ⚡ Simple setup with minimal configuration
  • 🛠 Works with your existing PayloadCMS project

Demo

payload-plugin-pagespeed-demo.webm

Installation

pnpm add payload-plugin-pagespeed

Getting Started

[!IMPORTANT]
Make sure to get a PageSpeed Insights API key as this plugin requires one to communicate with the PageSpeed API.

Add the plugin to your payload.config.ts:

import { buildConfig } from 'payload/config'
import { pageSpeedPlugin } from 'payload-plugin-pagespeed'

export default buildConfig({
  // ... your config
  plugins: [
    // ... your other plugins
    pageSpeedPlugin({
      apiKey: process.env.PAGESPEED_API_KEY, // Required
    }),
  ],
})

Now start your Payload app:

pnpm dev

You’ll see a new collection in the admin panel where your PageSpeed Insight reports are stored, by default this is the PageSpeed Insights collection.

Usage

  1. Go to the PageSpeed Insights collection in the Payload admin.
  2. Create a new entry with a URL.
  3. The plugin will fetch results from Google PageSpeed Insights and save them (This may take a while as the PageSpeed Insights API analyzes your page).
  4. View metrics such as Performance, Accessibility, SEO, and Best Practices.

create-new-doc

Configuration

The plugin accepts the following options:

KeyTypeDescription
apiKey*string (required)A Google PageSpeed Insights API key.
debugbooleanA boolean that, when true, shows debug information and the hidden reports collection.
disabledbooleanA boolean that, when true, prevents the plugin from mounting the api endpoint in collection config.
generateFileNamefunction (GenerateFileNameFn)An optional function that is invoked to generate a filename for a PageSpeed Insights report object.
generateFilePrefixfunction (GenerateFilePrefixFn)An optional function that is invoked to generate a file prefix for a PageSpeed Insights report object if using a storage adapter.
overrideInsightsCollectionfunction (CollectionOverride)A function used to override the default PageSpeed Insights collection.
overrideReportsCollectionfunction (CollectionOverride)A function used to override the default PageSpeed Reports collection.

[!NOTE] In order to successfully work, the user making the request needs to have both read and create access for the PageSpeed Insights collection. In addition, this plugin sets the update access control on the PageSpeed Insights collection to false. An example below shows customizing access controls and other collection configs.

Example plugin configurations

With custom access controls
import { buildConfig } from 'payload/config'
import { pageSpeedPlugin } from 'payload-plugin-pagespeed'

export default buildConfig({
  // ... your config
  plugins: [
    // ... your other plugins
    pageSpeedPlugin({
      apiKey: process.env.PAGESPEED_API_KEY, // Required
      overrideInsightsCollection: (collection) => ({
        ...collection,
        access: {
          ...collection,
          read: () => true, // Anyone can read the insights collection
          create: () => true, // Anyone can create an insights report
        }
        // ... other overrides
      })
    }),
  ],
})
With storage adapter
import { s3Storage } from '@payloadcms/storage-s3'
import { buildConfig } from 'payload/config'
import { pageSpeedPlugin } from 'payload-plugin-pagespeed'

export default buildConfig({
  // ... your config
  plugins: [
    // ... your other plugins
    s3Storage({
      bucket: process.env.S3_BUCKET || '',
      collections: {
        'pagespeed-reports': true,
      },
      config: {
        credentials: {
          accessKeyId: process.env.S3_ACCESS_KEY_ID || '',
          secretAccessKey: process.env.S3_SECRET || '',
        },
        endpoint: process.env.S3_ENDPOINT || '',
        region: process.env.S3_REGION || '',
      },
    })
    pageSpeedPlugin({
      apiKey: process.env.PAGESPEED_API_KEY, // Required
      generateFilePrefix: ({ collection, req }) => { ... } // Save to specific folder in storage
    }),
  ],
})

API Reference

HTTP request

GET <api-route>/<insights-slug>/:id?/report

The URL segment for api-route is your Payload configured base API route (by default /api), insights-slug is the collection slug for the PageSpeed Insights collection (by default pagespeed-insights), and :id? is an optional parameter representing a PageSpeed Insights doc id.

Query parameters

If a doc id is passed as a url segment, then the query parameters are overriden by the fields in the doc. To view available query parameters, see the PageSpeed API Reference.

Example HTTP request

If no doc id is provided, then the url query parameter is required.

GET /api/pagespeed-insights/report?url=https://payloadcms.com
Example HTTP request with doc id
GET /api/pagespeed-insights/68aa352d42f08695dd833412/report

Response body

A successful request will return:

ParameterTypeDescription
reportPageSpeedReportObject | string | numberThe pagespeed report. This will be a document id if the insights document already has a report generated.
messagestringA message containing the status message of the operation.

Contributing

Contributions are welcome!

If you’d like to improve this plugin, feel free to open an issue or PR.

License

MIT © 2025 saikhon.dev

Similar plugins