D
Datarevly

Installation

Every snippet below uses YOUR_SITE_IDas a placeholder. Grab the real one from a site's Settings page.

Quick start

Datarevly tracks with a single script tag. No cookie banner, no config file, no build step. Paste it before the closing </head> and you're done.

html
<script defer data-site-id="YOUR_SITE_ID" src="https://yourdomain.com/monitor.js"></script>

Plain HTML

Add the snippet to every page, right before </head>:

index.html
<!doctype html>
<html>
  <head>
    <title>My site</title>
    <script defer data-site-id="YOUR_SITE_ID" src="https://yourdomain.com/monitor.js"></script>
  </head>
  <body>...</body>
</html>

Next.js

Use next/script in your root layout so it loads once across the App Router:

app/layout.tsx
import Script from "next/script";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script
          defer
          data-site-id="YOUR_SITE_ID"
          src="https://yourdomain.com/monitor.js"
        />
      </body>
    </html>
  );
}

React (Vite / Create React App)

React has no built-in way to manage <head>, so add the script directly to your index.html:

index.html
<head>
  ...
  <script defer data-site-id="YOUR_SITE_ID" src="https://yourdomain.com/monitor.js"></script>
</head>

Vue.js

Same idea: add it to the index.html that Vite serves:

index.html
<head>
  ...
  <script defer data-site-id="YOUR_SITE_ID" src="https://yourdomain.com/monitor.js"></script>
</head>

Nuxt

Add it once, globally, with the built-in useHead composable in app.vue:

app.vue
<script setup>
useHead({
  script: [
    {
      defer: true,
      "data-site-id": "YOUR_SITE_ID",
      src: "https://yourdomain.com/monitor.js",
    },
  ],
});
</script>

SvelteKit

Add it to src/app.html, which wraps every page:

src/app.html
<head>
  ...
  <script defer data-site-id="YOUR_SITE_ID" src="https://yourdomain.com/monitor.js"></script>
</head>

Angular

Add it to src/index.html, which every route shares:

src/index.html
<head>
  ...
  <script defer data-site-id="YOUR_SITE_ID" src="https://yourdomain.com/monitor.js"></script>
</head>

WordPress

Use a plugin like Insert Headers and Footers, or paste the snippet directly into your theme's header.php just before <?php wp_head(); ?> closes:

html
<script defer data-site-id="YOUR_SITE_ID" src="https://yourdomain.com/monitor.js"></script>

Shopify

In your theme editor, open theme.liquid and add the snippet right before </head>:

theme.liquid
<script defer data-site-id="YOUR_SITE_ID" src="https://yourdomain.com/monitor.js"></script>

Webflow

Go to Site settings → Custom code and paste the snippet into Head code, then publish your site:

html
<script defer data-site-id="YOUR_SITE_ID" src="https://yourdomain.com/monitor.js"></script>

Squarespace

Go to Settings → Advanced → Code Injection and paste the snippet into the Header box (this requires a Business or Commerce plan):

html
<script defer data-site-id="YOUR_SITE_ID" src="https://yourdomain.com/monitor.js"></script>

Google Tag Manager

Create a new Custom HTML tag with the snippet below, and set its trigger to All Pages:

html
<script defer data-site-id="YOUR_SITE_ID" src="https://yourdomain.com/monitor.js"></script>

Custom events & goals

Call window.datarevly('track', name, props) from anywhere on the page to record a custom event, then turn it into a goal from a site's Goals & Funnels page.

javascript
document.querySelector("#signup-form").addEventListener("submit", () => {
  window.datarevly("track", "Signup", { plan: "pro" });
});

Revenue attribution

Connect Stripe (with a restricted API key), Polar (with an organization access token) or Paddle Billing (with an API key) from a site's Settings. Datarevly creates its own webhook in your Stripe account, imports the last 12 months, and tracks one-off payments, subscription renewals, cancellations and refunds. Renewals are credited to the visit that first won the customer, so revenue by source reflects lifetime value, not just first payments.

To attribute a Stripe purchase back to a traffic source, fetch the current visitor id and pass it as client_reference_id when you create the Checkout Session:

