Adds an Analytics Settings global to Payload 4 that injects analytics into a Next.js frontend without code changes. Editors manage a Google tag, custom scripts and pixels, and UTM attribution cookies from the admin. You render three server components in the root layout. Requires Payload 4 beta and Next.js.
Analytics for Payload CMS 4 and Next.js: Google tag, custom scripts and pixels, UTM attribution cookies, with consent categories.
Installation
npm i @serge-pro-dev/payload-plugin-analytics0
Stars
0
Forks
0
Open Issues
Yesterday
Last Updated
627
Weekly Downloads
v0.1.0-beta.2
npm Version
91.1 KB
Unpacked Size
2
Dependencies
00 since Nov 29
| 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 |
Shared by 6 plugins in serge-pro-dev/payload-plugins.
Trends appear after 7 days of data. Collecting since Dec 4 — 3 daily snapshots so far.
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/1479182369-analytics)<a href="https://payloaddirectory.dev/plugins/1479182369-analytics"><img src="https://payloaddirectory.dev/badge/1479182369-analytics.svg" alt="Payload Directory"></a>README
A Payload 4 global (Analytics Settings) that adds analytics to a Next.js site without code changes: Google tags, your own scripts and pixels, and UTM attribution cookies. Every group of scripts has a consent category that the consent plugin respects.

pnpm add @serge-pro-dev/payload-plugin-analytics
// payload.config.ts
import { analyticsPlugin } from '@serge-pro-dev/payload-plugin-analytics'
plugins: [analyticsPlugin()]
// src/app/(frontend)/layout.tsx (the folder may be named (app) in some templates)
import config from '@payload-config'
import { Analytics, AnalyticsBody, AnalyticsHead } from '@serge-pro-dev/payload-plugin-analytics/rsc'
import { draftMode } from 'next/headers'
export default async function RootLayout({ children }: { children: React.ReactNode }) {
const { isEnabled } = await draftMode()
return (
<html>
<head>{!isEnabled && <AnalyticsHead config={config} />}</head>
<body>
<Providers>
{!isEnabled && <Analytics config={config} />}
{children}
</Providers>
{!isEnabled && <AnalyticsBody config={config} />}
</body>
</html>
)
}
isEnabled is Next.js draft mode (Payload live preview); the scripts are skipped there. Render
{children} only once. Then run pnpm payload generate:types.
| Component | Renders |
|---|---|
AnalyticsHead | custom <script> tags placed in the head |
Analytics | Google tag and the UTM writer |
AnalyticsBody | custom <script> tags placed before </body> and all <noscript> blocks |
GTM-… (Tag Manager), G-… (GA4), GT-… (Google tag) or
AW-… (Google Ads). Use one ID; if GA4 already lives in Tag Manager, enter only the container.<script> tags (inline and external, data-*
attributes kept) go to <head> or before </body>; <noscript> fallbacks and tracking pixels
always go to the end of <body>. Other markup is ignored.utm_first_touch / utm_last_touch cookies that the Telegram and
Bitrix24 plugins read. Lifetime 1–365 days.Scripts are rendered on the server and cached; saving the global revalidates the cache
(revalidateTag('global_analytics')). Nothing is rendered in Next.js draft mode.
read: () => true) because the site reads it.parse5 on the server; max size 50 000 characters.Labels and descriptions are available in English and Russian. Enable both in the project:
i18n: { supportedLanguages: { en, ru } }.
New global analytics. Development: schema push. Production: pnpm payload migrate:create and
migrate.
MIT
payload plugin gtm
Google Tag Manager and GA4 for Payload with automatic dataLayer event discovery and an editable event registry
6031/wk0v3
analytics
Event registry and consent-gated routing of analytics events to GTM, GA4 and HubSpot from the Payload admin
4810/wk0v3
tracking
Tracking global and React providers for PostHog, Google Tag Manager and Vercel Analytics
6132/wk37v3
payload posthog
Native PostHog integration for Payload Admin covering analytics, session replay, error tracking, logs and feature flags
791.7k/wk0v3
payload plugin ab
A/B testing with page variants managed in the Payload admin and routed by Next.js middleware at the edge
741.0k/wk37v3
payload plugin stats
Privacy-preserving user count statistics for the Payload admin, with small groups hidden
7380/wk0v3