Documentation menuDocumentation tools: Nextra

Documentation tools

Add Loogika to Nextra

You add Loogika to Nextra in the root layout, with the Script component from next/script. Nextra is a docs framework for Next.js, so the tag sits in the same place as in any other Next.js app. On Nextra 4, which runs on the App Router, that place is app/layout.jsx. On Nextra 3, which runs on the Pages Router, it is pages/_app.jsx.

Last updated .

What do you need before you start?

Copy your script tag from Site Settings in Loogika, under the Tracking Script tab. It looks like this, with your own 12-character site ID in place of YOUR_SITE_ID:

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

In Nextra you use the Script component with strategy="afterInteractive" in place of the plain tag. You only need the address from the src attribute, and you can leave out defer.

How do you add Loogika to Nextra 4?

Add Script next to the Layout component in app/layout.jsx or app/layout.tsx. The example shows a full root layout with the docs theme.

import { Footer, Layout, Navbar } from "nextra-theme-docs";
import { Head } from "nextra/components";
import { getPageMap } from "nextra/page-map";
import Script from "next/script";
import "nextra-theme-docs/style.css";

export default async function RootLayout({ children }) {
  return (
    <html lang="en" dir="ltr" suppressHydrationWarning>
      <Head />
      <body>
        <Layout
          navbar={<Navbar logo={<b>My Docs</b>} />}
          pageMap={await getPageMap()}
          footer={<Footer>MIT {new Date().getFullYear()} © My Docs.</Footer>}
        >
          {children}
        </Layout>
        <Script
          src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID"
          strategy="afterInteractive"
        />
      </body>
    </html>
  );
}

How do you add Loogika to Nextra 3?

Render Script beside the page component in pages/_app.jsx. A project without that file needs a new one.

import Script from "next/script";

export default function App({ Component, pageProps }) {
  return (
    <>
      <Component {...pageProps} />
      <Script
        src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID"
        strategy="afterInteractive"
      />
    </>
  );
}

The head option of theme.config.jsx is the wrong place for the tag. Nextra passes that option to next/head, where Next.js advises you not to load scripts.

Does Loogika count page changes in Nextra?

Yes. Nextra moves between pages in the browser, without a full page load. Loogika records each of those route changes as a pageview when SPA Navigation is on in Site Settings. The setting is on for a new site.

How do you check that Loogika is installed?

Load your deployed site in a fresh browser tab and visit a few pages. The pageviews show up in the Loogika dashboard within a few seconds. If nothing arrives, open the page source and look for script.js?siteId=.

What are the common problems in Nextra?

ProblemCause and fix
Loogika tracks the docs pages and nothing elseOn Nextra 4, put the tag in app/layout.jsx at the root. A tag in a nested app/docs/layout.jsx misses landing pages outside docs/
Tracking stops after an upgrade from Nextra 3Nextra 4 has no Pages Router and no theme.config. During the migration, take Script out of pages/_app.jsx and add it to app/layout.jsx

The Next.js guide has more detail on the Script component, because a Nextra site is a Next.js app. The proxy guide explains how your own domain can serve the script.