Skip to main content

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 least base_url and id (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

FieldTypeRequiredDescription
channelstringNo"ONLINE" (default) or "OFFLINE"
sale_datestringFor offlineISO 8601 datetime. Required for offline sales.
session_idstringFor onlineAuto-included by SDK. Required for online attribution.
customer_idstringFor offlineYour customer ID. Required for offline attribution.
location_idstringNoFor multi-location marketplaces.

Sales Array Fields

FieldTypeRequiredDescription
advertiser_idstringYesThe advertiser's unique ID.
product_idstringYesThe product's unique ID.
quantitynumberYesNumber of units sold.
unit_pricenumberYesPrice 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 sendSaleEvent after 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_id and sale_date for 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_date is used to determine the conversion window for ad attribution.