Content management systems
Add Loogika to Payload
Payload is a headless CMS (content management system) that you install inside a Next.js app. Two route groups split that app: (payload) holds the admin panel, and (frontend) holds your site. The Loogika tag belongs in the root layout of the frontend. Keep it away from the Payload config and the admin panel.
Last updated .
What do you need before you start?
Copy your site ID from Site Settings in Loogika, under the Tracking Script tab. The site ID is the 12-character value after siteId= in the script address.
How do you add Loogika to a Payload app?
Render the script with next/script in the frontend root layout. The website and blank templates from npx create-payload-app both keep that layout in src/app/(frontend)/layout.tsx. Payload has no template or header setting to paste code into.
import Script from "next/script";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
{children}
<Script
src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID"
strategy="afterInteractive"
/>
</body>
</html>
);
}
Every public route now loads the script. The admin panel under src/app/(payload)/ does not. The Next.js guide explains the same setup in more detail.
Loogika records route changes inside the app as pageviews while SPA Navigation is on in Site Settings, which is the default. A click on a Next.js <Link> between Payload pages and posts counts without extra code.
What if your frontend is a separate app?
Follow the guide for that framework. Some sites fetch content from the REST or GraphQL API of Payload and render it elsewhere. We have guides for Nuxt, Astro, SvelteKit and Remix.
How do you check that Loogika is installed?
Load your site in a fresh browser tab and visit a few pages. The pageviews appear in the Loogika dashboard within a few seconds. If nothing arrives, open the page source and look for script.js?siteId=.
Does Live Preview count as visits?
Yes. Live Preview in the admin panel shows your frontend inside an iframe and takes the address from admin.livePreview.url. Loogika counts an editor in that iframe the way it counts every visitor.
To keep editors out of your numbers, give livePreview.url the address of a separate preview deployment. Then either register that deployment in Loogika as a site of its own, or build previews without the tag.
How do you skip draft preview routes?
Add a skip pattern to the script. Loogika also tracks pages that you open through the /next/preview route of the website template or through Next.js draft mode. The data-skip-patterns attribute takes a JSON array of paths that Loogika must not track:
<Script
src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID"
data-skip-patterns='["/next/**"]'
strategy="afterInteractive"
/>
Does Loogika track the Payload admin panel?
No. The (payload) route group renders /admin with its own layout, and that layout has no tag. Keep the tag in the (frontend) layout only.