Sale Event Tracking with sendSaleEvent
Overview
The sendSaleEvent function allows you to report completed sales to GoWit for conversion tracking and analytics. Once the Retail Ads SDK is initialized on your site, sendSaleEvent is available globally as window.sendSaleEvent.
Usage
1. Prerequisites
- The Retail Ads SDK must be loaded and initialized on your page.
- Your global config (
window.__rma__conf) should be set with at leastbase_urlandid(your marketplace UUID).
2. Sending an Online Sale Event
Call window.sendSaleEvent after a successful transaction, passing a sales object:
window.sendSaleEvent({
sales: [
{
advertiser_id: "ADVERTISER_ID",
product_id: "PRODUCT_ID",
quantity: 1,
unit_price: 99.99,
},
],
// Optional:
// customer_id: "CUSTOMER_ID",
// location_id: "LOCATION_ID"
});
3. Sending an Offline Sale Event
For in-store or physical sales, use channel: "OFFLINE" with a sale_date and customer_id:
window.sendSaleEvent({
channel: "OFFLINE",
sale_date: "2026-01-12T14:30:00Z",
customer_id: "CUSTOMER_ID", // Required for offline attribution
sales: [
{
advertiser_id: "ADVERTISER_ID",
product_id: "PRODUCT_ID",
quantity: 1,
unit_price: 99.99,
},
],
// location_id: "LOCATION_ID" // Optional
});
Field Reference
Request-Level Fields
| Field | Type | Required | Description |
|---|---|---|---|
channel | string | No | "ONLINE" (default) or "OFFLINE" |
sale_date | string | For offline | ISO 8601 datetime. Required for offline sales. |
session_id | string | For online | Auto-included by SDK. Required for online attribution. |
customer_id | string | For offline | Your customer ID. Required for offline attribution. |
location_id | string | No | For multi-location marketplaces. |
Sales Array Fields
| Field | Type | Required | Description |
|---|---|---|---|
advertiser_id | string | Yes | The advertiser's unique ID. |
product_id | string | Yes | The product's unique ID. |
quantity | number | Yes | Number of units sold. |
unit_price | number | Yes | Price per unit. |
Handling the Response
sendSaleEvent returns a Promise:
// Using Promises
window
.sendSaleEvent(saleData)
.then((response) => {
console.log("Sale event sent:", response);
})
.catch((error) => {
console.error("Sale event failed:", error);
});
// Using async/await
async function reportSale(saleData) {
try {
const response = await window.sendSaleEvent(saleData);
console.log("Sale event sent:", response);
} catch (error) {
console.error("Sale event failed:", error);
}
}
Best Practices
- Call after payment confirmation: Only trigger
sendSaleEventafter a successful payment. - Validate your data: Ensure all required fields are present and correctly typed.
- Handle errors: Always handle errors to retry or log failures.
- Offline sales: Always include
customer_idandsale_datefor proper attribution.
Notes
- The SDK automatically includes your marketplace and session info from the global config.
- Invalid parameters will log a warning and the event will not be sent.
- The function works asynchronously and does not block your page.
- For offline sales, the
sale_dateis used to determine the conversion window for ad attribution.