Skip to Content
Pageflock

@pageflock/analytics

One component for Next.js, React and Vue, and inject() for SvelteKit, Astro and any bundled site.

@pageflock/analytics bundles the tracker into your app, so you configure it in code and get typed track() calls. It has no runtime dependencies and adds about 1.5 KB gzipped.

npm install @pageflock/analytics

You need your site's ID from the dashboard. Events go to Pageflock's hosted ingest, https://e.pageflock.com/api/e, unless you set endpoint.

Add it to your app

app/layout.tsx
import { Analytics } from "@pageflock/analytics/next";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        {children}
        <Analytics site="SITE_ID" />
      </body>
    </html>
  );
}
  • Next.js: with the Pages Router, put it in pages/_app.tsx instead.
  • React: works with React Router, TanStack Router and any router that uses the History API.
  • Nuxt: use app.vue.
  • SvelteKit and Astro: inject() does nothing on the server, so it can run straight from the layout.

Client-side navigations are counted as page views on their own. For hash-routed apps, set hashRouting.

Custom events

import { track } from "@pageflock/analytics";

track("Signup", { plan: "pro", seats: 3 });

See Custom events for properties, no-code events and goals.

Next

On this page