Spoar

notFound

A not_found event with the referrer on pages marked as not found.

import { notFound } from "@spoar/sdk/plugins";
import { createAnalytics } from "@spoar/sdk";
import { notFound } from "@spoar/sdk/plugins";

export const analytics = createAnalytics({
  project: "example.com",
  key: "pk_...",
  endpoint: "/_ra",
  plugins: [notFound()],
});

Mark the 404 page with a meta tag:

<meta name="ra-not-found" />

Options

notFound() takes no options.

Sends

EventProps
not_found{ referrer: string | null }, document.referrer, or null when there is none

The event also carries the page path, so each broken URL shows up with where people came from.

Behaviour

  • The plugin looks for meta[name=ra-not-found] when it starts and again after every pageview. The tag's content is not read.
  • It reports each URL (path and query string) once in a row, so the first pageview after start does not send a second not_found for the same page. Navigating to another URL and back reports it again.
  • document.referrer is the page the browser loaded from. After a client-side navigation it still holds the referrer of the first page load.

In reports

breakdown/page with filter[event]=not_found lists the broken paths, and breakdown/prop:referrer with the same filter lists the pages that link to them.

On this page