Integrations · Apps

Node.js, sales from your server.

Record purchases and signups from route handlers, cron jobs and Stripe or Shopify webhooks. Sent from inside the buyer’s request, each one joins their visit, so the source that brought them gets the credit.

Node 18 or laterNever throwsCounted once
app/api/checkout/route.tsTS
await stats.track(request, website.id, 'Purchase', {
  revenue: { amount: 49, currency: 'USD' },
  props: { plan: 'pro' },
});

Illustration

At a glance

Server events, joined to the visit.

What changes when your server uses the SDK.

  • Credit to the source

    Sales from the buyer’s request join their visit.

  • Never throws

    A stats hiccup can’t break a checkout or a signup.

  • Counted once

    The same event id within three days counts once.

  • Any runtime

    Node 18 or later, Deno, Bun and edge runtimes.

Ways to send

Send from anywhere on your server.

From the nahnu-analytics-sdk package.

MethodWhenDetails
track()Inside the buyer’s requestJoins their visit; returns false on failure
trackAfter()After the response, with Next.js 15The page never waits
events.send()Cron jobs and importsOne event or a list of up to 50
fromStripe()Your Stripe webhookPaid checkouts become Purchase, renewals Subscription renewed
fromShopify()Shopify’s orders/paid webhookUses the buyer’s IP and browser; test orders are skipped

Where it shows

Where you see it.

Server events count with the browser’s.

  • Revenue

    Purchases and renewals with their amounts.

  • Goals

    Add a goal with the event’s name.

  • Sources

    The source that brought the buyer gets the credit.

  • Funnels

    Across server events and pages.

  • Your clients’ sites

    One platform key works for all clients.

  • Health check

    stats.check() says what is wrong, if anything.

Install

One package, two environment variables.

Install the package, make a platform key in wp-admin under Nahnu Analytics › Data & API › API keys, and set two environment variables.

  • A platform key works for all clients
  • 20,000 requests an hour
  • Keep the key on your server only
Install and authenticate →
.envBASH
NAHNU_ANALYTICS_URL=https://stats.example.com
NAHNU_ANALYTICS_KEY=nak_…

Webhooks

A sale sent twice is still one sale.

Give every event an id, such as your order number or a webhook’s event id. A webhook sent again is then not a second sale, and the SDK can safely retry it.

  • fromStripe and fromShopify set the id for you
  • Stripe amounts are converted from cents for each currency
  • Without the buyer’s address a sale still counts, as its own visitor
Read the server guide →
Stripe webhookTS
import { fromStripe } from 'nahnu-analytics-sdk';

const sale = fromStripe(event);
if (sale) await stats.events.send(sale.site ?? website.id, sale.event);

Questions

Node.js questions

Something else? Ask us.

Which runtimes are supported?

Node 18 or later, or any runtime with fetch and Web Crypto, such as Deno, Bun and edge runtimes.

Can a stats error break my checkout?

No. track() never throws. It returns false and passes the error to onError.

Will a webhook sent twice count twice?

No. The same event id within three days counts once.

Is the platform key safe in my app?

Keep it on your server only, never in a browser bundle or an app.

Try it on every client site.

Unlimited websites, every feature, one license.