Important: For conversion tracking to work, users must arrive on your
website via a Taapit deeplink. This is how the tracking ID (ta_tid) is
generated and passed to your site.
Before you start:
Create a Taapit deeplink pointing to your website or landing page
import { Taapit } from "taapit-sdk";import { cookies } from "next/headers";const taapit = new Taapit({ apiKey: process.env.TAAPIT_API_KEY,});export async function POST(request: Request) { const body = await request.json(); // Get tracking ID from cookie const cookieStore = cookies(); const trackingId = cookieStore.get("ta_tid")?.value; // Create user in your database const user = await db.users.create({ email: body.email, name: body.name, }); // Track the lead if (trackingId) { await taapit.track.lead({ trackingId, customer: { externalId: user.id, email: user.email, }, }); } return Response.json({ user });}
trackingId for sales: If the customer was already tracked via a lead
event, the trackingId is optional for sale events. You only need to
provide the customerExternalId to link the sale to the existing customer. If
this is a new customer (no prior lead), trackingId is required.
Node.js SDK
REST API
Copy
export async function POST(request: Request) { const body = await request.json(); const cookieStore = cookies(); const trackingId = cookieStore.get('ta_tid')?.value || body.trackingId; // Verify payment const order = await verifyPayment(body); // Track sale // trackingId is optional if customer was already tracked via a lead event await taapit.track.sale({ trackingId, // Optional if customer already exists customer: { externalId: order.userId, // Required - links to existing customer or creates new one email: order.customerEmail, }, amount: order.total, // e.g., 149.99 (NOT cents) currency: order.currency, // e.g., 'eur' metadata: { orderId: order.id, productIds: order.items.map(i => i.productId), }, }); return Response.json({ success: true });}
Copy
# With trackingId (new customer or first-time tracking)curl -X POST https://track.taap.it/api/events/sale \ -H "Authorization: Bearer taapit_sk_xxx" \ -H "Content-Type: application/json" \ -d '{ "trackingId": "rLnWe1uz9t282v7g", "customer": { "externalId": "user_123", "email": "john@example.com" }, "amount": 99.99, "currency": "eur", "metadata": { "orderId": "order_456" } }'# Without trackingId (customer already tracked via lead event)curl -X POST https://track.taap.it/api/events/sale \ -H "Authorization: Bearer taapit_sk_xxx" \ -H "Content-Type: application/json" \ -d '{"customer": {"externalId": "user_123"},"amount": 99.99,"currency": "eur"}'
{ "trackingId": "rLnWe1uz9t282v7g", "customer": { "externalId": "user_123", "email": "john@example.com", "firstname": "John", "lastname": "Doe", "phoneNumber": "+33612345678", "avatarUrl": "https://example.com/avatar.jpg" }, "amount": 99.99, // Sale only "currency": "eur", // Sale only "metadata": {}}
Field
Type
Required
Description
trackingId
string
See below
The ta_tid from cookie/URL
customer.externalId
string
Yes
Your internal user ID
customer.email
string
No
User’s email
amount
number
Sale only
Amount in currency units
currency
string
Sale only
ISO 4217 code (eur, usd…)
metadata
object
No
Custom data
When is trackingId required? - Lead events: trackingId is always
required - Sale events: - If the customerExternalId was already
tracked (via a previous lead event), trackingId is optional - If this is
a new customer (no prior lead event), trackingId is required to create
the customer record