Docs/REVENUE/Server-side tracking (Recommended)

Server-Side Revenue Tracking (Recommended)

Recommended: Server-side tracking provides the most accurate revenue attribution by linking payments directly to user sessions from your backend, bypassing ad blockers and client-side issues.

How It Works

When a payment is completed on your server, send the user's session information along with the payment details to VersaTailor. This correctly attributes the payment to its source and shows you a clear picture of your user's journey.

Basic Implementation

Make a POST request to the VersaTailor API when a payment is successfully processed:

// Server-side revenue attribution
const response = await fetch(
  "https://versatailor.com/api/v1/attribute-payment",
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: "Bearer YOUR_VERSATAILOR_API_KEY", // Replace with your API key
    },
    body: JSON.stringify({
      session_id: userSessionId, // From VersaTailor cookies
      visitor_id: userVisitorId, // From VersaTailor cookies
      website_id: "your_website_id", // Your VersaTailor website ID
      email: "customer@example.com", // Customer's email
      revenue: 2999, // Amount in cents ($29.99)
    }),
  }
);

if (response.ok) {
  console.log("Revenue attributed successfully");
} else {
  console.error("Failed to attribute revenue");
}

Required Parameters

VersaTailor API Key

Get it from here

session_id & visitor_id

Retrieved from VersaTailor cookies on the user's browser. See extraction methods below.

website_id

Your unique website identifier from the VersaTailor dashboard URL.

email

Customer's email address. Use "dummy@example.com" if privacy is a concern.

revenue

Payment amount in cents. For example: $29.99 = 2999, $100.00 = 10000

Step 1: Get Your Website ID

  1. Log in to your VersaTailor dashboard
  2. Navigate to your website
  3. Copy the website ID from the URL: versatailor.com/dashboard/[website_id]

Step 2: Extract Session & Visitor IDs

The VersaTailor tracking script stores session and visitor IDs in cookies. Extract these on your server or send them from the frontend.

Frontend Extraction

// Get VersaTailor session and visitor IDs from cookies
function getVersaTailorIds() {
  const cookies = document.cookie.split(";");
  let sessionId = null;
  let visitorId = null;

  cookies.forEach((cookie) => {
    const [name, value] = cookie.trim().split("=");
    if (name === "vt_session_id") {
      sessionId = value;
    } else if (name === "vt_visitor_id") {
      visitorId = value;
    }
  });

  return { sessionId, visitorId };
}

// Send to your server
const { sessionId, visitorId } = getVersaTailorIds();

Server-Side Extraction

// Node.js example
function getVersaTailorIds(req) {
  const sessionId = req.cookies.vt_session_id;
  const visitorId = req.cookies.vt_visitor_id;
  return { sessionId, visitorId };
}

Implementation Examples

Node.js with Express

app.post("/api/payment-success", async (req, res) => {
  try {
    // Process payment
    const payment = await processPayment(req.body);

    // Get VersaTailor IDs from cookies
    const { sessionId, visitorId } = getVersaTailorIds(req);

    // Attribute revenue to VersaTailor
    await fetch("https://versatailor.com/api/v1/attribute-payment", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${process.env.VERSATAILOR_API_KEY}`,
      },
      body: JSON.stringify({
        session_id: sessionId,
        visitor_id: visitorId,
        website_id: process.env.VERSATAILOR_WEBSITE_ID,
        email: payment.customerEmail,
        revenue: payment.amountInCents,
      }),
    });

    res.json({ success: true });
  } catch (error) {
    console.error("Payment processing error:", error);
    res.status(500).json({ error: "Payment failed" });
  }
});

PHP Example

<?php
// Process payment
$payment = processPayment($_POST);

// Get VersaTailor IDs from cookies
$sessionId = $_COOKIE['vt_session_id'] ?? null;
$visitorId = $_COOKIE['vt_visitor_id'] ?? null;

// Attribute revenue to VersaTailor
$data = [
    'session_id' => $sessionId,
    'visitor_id' => $visitorId,
    'website_id' => $_ENV['VERSATAILOR_WEBSITE_ID'],
    'email' => $payment['customer_email'],
    'revenue' => $payment['amount_cents'],
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://versatailor.com/api/v1/attribute-payment');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Authorization: Bearer ' . $_ENV['VERSATAILOR_API_KEY']
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);
?>

Python with Flask

import requests
import os

@app.route('/api/payment-success', methods=['POST'])
def payment_success():
    try:
        # Process payment
        payment = process_payment(request.json)

        # Get VersaTailor IDs from cookies
        session_id = request.cookies.get('vt_session_id')
        visitor_id = request.cookies.get('vt_visitor_id')

        # Attribute revenue to VersaTailor
        response = requests.post(
            'https://versatailor.com/api/v1/attribute-payment',
            headers={
                'Content-Type': 'application/json',
                'Authorization': f'Bearer {os.getenv("VERSATAILOR_API_KEY")}'
            },
            json={
                'session_id': session_id,
                'visitor_id': visitor_id,
                'website_id': os.getenv('VERSATAILOR_WEBSITE_ID'),
                'email': payment['customer_email'],
                'revenue': payment['amount_cents'],
            }
        )

        return jsonify({'success': True})
    except Exception as e:
        return jsonify({'error': str(e)}), 500

Important Notes

Important Notes:

  • Only call the API after payment is successfully processed
  • Handle API failures gracefully - revenue attribution shouldn't break your payment flow

Troubleshooting

Revenue not appearing?

Please contact us at support@versatailor.com

Next Steps

Now that you understand server-side tracking:

Need help? Contact us for assistance.

Suggest features? We'd love your feedback