Appearance
Track Order
Call trackOrder() on your order confirmation page to track purchases and calculate commissions.
Usage
javascript
<script>
const orderData = {
orderId: "ORD-12345",
total: 99.99,
subtotal: 89.99, // Optional
discount: 10.00, // Optional
tax: 8.00, // Optional
customer: {
email: "customer@example.com",
userId: "user_12345", // Optional
name: "John Doe", // Optional
address: { // Optional
address_line1: "123 Main St",
city: "New York",
state: "NY",
country: "US"
}
},
lineItems: [ // Optional
{
productId: "PROD-001",
name: "Running Shoes",
qty: 2,
price: 44.99
}
]
};
AffiliateSDK.trackOrder(orderData);
</script>php
<!-- In WooCommerce thank-you page -->
<?php
$order_data = array(
'orderId' => $order->get_id(),
'total' => $order->get_total(),
'subtotal' => $order->get_subtotal(), // Optional
'discount' => $order->get_total_discount(), // Optional
'tax' => $order->get_total_tax(), // Optional
'customer' => array(
'email' => $order->get_billing_email(),
'userId' => $order->get_customer_id(), // Optional
'name' => $order->get_billing_first_name() . ' ' . $order->get_billing_last_name() // Optional
)
);
?>
<script>
const orderData = <?php echo json_encode($order_data); ?>;
AffiliateSDK.trackOrder(orderData);
</script>liquid
<!-- In order confirmation page -->
<script>
const orderData = {
orderId: "{{ order.name }}",
total: {{ order.total_price | money_without_currency }},
subtotal: {{ order.subtotal_price | money_without_currency }}, // Optional
discount: {{ order.total_discounts | money_without_currency }}, // Optional
tax: {{ order.tax_price | money_without_currency }}, // Optional
customer: {
email: "{{ order.email }}",
name: "{{ order.customer.name }}" // Optional
}
};
AffiliateSDK.trackOrder(orderData);
</script>jsx
import { useEffect } from "react";
export default function ThankYou({ order }) {
useEffect(() => {
const orderData = {
orderId: order.id,
total: order.total,
subtotal: order.subtotal, // Optional
discount: order.discount, // Optional
tax: order.tax, // Optional
customer: {
email: order.customerEmail,
userId: order.customerId, // Optional
name: order.customerName, // Optional
},
lineItems: order.items.map((item) => ({
// Optional
productId: item.id,
name: item.name,
qty: item.quantity,
price: item.price,
})),
};
if (window.AffiliateSDK) {
window.AffiliateSDK.trackOrder(orderData);
}
}, [order]);
return <h1>Order Confirmed!</h1>;
}vue
<script setup lang="ts">
const order = ref(null);
onMounted(() => {
const orderData = {
orderId: order.value.id,
total: order.value.total,
subtotal: order.value.subtotal, // Optional
discount: order.value.discount, // Optional
tax: order.value.tax, // Optional
customer: {
email: order.value.customerEmail,
userId: order.value.customerId, // Optional
name: order.value.customerName, // Optional
},
lineItems: order.value.items, // Optional
};
if (window.AffiliateSDK) {
window.AffiliateSDK.trackOrder(orderData);
}
});
</script>
<template>
<h1>Order Confirmed!</h1>
</template>