traaaction
v1.3.0
Published
TypeScript/JavaScript SDK for Traaaction affiliate tracking and management
Downloads
24
Maintainers
Readme
traaaction
Official TypeScript/JavaScript SDK for Traaaction — the affiliate SaaS platform connecting startups and sellers.
Installation
npm install traaaction
# or
yarn add traaaction
# or
pnpm add traaactionQuick Start
import { Traaaction } from 'traaaction'
const trac = new Traaaction({
apiKey: process.env.TRAAACTION_API_KEY, // trac_live_xxx
})Tracking
Track affiliate events from your server. Use the public key (pk_xxx) or secret key.
// After a user signs up
await trac.track.lead({
customerId: user.id,
clickId: request.cookies.get('trac_click_id')?.value,
eventName: 'sign_up',
customerEmail: user.email,
})
// Manual sale (if not using Stripe webhooks)
await trac.track.sale({
customerId: user.id,
amount: 5900, // €59 in cents
currency: 'EUR',
})Management API
All management methods require a secret key (trac_live_xxx).
Short Links
// List links
const { data: links, meta } = await trac.links.list({ page: 1, limit: 50 })
// Create a link
const { data: link } = await trac.links.create({
destination: 'https://example.com/landing',
missionId: 'mission_id_here',
})
// Update a link
await trac.links.update(link.id, { channel: 'email' })
// Delete a link
await trac.links.delete(link.id)Missions
const { data: missions } = await trac.missions.list({ status: 'ACTIVE' })
const { data: mission } = await trac.missions.get('mission_id')Sellers
const { data: sellers } = await trac.sellers.list({ status: 'APPROVED' })
const { data: seller } = await trac.sellers.get('seller_id')
// seller.balance includes { pending, due, paid_total }Customers
const { data: customers } = await trac.customers.list()
// Lookup by your app's user ID
const { data: customer } = await trac.customers.get(user.id)Commissions
const { data: commissions } = await trac.commissions.list({
status: 'PROCEED',
sellerId: 'seller_id',
})Payouts
const { data: payouts } = await trac.payouts.list()Analytics
const { data: stats } = await trac.analytics.retrieve({ interval: '30d' })
// stats.clicks, stats.leads, stats.sales, stats.revenue, stats.timeseriesError Handling
import { Traaaction, TraaactionAPIError, TraaactionAuthError } from 'traaaction'
try {
const { data } = await trac.links.get('invalid_id')
} catch (error) {
if (error instanceof TraaactionAuthError) {
console.error('Invalid API key')
} else if (error instanceof TraaactionAPIError) {
console.error(`API error ${error.statusCode}: ${error.code}`)
}
}Requirements
- Node.js 18+ (uses native
fetch) - Works in Edge Runtime (Vercel, Cloudflare Workers)
License
MIT
