OnyxMetric
Integration Guides

Payload

Add OnyxMetric analytics to your Payload site

Payload is a headless CMS that installs into a Next.js app. The admin panel lives in the (payload) route group and your public site in (frontend). Add the tag to the frontend layout only.

Copy your tracking snippet

In OnyxMetric, open your site's Site Settings and copy the tracking script. It looks like this:

<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>

YOUR_SITE_ID is the numeric ID of your site.

Add the snippet to Payload

Payload has no template or head setting to paste into. Add the snippet to the root layout of the Next.js frontend that renders your site.

In projects made with npx create-payload-app, that file is src/app/(frontend)/layout.tsx. Render next/script there:

src/app/(frontend)/layout.tsx
import Script from "next/script";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script
          src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID"
          strategy="afterInteractive"
        />
      </body>
    </html>
  );
}

Client-side navigation between pages and posts is counted automatically.

If your frontend is a separate app (Nuxt, Astro, SvelteKit) that reads from Payload's REST or GraphQL API, follow that framework's guide instead: Nuxt, Astro, SvelteKit.

Check that it works

Load your live site and click through a few pages. Pageviews show up in the OnyxMetric dashboard within seconds.

If nothing arrives:

  • View the page source and search for script.js?siteId= to confirm the tag is present.
  • In the browser's Network tab, check that script.js returns 200 and that requests go to /api/track.
  • Turn off ad blockers, or proxy the script through your own domain.
  • Read script troubleshooting for other causes.

Troubleshooting

  • Live Preview counts as visits: the admin's Live Preview loads your frontend in an iframe at the URL in admin.livePreview.url, so editors' preview sessions are tracked. Use a separate preview deployment registered as its own site.
  • Draft routes: pages shown through Next.js draft mode are tracked too. Add those paths to the skip patterns.
  • Admin is not tracked: /admin renders from the (payload) route group, which has its own layout without the tag. That is expected.

Next steps

On this page