npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

payload-ga-4

v0.1.6

Published

Google Analytics 4 (GA4) plugin for Payload CMS. Add analytics widgets and dashboards to admin panel with service account authentication.

Readme

Google Analytics 4 (GA4) Plugin for Payload CMS

Payload GA4 Dashboard

Add Google Analytics 4 (GA4) widgets and dashboards directly to your Payload CMS admin panel using your Google Developer Service Account credentials.

Features

  • Custom Analytics Dashboard View (/analytics)
  • Widgets that can be placed in Dashboard, Collections, or Globals
  • Support for multiple timeframes (7d, 30d, 90d)
  • Service Account based authentication (No OAuth screens required)

Installation

npm install payload-ga-4
# or
yarn add payload-ga-4
# or
pnpm add payload-ga-4

Setup Google Analytics

To use this plugin, you'll need a Google Cloud Service Account and a GA4 Property ID.

  1. Go to Google Cloud Console
  2. Create a new Service Account and download the JSON key.
  3. Keep note of the client_email and private_key from the JSON.
  4. Go to Google Analytics Admin
  5. Find your GA4 Property ID (Admin > Property Settings).
  6. Give your Service Account email "Viewer" access to your GA4 property under Property Access Management.

Configuration

Import the payloadGa4 plugin and add it to your payload.config.ts.

import { buildConfig } from 'payload'
import { payloadGa4 } from 'payload-ga-4'

export default buildConfig({
  // ... other payload config
  plugins: [
    payloadGa4({
      enabled: true,
      
      // Look for the Property ID in Google Analytics Admin > Property > Property Settings
      propertyId: process.env.GA_PROPERTY_ID!,
      
      // Google Service Account Credentials
      credentials: {
        type: 'service_account', // or process.env.GA_ANALYTIC_TYPE
        clientEmail: process.env.GA_ANALYTIC_CLIENT_EMAIL!,
        // Note: ensure \n is handled properly if parsed from .env string
        privateKey: process.env.GA_ANALYTIC_PRIVATE_KEY!,
      },

      defaultTimeframe: '30d',
      
      // Where to show the analytics dashboard widget
      placement: ['dashboard', 'root'],
      
      // Widget specific config
      widget: {
        title: 'Google Analytics',
      },
      
      // Access control for the analytics data
      access: async (user) => {
        return user ? true : false
      },
    }),
  ],
})

Options

| Option | Type | Description | |--------|------|-------------| | enabled | boolean | Whether to enable the plugin (default: false). | | propertyId | string | Required. Your GA4 Property ID. | | credentials.type | string | Typically 'serviceAccount' / 'service_account' | | credentials.clientEmail | string | Required. Service account client email. | | credentials.privateKey | string | Required. Service account private key. | | defaultTimeframe | '7d' \| '30d' \| '90d' | Default timeframe for fetching data. | | placement | PlacementSlot \| PlacementSlot[] | Where to render the widget. See Placements below. | | widget.title | string | Title of the widget component. | | widget.timeframe | '7d' \| '30d' \| '90d' | Widget component default time period. | | widget.detailPath | string | Detailed analytics view path (matches your root view path if set). | | path | string | Custom path for the root analytics view (default: /analytics). | | access | (user: any) => boolean \| Promise<boolean> | Function to control access to analytics endpoints and view dashboard. |

Placements

Provide a plain string or an object to bind widgets to specific collections or globals:

// Into the main dashboard before elements:
placement: 'dashboard'

// As a separate view on the side nav root:
placement: 'root'

// Bound to specific collections:
placement: {
  collection: 'pages',
  position: 'afterList' // 'beforeList' | 'afterList' | 'beforeEdit' | 'afterEdit'
}

// Bound to globals:
placement: {
  global: 'site-settings',
  position: 'beforeEdit' // 'beforeEdit' | 'afterEdit'
}