Install FastAnalytics on Next.js, React, Vue and other single-page apps
Load the script once. It listens to the browser history, so every client-side navigation counts as a page view without extra code.
Next.js (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://e.fastanalytics.site/e.js" data-id="FA-XXXXXXXXXX" strategy="afterInteractive" />
</body>
</html>
);
}Next.js (Pages Router)
In pages/_app.tsx, render the same <Script /> component once next to <Component {...pageProps} />.
React, Vue, Svelte with Vite
Paste the script in index.html, inside <head>:
<script>window.hm=window.hm||function(){(window.hm.q=window.hm.q||[]).push(arguments)};</script>
<script defer src="https://e.fastanalytics.site/e.js" data-id="FA-XXXXXXXXXX"></script>Nuxt, Astro, SvelteKit
- Nuxt: add it to
app.head.scriptinnuxt.config, withdefer: trueand'data-id'. - Astro: add it to your base layout
<head>. - SvelteKit: add it to
src/app.html, inside<head>.
Load it only once. Do not add it inside a component that re-renders, or page views would be counted twice.
Query parameters
By default only the path is sent (/products/shoes), never the query string, and parts of the path that look like IDs are replaced with :id. If a query parameter really defines the page, list it in data-keep:
<script>window.hm=window.hm||function(){(window.hm.q=window.hm.q||[]).push(arguments)};</script>
<script defer src="https://e.fastanalytics.site/e.js" data-id="FA-XXXXXXXXXX" data-keep="category,page"></script>FAQ
Do I need to call anything on route change?
No. The script detects pushState, replaceState and back/forward navigation by itself.
Keep reading
Track custom events: sign-ups, purchases, clicks and outbound linksCount the actions that matter with FastAnalytics: hm() in JavaScript, the data-hm attribute without code, and automatic outbound, WhatsApp, email and phone clicks.Read →4 minCheck your installation and fix missing visitsHow to check that FastAnalytics is working, why visits might not appear (domains, ad blockers, caching, Content Security Policy) and how to exclude your own visits.Read →4 minInstall the FastAnalytics tracking scriptHow to add FastAnalytics to any website in two minutes: get your FA code, paste one line before the closing head tag and check that visits arrive in real time.Read →3 min