SDK reference

Script tag

<script defer src="https://i.lapwy.com/s.js"
        data-site="lw_…"
        data-pages="/blog/:slug, /users/:id"></script>

Attributes

AttributeValueWhat it does
data-sitestringThe site's key, from its Install tab. Required.
data-pagespatterns, comma-separatedPages to count as one: "/blog/:slug, /docs/*". See Group pages.
data-cookie"always" | "consent"Keeps one id per visitor in a first-party cookie. With "consent", only after lapwy.consent(true).
data-apihosts, comma-separated | "off"Other hosts whose API calls count: "api.example.com". "off" counts none.
data-releasestringYour build or version.
data-endpointURLWhere events go. Defaults to the server the script came from.

In the page

CallTakesWhat it does
lapwy.track(name, props?)string, objectSomething a visitor did: lapwy.track("signup", { plan: "pro" }).
lapwy.page(props?)objectA page view, when you want to send one yourself.
lapwy.consent(granted)booleanWhat the visitor said about cookies.
lapwy.notFound(status?)numberMarks the page as a dead end.
data-lapwy-eventHTML attributeTracks a click with no code: <button data-lapwy-event="signup" data-lapwy-plan="pro">. Every other data-lapwy-… attribute becomes a property.

JavaScript

npm install @lapwy/js

import { init, track } from "@lapwy/js";

init({ site: "lw_…", pages: ["/blog/:slug", "/users/:id"] });  // once, in the browser
track("signup", { plan: "pro" });                              // anywhere, any time

init is safe to call twice and safe on a server, where it does nothing. What is tracked before init is kept and sent after it.

init(options)

OptionTypeWhat it does
sitestringThe site's key, from its Install tab. The only one that is required.
pagesstring[]Pages to count as one: ["/blog/:slug"]. See Group pages.
path(path) => stringRewrites the path yourself, for what patterns cannot say. Used instead of pages.
cookie"always" | "consent"Keeps one id per visitor in a first-party cookie. With "consent", only after consent(true). Left out: no cookie, nothing kept between visits. The site’s own setting in lapwy must ask for it too.
apistring[] | falseAPI calls to your own domain are counted on their own. List other API hosts here: ["api.example.com"]. false counts none.
releasestringYour build or version, to see what a release changed.
endpointstringWhere events go. Defaults to https://i.lapwy.com/e.

Calls

CallTakesWhat it does
track(name, props?)string, objectSomething a visitor did: track("signup", { plan: "pro" }).
page(props?)objectA page view. The first page and every route change are sent without it; call it only to send one yourself.
consent(granted)booleanWhat the visitor said about cookies. Matters only with cookie: "consent".
notFound(status?)numberMarks the page as a dead end. Call it from the “not found” screen of a single-page app; a page the server answers with 404 or 500 is seen without it.

React

npm install @lapwy/react

import { Lapwy, useLapwy } from "@lapwy/react";

<Lapwy site="lw_…" pages={["/blog/:slug", "/users/:id"]} />   // once, near the root

const { track } = useLapwy();                                  // in any component
<button onClick={() => track("signup", { plan: "pro" })}>

Works with React Router and any router that changes the address: route changes are page views.

<Lapwy> props

PropTypeWhat it does
sitestringThe site's key, from its Install tab. The only one that is required.
pagesstring[]Pages to count as one: ["/blog/:slug"]. See Group pages.
path(path) => stringRewrites the path yourself, for what patterns cannot say. Used instead of pages.
cookie"always" | "consent"Keeps one id per visitor in a first-party cookie. With "consent", only after consent(true). Left out: no cookie, nothing kept between visits. The site’s own setting in lapwy must ask for it too.
apistring[] | falseAPI calls to your own domain are counted on their own. List other API hosts here: ["api.example.com"]. false counts none.
releasestringYour build or version, to see what a release changed.
endpointstringWhere events go. Defaults to https://i.lapwy.com/e.

useLapwy()

CallTakesWhat it does
track(name, props?)string, objectSomething a visitor did: track("signup", { plan: "pro" }).
page(props?)objectA page view. The first page and every route change are sent without it; call it only to send one yourself.
consent(granted)booleanWhat the visitor said about cookies. Matters only with cookie: "consent".
notFound(status?)numberMarks the page as a dead end. Call it from the “not found” screen of a single-page app; a page the server answers with 404 or 500 is seen without it.

Next.js

npm install @lapwy/next

// app/layout.tsx
import { Lapwy } from "@lapwy/next";

<body>
  {children}
  <Lapwy site="lw_…" pages={["/blog/:slug", "/users/:id"]} />
</body>

// in a client component
import { track } from "@lapwy/next";
track("signup", { plan: "pro" });

App Router and Pages Router. path is a function, so a layout that is a server component cannot pass it: use pages there, or put <Lapwy> in a client component.

<Lapwy> props

PropTypeWhat it does
sitestringThe site's key, from its Install tab. The only one that is required.
pagesstring[]Pages to count as one: ["/blog/:slug"]. See Group pages.
path(path) => stringRewrites the path yourself, for what patterns cannot say. Used instead of pages.
cookie"always" | "consent"Keeps one id per visitor in a first-party cookie. With "consent", only after consent(true). Left out: no cookie, nothing kept between visits. The site’s own setting in lapwy must ask for it too.
apistring[] | falseAPI calls to your own domain are counted on their own. List other API hosts here: ["api.example.com"]. false counts none.
releasestringYour build or version, to see what a release changed.
endpointstringWhere events go. Defaults to https://i.lapwy.com/e.

