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 a 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"
});

Required fields for each sale:

  • advertiser_id (string): The advertiser's unique ID.
  • product_id (string): The product's unique ID.
  • quantity (number): Number of units sold.
  • unit_price (number): Price per unit.

Optional fields:

  • customer_id (string): The buyer's ID.
  • location_id (string): The sale location (for multi-location setups).

3. Handling the Response

sendSaleEvent returns a Promise. You can use .then/.catch or async/await to handle the result:

// 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);
}
}

4. 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.

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.