Documentation
Next.js server actions guide
Read the visitor id in the browser (attribution().ml_visitor_id from the browser package, or the ml_vid cookie) and pass it into a Server Action. Take the price from your catalog on the server. A Server Action is a public POST, so authenticate the shopper and ignore any amount sent by the browser.
@analyticfast/node is not published. Vendor packages/node/src/index.ts until it is. Keep ANALYTICFAST_TOKEN in the server environment, never in a client component.
'use server';
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,
});
export async function recordPaidOrder(input: { orderId: string; visitorId?: string }) {
const order = await loadOrderForCurrentUser(input.orderId); // your database, not the client price
return analytics.payment({
transactionId: order.id,
amountMinor: order.totalMinor, // 2999 = $29.99
currency: order.currency, // 'USD'
visitorId: input.visitorId,
});
}
Call it from the client with startTransition or a form action. Retrying the action with the same order id is safe. Use track (events:write) for a server-side goal such as signup, and identify only with identity the customer gave you.
The browser install stays the client component in [Next.js installation](../install/nextjs.md). Do not put the API token next to init().
Official references, checked 2026-10-26: use server, Server Actions.
Questions, answered.
How do I use next.js server actions with AnalyticFast?
Follow the Next.js server actions 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.