javascript
window.datarevly("getVisitorId", (visitorId) => {
  fetch("/create-checkout-session", {
    method: "POST",
    body: JSON.stringify({ visitorId }),
  });
});

Then in your own backend, pass that value through to Stripe as client_reference_id (or as metadata.datarevly_visitor_id if you already use client_reference_idfor something else), and configure the webhook URL shown on the site's Settings page.

Purchases are credited to the visitor's last visit from an external source in the 30 days before they paid, so someone who found you on Google and came back days later by typing your URL still counts as Google.

Polar

Pass the visitor id as checkout metadata.datarevly_visitor_id when creating a checkout session; Polar copies it onto the order and subscription. With a checkout link, append ?reference_id=VISITOR_ID instead. If you set external_customer_id to your own user id, it's matched with identify calls. Revenue from Polar is reported before tax, since Polar collects and remits tax as merchant of record.

Paddle

Pass the visitor id (and, for signed-in users, your own user id) as customData when opening checkout; Paddle stores it on the transaction and on the subscription the checkout creates, so renewals are credited too:

javascript
window.datarevly("getVisitorId", (visitorId) => {
  Paddle.Checkout.open({
    items: [{ priceId: "pri_...", quantity: 1 }],
    customData: { datarevly_visitor_id: visitorId, datarevly_user_id: currentUserId },
  });
});

Revenue from Paddle is reported before tax, since Paddle collects and remits tax as merchant of record. Refunds count once Paddle approves them, and chargebacks are subtracted too.

Identify signed-in users

In cookieless mode a visitor's id changes every day, and on a new device it is always new. Calling identify with your own user id once someone signs in links those visits together, so a purchase made days later still traces back to the visit that brought them in:

javascript
// On every page load, once you know who the user is:
window.datarevly("identify", currentUser.id);

For the strongest link, also pass the same id to Stripe as metadata.datarevly_user_id. Use an opaque id from your database, never an email address. Call identify(null) on sign-out.

First-party proxy

Some ad blockers drop requests to third-party analytics domains. Serving the script and sending events through your own domain keeps that traffic counted. The @datarevly/node package includes a ready-made handler.

Next.js: create app/stats/[...path]/route.ts:

typescript
import { createProxy } from "@datarevly/node";

const proxy = createProxy();
export const GET = proxy;
export const POST = proxy;

Then point your snippet at the proxied path. Any file name ending in .js works:

html
<script defer data-site-id="YOUR_SITE_ID" src="/stats/s.js"></script>

The handler is a standard (Request) => Responsefunction, so the same code works in Cloudflare Workers, Hono, Remix and SvelteKit. It forwards the visitor's IP and location, so countries and cookieless visitor counts stay accurate.

Server-side events

Send events from your backend for things the browser never sees, like a renewed subscription or a signup confirmed by email. Create an API key under a site's Settings, then:

typescript
import { Datarevly } from "@datarevly/node";

const datarevly = new Datarevly({ siteId: "YOUR_SITE_ID" }); // reads DATAREVLY_API_KEY

// For a known user, anywhere in your backend:
await datarevly.track({ name: "Subscription Renewed", url: "https://example.com/billing", userId: user.id });

// Inside a request handler, joining the visitor's browser session:
await datarevly.trackRequest(request, { name: "Signup", userId: user.id });

Or call the REST endpoint directly with up to 100 events per request. Each event needs a userId, or both the visitor's ip and userAgent:

bash
curl -X POST https://yourdomain.com/api/v1/events \
  -H "Authorization: Bearer $DATAREVLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"siteId":"YOUR_SITE_ID","events":[{"name":"Signup","url":"https://example.com/signup","userId":"u_123"}]}'

AI traffic

Visits from ChatGPT, Perplexity, Claude, Gemini, Copilot and other assistants are recognised automatically from their referrer or utm_source (ChatGPT tags the links it cites with utm_source=chatgpt.com, which also survives its mobile apps dropping the referrer). Each site has an AI traffic page, and every dashboard view can be filtered with ?ai_assistant=any or a specific assistant.

