Setup & Installation

Moneat Analytics offers two integration methods: a lightweight script tag for any website, and an NPM package for JavaScript frameworks.

Script tag

Add the following to your website's <head>:

HTML
<script
  defer
  data-domain="yoursite.com"
  data-key="your-service-public-key"
  src="https://your-moneat-instance.com/js/m.js"
></script>

That's it. The script automatically tracks pageviews, including client-side navigations in single-page applications.

Script attributes

AttributeRequiredDescription
data-domainYesYour website's domain (e.g., example.com). Must match the domain you're tracking.
data-keyYesYour Moneat service public key. Found in Service settings.
data-apiNoOverride the API host if the analytics API runs on a different domain than the script origin.
srcYesURL to the tracking script served by your Moneat instance.

Script behavior

  • Deferred loading - The defer attribute ensures the script doesn't block page rendering
  • Automatic pageview tracking - Fires on initial load and on every History API navigation (pushState, replaceState, popstate)
  • Respects Do Not Track - If the browser has DNT enabled, no events are sent
  • No cookies - Zero cookies are set, ever
  • Error-resilient - If the script fails to load or the API is unreachable, your site is unaffected

NPM package

For SPAs and JavaScript frameworks (React, Vue, Next.js, Nuxt, SvelteKit, etc.):

Shell
npm install @moneat/analytics

Initialization

Initialize the tracker once, typically in your app's entry point:

TypeScript
import { init } from '@moneat/analytics'

init({
  domain: 'yoursite.com',
  apiHost: 'https://your-moneat-instance.com',
  key: 'your-service-public-key',
})

Configuration options

OptionTypeRequiredDescription
domainstringYesYour website's domain
apiHoststringYesYour Moneat instance URL
keystringYesService public key
trackLocalhostbooleanNoTrack events on localhost (default: false)
hashModebooleanNoUse hash-based routing instead of History API (default: false)

Framework examples

React (Create React App / Vite)

TSX
// src/main.tsx
import { init } from '@moneat/analytics'

init({
  domain: 'yoursite.com',
  apiHost: 'https://your-moneat-instance.com',
  key: 'your-service-public-key',
})

Next.js (App Router)

TSX
// app/layout.tsx
import Script from 'next/script'

export default function RootLayout({ children }) {
  return (
    <html>
      <head>
        <Script
          defer
          data-domain="yoursite.com"
          data-key="your-service-public-key"
          src="https://your-moneat-instance.com/js/m.js"
          strategy="afterInteractive"
        />
      </head>
      <body>{children}</body>
    </html>
  )
}

Vue / Nuxt

TypeScript
// plugins/analytics.ts
import { init } from '@moneat/analytics'

export default defineNuxtPlugin(() => {
  init({
    domain: 'yoursite.com',
    apiHost: 'https://your-moneat-instance.com',
    key: 'your-service-public-key',
  })
})

Finding your service key

  1. Open the Moneat dashboard
  2. Navigate to your service's Settings page
  3. Copy the Public Key

This is the same service public key used by client-side service ingestion.

Verifying installation

After adding the script or initializing the NPM package:

  1. Open your website in a browser
  2. Navigate to the Analytics section in the Moneat dashboard
  3. You should see your visit appear in the Realtime badge within seconds
Debugging

Open your browser's Network tab and look for requests to /api/{domain}/analytics/event?sentry_key=.... A 202 Accepted response confirms events are being received.

Self-hosted considerations

If you self-host Moneat, ensure the following:

  • The tracking script is served from your Moneat instance at /js/m.js
  • The browser analytics ingestion endpoint (/api/{domain}/analytics/event?sentry_key=...) is accessible from client browsers
  • If using a CDN or reverse proxy, ensure the client's real IP is forwarded via X-Forwarded-For or X-Real-IP headers (required for GeoIP and session hashing)

GeoIP database

Location data (country, region, city) requires a MaxMind GeoLite2-City database. Set the path via environment variable:

Shell
GEOIP_DB_PATH=/usr/share/GeoIP/GeoLite2-City.mmdb

If the database is not available, analytics works normally but location breakdowns will be empty.