Documentation

Express guide

Parse JSON with express.json(), load the order in your process, then send amountMinor from that record. The token stays in the environment. Vendor packages/node/src/index.ts; the package is not on npm.

import express from 'express';
import { createClient } from '@analyticfast/node';

const analytics = createClient({
  token: process.env.ANALYTICFAST_TOKEN,
  baseUrl: process.env.ANALYTICFAST_BASE_URL,
  siteId: process.env.ANALYTICFAST_SITE_ID,
});
const app = express();
app.use(express.json());

app.post('/orders/:id/paid', async (req, res, next) => {
  try {
    const order = await loadPaidOrder(req.params.id); // authoritative amount, not req.body.amount
    const result = await analytics.payment({
      transactionId: order.id,
      amountMinor: order.totalMinor,
      currency: order.currency,
      visitorId: typeof req.body?.visitorId === 'string' ? req.body.visitorId : undefined,
    });
    res.json(result);
  } catch (error) { next(error); }
});

req.body is untrusted. Confirm the order is paid before calling AnalyticFast. The same transactionId on a retry returns the original payment instead of adding revenue again. visitorId is the website ml_vid value your checkout stored. Omit it when you do not have it.

A goal from this server uses analytics.track({ name: 'signup', visitorId, eventId: order.id }) with an events:write token. One token may hold both scopes.

Official references, checked 2026-10-26: express.json(), routing.

Questions, answered.

How do I use express with AnalyticFast?

Follow the Express instructions on this page using your own website’s Site ID and configuration. Verify a real event before relying on the reports.

Where can I get setup help?

Contact support@analyticfast.com with the website domain and a redacted description. Do not send API tokens, signing secrets or personal customer data.