Revenue Configuration
@pulsora/revenue runs on your server or serverless functions. This page explains the configuration options and recommended setups.
Installation Recap
npm install @pulsora/revenue
import { Revenue } from '@pulsora/revenue';
const revenue = new Revenue({
apiToken: process.env.PULSORA_SECRET!,
});
Always use secret tokens (they start with sec_) when instantiating the revenue tracker. Secret tokens grant access to revenue ingestion and must never be shipped to the browser.
Configuration Options
interface RevenueConfig {
apiToken: string;
debug?: boolean; // default: false
maxRetries?: number; // default: 3
retryBackoff?: number; // default: 1000 (ms)
}
- apiToken (required) — Your secret API token. Load it from environment variables or a secrets manager.
- debug — Prints detailed logs to stdout when
true. - maxRetries — Max number of automatic retries for network or rate-limit errors.
- retryBackoff — Initial delay for exponential backoff between retries.
Environment Variables
Recommended .env entries:
PULSORA_SECRET=sec_xxx
PULSORA_DEBUG=false
Then wire them into the config:
const revenue = new Revenue({
apiToken: process.env.PULSORA_SECRET!,
debug: process.env.PULSORA_DEBUG === 'true',
});
Framework Examples
Node.js / Express
import express from 'express';
import { Revenue } from '@pulsora/revenue';
const revenue = new Revenue({ apiToken: process.env.PULSORA_SECRET! });
const app = express();
app.post('/webhooks/stripe', express.json(), async (req, res) => {
const session = req.body.data.object;
await revenue.track({
visitor_fingerprint: session.metadata.visitor_fingerprint,
session_id: session.metadata.session_id,
customer_id: session.customer,
amount: session.amount_total / 100,
currency: session.currency.toUpperCase(),
transaction_id: session.id,
payment_processor: 'stripe',
event_type: 'purchase',
});
res.json({ received: true });
});
Serverless Functions (Vercel, Netlify, AWS Lambda)
import { Revenue } from '@pulsora/revenue';
const revenue = new Revenue({
apiToken: process.env.PULSORA_SECRET!,
});
export default async function handler(req, res) {
if (req.method !== 'POST') {
return res.status(405).end();
}
await revenue.track(req.body);
res.status(200).json({ success: true });
}
Remember to enable body parsing (JSON) in your serverless platform and to verify webhook signatures from processors like Stripe or Paddle before calling revenue.track().
Security Checklist
- ✅ Load tokens from environment variables, not source control.
- ✅ Verify webhook signatures before accepting payloads.
- ✅ Never call
new Revenue()inside browser bundles. - ✅ Log failures to your monitoring tool (Sentry, Datadog, etc.).
- ✅ Handle promise rejections on
revenue.track()to avoid swallowing errors.
Continue to the API reference for payload structure: API Reference →