Calls

CallTakesWhat it does
track(name, props?)string, objectSomething a visitor did: track("signup", { plan: "pro" }).
page(props?)objectA page view. The first page and every route change are sent without it; call it only to send one yourself.
consent(granted)booleanWhat the visitor said about cookies. Matters only with cookie: "consent".
notFound(status?)numberMarks the page as a dead end. Call it from the “not found” screen of a single-page app; a page the server answers with 404 or 500 is seen without it.

Vue

npm install @lapwy/vue

// main.ts
import { lapwy } from "@lapwy/vue";

createApp(App).use(lapwy, { site: "lw_…", pages: ["/blog/:slug", "/users/:id"] }).mount("#app");

// in a component
import { useLapwy } from "@lapwy/vue";
const { track } = useLapwy();
track("signup", { plan: "pro" });

In templates the same calls are on $lapwy. Under Nuxt, register the plugin in a client-only plugin.

Plugin options

OptionTypeWhat it does
sitestringThe site's key, from its Install tab. The only one that is required.
pagesstring[]Pages to count as one: ["/blog/:slug"]. See Group pages.
path(path) => stringRewrites the path yourself, for what patterns cannot say. Used instead of pages.
cookie"always" | "consent"Keeps one id per visitor in a first-party cookie. With "consent", only after consent(true). Left out: no cookie, nothing kept between visits. The site’s own setting in lapwy must ask for it too.
apistring[] | falseAPI calls to your own domain are counted on their own. List other API hosts here: ["api.example.com"]. false counts none.
releasestringYour build or version, to see what a release changed.
endpointstringWhere events go. Defaults to https://i.lapwy.com/e.

useLapwy()

CallTakesWhat it does
track(name, props?)string, objectSomething a visitor did: track("signup", { plan: "pro" }).
page(props?)objectA page view. The first page and every route change are sent without it; call it only to send one yourself.
consent(granted)booleanWhat the visitor said about cookies. Matters only with cookie: "consent".
notFound(status?)numberMarks the page as a dead end. Call it from the “not found” screen of a single-page app; a page the server answers with 404 or 500 is seen without it.

React Native

npm install @lapwy/react-native @react-native-async-storage/async-storage

import AsyncStorage from "@react-native-async-storage/async-storage";
import { init, screen, track } from "@lapwy/react-native";

init({ site: "lw_…", app: "fernshop", storage: AsyncStorage });  // once, at start-up
screen("Home");                                                  // on every screen
track("add_to_cart", { product: "monstera" });

Also for Expo. Screens have names, not addresses, so there is nothing to group: name a screen once and every view of it counts together.

init(options)

OptionTypeWhat it does
sitestringThe app's key, from its Install tab. Required.
appstringA short name for the app, such as its bundle name. It stands where a website's domain would.
storageAsyncStorageKeeps the install id and the waiting events between launches. Without it every launch is a new user and nothing survives a restart.
versionstringYour app's version.
errorsbooleanReport uncaught JavaScript errors. On unless set to false.
endpointstringWhere events go. Defaults to https://i.lapwy.com/e.

Calls

CallTakesWhat it does
screen(name, props?)string, objectThe user is looking at a screen.
track(name, props?)string, objectSomething a user did.
navigationTracker(ref)navigation refReact Navigation: reports every screen. <NavigationContainer ref={ref} {...navigationTracker(ref)}>.
useScreen(name)stringReports a screen from a component. Expo Router, once in the root layout: useScreen(usePathname()).
optOut(stop)booleanStops or resumes tracking for this user. Stopping throws away what is waiting and forgets the install id.
flush()Sends what is waiting now. Happens on its own after anything is tracked and when the app goes to the background.

Group pages

Every address is its own page unless you say otherwise. A pattern counts the pages that differ only by an id or a name as one page. The address is rewritten in the browser, before anything is sent: the id never reaches lapwy, and the pages cannot be told apart afterwards. Group order numbers and user ids; leave apart what you want to compare, such as articles.

pages: ["/blog/:slug", "/users/:id/orders/:order", "/docs/*"]
AddressPatternCounted as
/blog/my-first-post/blog/:slug/blog/:slug
/users/8141/orders/77/users/:id/orders/:order/users/:id/orders/:order
/docs/guides/install/docs/*/docs/*
/blog/2026/11/long-read/blog/:slug/blog/2026/11/long-read
/pricingnone fits/pricing

:name stands for exactly one part of the path, * at the end for everything after it. The first pattern that fits wins. The query string is kept, so campaign links still count. For anything else, path takes a function:

path: (path) => path.replace(/^\/(en|nl|de)\//, "/")   // one page for every language

Events

An event has a name and up to 30 properties: text, numbers, or true and false. Money goes in as revenue with a three-letter currency; a goal marked as revenue reads it from there.

track("signup", { plan: "pro" });
track("purchase", { revenue: 49, currency: "EUR", product: "monstera" });