Session replay for Next.js

Load the recorder with next/script in your root layout. It needs no npm package and works with the App Router and the Pages Router.

Replayowl player paused on an uncaught error, with the activity list showing the click and the console errors next to the recorded page
The Replayowl dashboard. Try the live demo.

You need a running Replayowl server first. See Deploy to Cloudflare Workers. Below, replace replay.example.com with your server’s domain.

App Router

In app/layout.tsx:

import Script from "next/script";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script
          src="https://replay.example.com/recorder.js"
          data-endpoint="https://replay.example.com/api/ingest"
          strategy="afterInteractive"
        />
      </body>
    </html>
  );
}

Pages Router

Put the same <Script> in pages/_app.tsx, next to <Component {...pageProps} />.

Attaching the signed-in user

Call identify once you know who is signed in. window.ReplayOwl exists only after the script has loaded, so wait for it if needed:

"use client";
import { useEffect } from "react";

declare global {
  interface Window { ReplayOwl?: { identify(id: string): void } }
}

export function ReplayIdentity({ userId }: { userId?: string }) {
  useEffect(() => {
    if (!userId) return;
    const tryIdentify = () => window.ReplayOwl?.identify(userId);
    if (window.ReplayOwl) tryIdentify();
    else window.addEventListener("load", tryIdentify, { once: true });
  }, [userId]);
  return null;
}

Client-side navigation

Route changes made by the Next.js router are recorded and replayed like any other change to the page. The URL is read on full page loads only, so the session list and page searches show the page where the visit started and any pages loaded in full. See limitations.

Privacy

Inputs, emails and card numbers are masked by default. Add data-ro-mask or data-ro-block to components that show sensitive data. See Masking and privacy.

Try Replayowl on your own site

Hosted

Free for 1,000 sessions a month

Then $29 a month for 10,000. Paste one script tag and watch your first session a minute later.

Start free

Self-hosted

Free, no session caps

One Cloudflare Worker with your own R2 bucket and D1 database. Nothing is sent to us.

Self-host on Cloudflare

Or watch it record you first in the live demo, no sign-up.