Revenue
Revenue tracking is opt-in. You choose which events mean a payment went through and which mean it failed, and TraceIQ sums the amount on the successful ones. Projects that never set it up don’t see a Revenue card at all.
1. Send payment events
Send one event when a payment succeeds and one when it fails. Any names work; these are the ones we suggest:
payment_succeeded— The provider confirmed the payment. Carries amount, currency, provider and reference.payment_failed— The charge was declined or verification failed. Same properties, plus reason.
amount— A number in the main currency unit: naira, not kobo; dollars, not cents. Paystack and Stripe send the smallest unit, so divide by 100.currency— An ISO code such as NGN or USD. Send every amount in the currency you pick in settings.reference— The provider's transaction reference, so you can match an event to a payment.reason— On failures, the provider message or code (for example "Insufficient funds").
2. Send them from your backend
Send payment events where your payment provider confirms them: in its webhook handler, or after your server verifies the transaction. A browser event fires only if the customer comes back to your site after paying, so closing the tab loses the sale, and a decline on the provider’s page sends nothing at all.
// Paystack webhook (Express). Check x-paystack-signature first.
import { TraceIQ } from 'traceiq-node';
const traceiq = new TraceIQ({
projectId: process.env.TRACEIQ_PROJECT_ID!, // YOUR_PROJECT_ID
writeKey: process.env.TRACEIQ_WRITE_KEY!
});
app.post('/webhooks/paystack', verifyPaystackSignature, (req, res) => {
const { event, data } = req.body;
const payment = {
amount: data.amount / 100, // kobo to naira
currency: data.currency,
provider: 'paystack',
reference: data.reference,
plan: data.metadata?.plan
};
if (event === 'charge.success') {
traceiq.capture({ event: 'payment_succeeded', userId: data.metadata?.userId, properties: payment });
}
if (event === 'charge.failed') {
traceiq.capture({
event: 'payment_failed',
userId: data.metadata?.userId,
properties: { ...payment, reason: data.gateway_response }
});
}
res.sendStatus(200);
});Use the same userId your frontend passes to identify, so payments join the rest of that person’s activity. Webhooks are retried, so record each reference once. Stripe works the same way with payment_intent.succeeded and payment_intent.payment_failed; Flutterwave with charge.completed and its status.
Keep your frontend checkout events (checkout_started, plan_selected) as funnel steps, but don’t put an amount on them. Call it price instead.
3. Turn it on
Open Settings → Revenue. Mark your events as Paid or Failed, check the currency and amount property, switch revenue on and save. The page lists your recent events, pre-selects ones that look like payments, and shows the last 30 days with your settings so you can compare them with your provider’s dashboard.
Overview— A Revenue card with the total, successful and failed payments, and the change from the previous period.Weekly digest— Revenue for the week, for projects that turned it on.Funnels— Add payment_succeeded as the last step of your checkout funnel to see who actually paid.Alerts— Alert on a spike in payment_failed.
Set it up with AI
Paste this prompt into Claude Code, Cursor or another coding assistant inside your app’s repository. It finds your payment provider, adds both events in the webhook handler, and tells you the event names to select. This one is for a Node.js backend. Settings → Revenue has the same prompt for Python (Django, Flask, FastAPI), PHP, Rust or any other language over the HTTP API, filled in with your settings.
Add revenue tracking to this app with TraceIQ. Track every successful and failed payment from the backend (Node.js), where the payment provider confirms it.
1. Find the payment flow
- Find the payment provider (Paystack, Flutterwave, Stripe, Monnify, Paddle or another) and where payments are confirmed: the provider's webhook handler and any "verify transaction" call.
- If there is no webhook handler, add one using the provider's signature check (for example Paystack's x-paystack-signature HMAC, Stripe's constructEvent).
- Reuse the existing payment logic. Only add the tracking calls.
2. Set up TraceIQ for Node.js
- Install the TraceIQ Node SDK: npm install traceiq-node.
- Create one shared client:
import { TraceIQ } from 'traceiq-node';
export const traceiq = new TraceIQ({ projectId: process.env.TRACEIQ_PROJECT_ID!, writeKey: process.env.TRACEIQ_WRITE_KEY!, endpoint: process.env.TRACEIQ_API_URL ?? 'https://api.traceiq.run' });
- In serverless functions, await traceiq.flush() before returning.
- Add TRACEIQ_PROJECT_ID (YOUR_PROJECT_ID), TRACEIQ_WRITE_KEY and TRACEIQ_API_URL (https://api.traceiq.run) to the env example file. Never hard-code the write key. Without TRACEIQ_API_URL the SDKs send to localhost.
3. Use the same user id as the frontend
- Payment events must use the exact id the frontend passes to traceiq.identify(), or they won't join the user's journey.
- Look for that identify call in this repository. If the frontend lives in another repository, ask me which id it uses (email, database id or UUID). Don't assume the backend's user id matches.
4. Send "payment_succeeded" when a payment is confirmed
- Only after the provider confirms it (Paystack charge.success, Flutterwave charge.completed with status "successful", Stripe payment_intent.succeeded or invoice.paid).
traceiq.capture({
event: 'payment_succeeded',
userId: <the same user id the frontend passes to traceiq.identify>,
properties: {
amount: <amount in the main currency unit: naira, not kobo; dollars, not cents>,
currency: '<ISO code, e.g. USD>',
provider: '<paystack | flutterwave | stripe | …>',
reference: <the provider's transaction reference>,
plan: <plan or product, if any>
}
});
- Paystack and Stripe send amounts in the smallest unit, so divide by 100.
- Send it once per payment. Webhooks are retried, so skip a reference you've already recorded.
5. Send "payment_failed" when a payment fails
- On the provider's failure webhook (Paystack charge.failed, Stripe payment_intent.payment_failed, Flutterwave status "failed"), and when your own verify call says it failed.
- Same properties as above plus reason: <the provider's failure message or code>.
- Don't include card numbers, CVV, bank details or the customer's email in properties.
6. Clean up existing events
- Events that only show intent (checkout_started, plan_selected, redirected to the gateway) must not carry an "amount" property. Rename it to "price" if you need it.
- Keep the existing frontend checkout events as funnel steps.
7. Before finishing
- Tracking must never throw, fail or delay payment processing or the webhook response. Catch and log any analytics error.
- Add or update tests for the webhook handler: a successful payment, a failed payment, and the same webhook delivered twice.
- Tell me the exact event names you used for successful and failed payments, so I can select them in TraceIQ → Settings → Revenue.
