Analytics
  • Overview
  • Realtime
  • Errors
Manage
  • Setup & export
  • Sign in to add your sites
  • Back to site

Setup & export

acme.store

1. Add the script
Paste it into the <head> of every page on acme.store.
index.html
<script
  defer
  data-website-id="demo"
  src="https://usedatasense.com/js/script.js"
></script>
Receiving data · last event 3h ago
Track goals (optional)
// From JavaScript
window.datasense?.("signup", { plan: "pro" })

// Or declaratively on any element
<button data-ds-goal="checkout" data-ds-goal-plan="pro">Buy</button>
2. Route through your domain
Recommended. Ad blockers and private browsing drop requests to analytics domains; a first-party path on acme.store gets through. The script detects the proxy automatically.

Pick a short, unique path. Filter lists match common analytics paths, not /_ds on your own domain.

next.config.ts
// next.config.ts
import type { NextConfig } from "next"

const nextConfig: NextConfig = {
  async rewrites() {
    return [
      { source: "/_ds/js/script.js", destination: "https://usedatasense.com/js/script.js" },
      { source: "/_ds/api/e", destination: "https://usedatasense.com/api/e" },
    ]
  },
}

export default nextConfig
Then load the script from your own domain
<script
  defer
  data-website-id="demo"
  src="/_ds/js/script.js"
></script>
3. Attribute revenue
See which sources bring paying customers. Carry the visitor's session ID through checkout, then report each payment from your webhook. Works with any provider; repeated webhooks are de-duplicated by transaction ID.
Secret API keyNo key yet
checkout.js
// 1. In the browser, when the visitor starts checkout
await fetch("/api/checkout", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    plan: "pro",
    datasense_session_id: window.datasense?.sessionId?.(),
  }),
})
api/checkout.js
// 2. On your server, keep it on the checkout session
const session = await stripe.checkout.sessions.create({
  line_items: [/* … */],
  metadata: { datasense_session_id: body.datasense_session_id },
})
api/webhook.js
// 3. In your payment webhook, report the successful payment
await fetch("https://usedatasense.com/api/v1/payments", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.DATASENSE_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    amount: 29.99,                 // in major units, not cents
    currency: "USD",
    transaction_id: payment.id,    // makes retries safe
    datasense_session_id: payment.metadata.datasense_session_id,
    customer_id: payment.customer, // optional
    renewal: false,                // true for subscription renewals
    // refunded: true,             // send again with this for a refund
  }),
})
Receiving payments · last one 4h ago
Export data
Download raw rows for spreadsheets, notebooks or your warehouse.

Pageviews, goals and time on page, one row per event.

Download events as CSV