Install the script
Framework-specific instructions for adding the Stancelens tracker.
The tracker is a 1 KB (gzipped) script served from https://stancelens.com/e.js. It loads with defer, doesn't block rendering and tracks single-page-app navigation automatically. Extra features are opt-in modules.
Script attributes
| Attribute | Description |
|---|---|
data-site | Required. Your site ID. |
data-api | Custom ingest endpoint, used when proxying. |
data-exclude | Comma-separated paths to ignore, * wildcards: /admin/*,/preview. |
data-hash | Track hash changes (#/route) as page views. |
data-manual | No automatic page views; call stancelens.pageview() yourself. |
data-outbound, data-downloads, data-scroll, data-vitals, data-errors, data-tagged, data-replay | Opt-in modules. |
The full list, with defaults, is on Tracker modules.
HTML
Paste into the <head> of every page:
<script defer data-site="SITE_ID" src="https://stancelens.com/e.js"></script>Next.js
Use next/script in your root layout. App Router and Pages Router navigations are tracked automatically. The Next.js page covers the npm package.
import Script from "next/script";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<Script defer data-site="SITE_ID" src="https://stancelens.com/e.js" strategy="afterInteractive" />
</head>
<body>{children}</body>
</html>
);
}React (Vite, CRA)
Add the tag to index.html. History navigation is tracked automatically.
<!doctype html>
<html lang="en">
<head>
<script defer data-site="SITE_ID" src="https://stancelens.com/e.js"></script>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>For TypeScript, declare the global once so stancelens(...) is typed:
declare global {
interface Window {
stancelens: ((cmd: "event" | "identify" | "pageview", ...args: unknown[]) => void) & {
track(name: string, props?: Record<string, unknown>): void;
identify(id: string | null, traits?: Record<string, unknown>): void;
reset(): void;
pageview(): void;
flag(key: string): Promise<boolean | string>;
};
}
const stancelens: Window["stancelens"];
}
export {};Vue
Add the tag to index.html (Vite) or public/index.html (Vue CLI):
<script defer data-site="SITE_ID" src="https://stancelens.com/e.js"></script>Nuxt
export default defineNuxtConfig({
app: {
head: {
script: [{ src: "https://stancelens.com/e.js", defer: true, "data-site": "SITE_ID" }],
},
},
});SvelteKit
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<script defer data-site="SITE_ID" src="https://stancelens.com/e.js"></script>
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>WordPress
Add this to your (child) theme's functions.php, or paste the HTML snippet with any “header scripts” plugin.
add_action('wp_head', function () {
echo '<script defer data-site="SITE_ID" src="https://stancelens.com/e.js"></script>';
});Shopify
- In Shopify admin, go to Online Store → Themes → Edit code.
- Open
layout/theme.liquidand paste the snippet just before</head>. - For checkout and order-status pages, add it under Settings → Customer events → Add custom pixel, and send purchases as revenue events.
<script defer data-site="SITE_ID" src="https://stancelens.com/e.js"></script>Webflow
- In Webflow, open your site's Site settings and go to the Custom code tab.
- Paste the snippet into Head code and save.
- Publish your site. Custom code only runs on the published domain.
Google Tag Manager
Create a Custom HTML tag that fires on All Pages and add the script element from JavaScript, so its data-* attributes are set no matter how GTM injects the tag:
<script>
(function () {
var s = document.createElement("script");
s.defer = true;
s.dataset.site = "SITE_ID";
s.src = "https://stancelens.com/e.js";
document.head.appendChild(s);
})();
</script>