Barelytics Documentation

Integration

Add Barelytics to your website and confirm data is flowing.

1. Add your website in Barelytics

In the dashboard:

  1. Click Add Website.
  2. Enter your domain (for example, example.com, without https://).
  3. 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

  1. Open your website in an incognito/private window.
  2. Browse a few pages.
  3. Go to your Barelytics dashboard in Live mode.
  4. Confirm you see live visitors and pageviews.

Data usually appears within a few minutes.

Script options

AttributeDescription
srcRequired. Script URL: https://cdn.barelytics.com/script.js
data-domainRecommended. Domain to attribute events to (for example example.com)
data-apiOptional. Custom ingestion endpoint (for example self-hosted /track.gif)
deferRecommended. 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.

On this page