AI crawlers like GPTBot, ClaudeBot and PerplexityBot don't run JavaScript, so report them from your server with @datarevly/node. In Next.js, middleware.ts:

typescript
import { NextResponse, type NextRequest, type NextFetchEvent } from "next/server";
import { trackAiCrawler } from "@datarevly/node";

export function middleware(req: NextRequest, event: NextFetchEvent) {
  event.waitUntil(trackAiCrawler(req, { siteId: "YOUR_SITE_ID" }));
  return NextResponse.next();
}

It only sends a request when the user agent is a known AI crawler and never throws. Elsewhere, call trackAiCrawler(request, { siteId }) in your request handler, or POST { siteId, path, userAgent } to https://yourdomain.com/api/crawl.

API, CLI & MCP

Create an API key from a site's Settings page, under API access. The key is shown once, so store it somewhere safe. Every method below (REST, CLI, MCP) uses the same key and the same underlying endpoints: pick whichever fits how you want to pull data out.

REST API

Pass the key as a bearer token. {siteId}is the site's id (visible in its dashboard URL, not the tracking id used in the snippet above).range is optional and defaults to 7d. It also accepts today, yesterday, week, 30d, 90d, or a custom span of up to a year such as 2026-11-01..2026-11-15(whole days in the site's time zone).

/stats and /top-pages also take filters, combined with AND: page, referrer, country, browser, os, device_type, utm_source, utm_medium and utm_campaign, for example ?range=30d&country=KE&referrer=google.com. Use referrer=Direct for visits with no referrer.

bash
curl "https://yourdomain.com/api/v1/sites/YOUR_SITE_ID/stats?range=7d" \
  -H "Authorization: Bearer YOUR_API_KEY"

These endpoints are available, all under /api/v1/sites/{siteId}:

  • /stats: pageviews, visitors, bounce rate, avg. session duration, live visitor count
  • /top-pages: most-viewed pages for the range
  • /revenue: total revenue and revenue by traffic source (requires a connected payment provider)
  • /annotations: GET lists chart notes in the range; POST with { "label": "Launched v2", "date": "2026-11-29" } pins one (date is optional and defaults to now), handy from a deploy script. DELETE /annotations/{id} removes one.

CLI

Install @datarevly/cli globally, or run it with npx without installing anything:

bash
npm install -g @datarevly/cli
# or: npx @datarevly/cli stats --site YOUR_SITE_ID

Commands stats, top-pages, revenue, annotations and annotate map directly to the REST endpoints above:

bash
export DATAREVLY_API_KEY=YOUR_API_KEY
datarevly stats --site YOUR_SITE_ID --range 30d
datarevly annotate "Launched v2" --site YOUR_SITE_ID

Flags:

  • --site <id>: required, the site's id (same one used above)
  • --range <range>: 7d, 30d, or 90d (default 7d)
  • --api-key / --api-url: override the environment variables for a single call
  • --raw: compact JSON instead of pretty-printed, useful for piping into jq
  • -v, --version / -h, --help

Hosted MCP server (recommended)

Connect Claude, Cursor or any MCP client to https://yourdomain.com/api/mcp with the header Authorization: Bearer YOUR_API_KEY. Nothing to install. It has tools for stats with period comparison, the traffic chart, pages, sources, breakdowns, sessions, live visitors, goals and funnels, revenue, MRR history and ad spend, plus a few writes: creating goals and funnels, deleting a goal, and recording ad spend. Every tool takes the same ranges and filters as the REST API.

claude code
claude mcp add --transport http datarevly https://yourdomain.com/api/mcp \
  --header "Authorization: Bearer YOUR_API_KEY"

Local MCP server

For clients that only run local servers, @datarevly/mcp exposes the original three tools (get_stats, get_top_pages, get_revenue_by_source) over stdio:

json
{
  "mcpServers": {
    "datarevly": {
      "command": "npx",
      "args": ["-y", "@datarevly/mcp"],
      "env": {
        "DATAREVLY_API_KEY": "YOUR_API_KEY"
      }
    }
  }
}

Both datarevly and datarevly-mcp also honor DATAREVLY_API_URLas an environment variable if you're self-hosting instead of using https://yourdomain.com.