Integration
Add Barelytics to your website and confirm data is flowing.
1. Add your website in Barelytics
In the dashboard:
- Click Add Website.
- Enter your domain (for example,
example.com, withouthttps://). - Continue to the setup page to copy your tracking snippet.
2. Install the tracking script
Add this script in your site <head>:
<script defer data-domain="yourdomain.com" src="https://cdn.barelytics.com/script.js"></script>data-domain should match the website you added in Barelytics.
3. Framework examples
Next.js
For App Router, add the script in app/layout.tsx:
import Script from 'next/script'
export default function RootLayout({ children }) {
return (
<html lang="en">
<head>
<Script
defer
data-domain="yourdomain.com"
src="https://cdn.barelytics.com/script.js"
strategy="afterInteractive"
/>
</head>
<body>{children}</body>
</html>
)
}Static HTML
Paste the script tag directly in your index.html <head>.
SPAs (React, Vue, Angular)
No extra pageview wiring is needed. Barelytics automatically tracks URL changes via History API (pushState, replaceState, popstate).
4. Verify installation
- Open your website in an incognito/private window.
- Browse a few pages.
- Go to your Barelytics dashboard in Live mode.
- Confirm you see live visitors and pageviews.
Data usually appears within a few minutes.
Script options
| Attribute | Description |
|---|---|
src | Required. Script URL: https://cdn.barelytics.com/script.js |
data-domain | Recommended. Domain to attribute events to (for example example.com) |
data-api | Optional. Custom ingestion endpoint (for example self-hosted /track.gif) |
defer | Recommended. Loads script without blocking rendering |
Optional: Track custom events
After the script loads, you can send custom events:
<script>
window.barelytics.track('signup', { plan: 'pro' })
</script>If you need to queue events before the script loads:
<script>
window.barelytics = window.barelytics || [];
window.barelytics.push(['track', 'signup', { plan: 'pro' }]);
</script>For funnel setup using custom events, continue to Custom Events and Funnels.