Skip to Content
Pageflock

Custom events

Track signups, purchases and any other action, with properties you can break down in the dashboard.

Page views are counted on their own. For everything else, send a custom event.

From code

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

track("Signup", { plan: "pro", seats: 3 });
  • The name can be anything; keep it short and stable, like Signup or Checkout started.
  • Property values are strings, numbers or booleans.
  • With @pageflock/analytics, track() can be called before <Analytics /> mounts. Events wait in a queue and are sent once tracking starts. It also does nothing during server rendering.

Without code

Any element with data-track sends an event when clicked. Other data-track-* attributes become its properties:

<button data-track="Signup" data-track-plan="pro">Sign up</button>

Automatic events

Set autoEvents (or load s.auto.js) and Pageflock also records:

  • Outbound Link: Click, with the destination URL
  • File Download, for links to PDFs, archives, installers, documents and media
  • 404, with the path, on pages whose title says 404 or "not found", or that have a data-pageflock-404 element

In the dashboard

Events show in the Events panel of the site dashboard. Select an event to see its properties, then break a property down by its values. The conversion_rate metric shows the share of visitors who sent it.

From the API or MCP, query them with the events and conversion_rate metrics and the event and prop:<key> dimensions. See the REST API.

Changing or dropping events

beforeSend sees every event, page views included, before it is sent. Return it changed, or null to drop it:

<Analytics
  site="SITE_ID"
  beforeSend={(event) => {
    const url = new URL(event.url);
    if (url.pathname.startsWith("/admin")) {
      return null;
    }
    url.searchParams.delete("token");
    return { ...event, url: url.href };
  }}
/>

beforeSend is only in the npm packages; the script tag leaves it out to save bytes.

On this page