Skip to content

Quickstart: Tracking purchases and key conversions with the Events API

View MD

You’ve learned how to track what users see and click on using the Events API. The next crucial step is to track when they perform a meaningful action, known as a conversion. A conversion is any user action that is important to your business, but the most significant one is a completed purchase.

Tracking purchases provides the strongest possible positive signal to the Luigi’s Box AI models, directly teaching them which products are most valuable and helping to improve search ranking and recommendations for all future users.

  • How to send an “add to cart” conversion event using the Events API.
  • How to send a transaction event to record a completed purchase using the Events API.
  • Best practices for tracking conversion events accurately with the Events API.

Before you start, please ensure you have the following:

  • A working analytics setup using the Events API.
  • Luigi’s Box tracker_id.
  • The ability to add tracking code to your backend logic that fires when a user adds an item to the cart and completes a purchase.

All events are sent via an HTTP POST request to https://api.luigisbox.com/.

Tracking when a user adds an item to their cart is a key “micro-conversion” that signals strong interest. You should send a click event with a descriptive action.type every time this action occurs.

{
"id": "a1b2c3d4-e5f6-7890-1234-567890abcdef", // A globally unique ID for this event
"type": "click",
"tracker_id": "YOUR_TRACKER_ID",
"client_id": 6667519810961010000,
"action": {
"type": "add-to-cart", // Descriptive action type
"resource_identifier": "SKU_12345" // The ID of the item added to the cart
},
"platform": "backend" // Optional
}
  • type: Must be exactly "click" for this type of conversion.
  • action.type: Use a descriptive name like “add-to-cart”. Anything other than “click” for action.type is considered a conversion.
  • action.resource_identifier: The unique ID of the product being added to the cart. This must match the ID in your catalog.

These examples show how to make HTTP POST requests to the Events API.

require 'faraday'
require 'json'
require 'securerandom'
# --- Configuration (ensure these are defined, e.g., from a previous guide/setup) ---
TRACKER_ID = "YOUR_TRACKER_ID"
API_ENDPOINT = "https://api.luigisbox.com/"
CLIENT_ID = 6667519810961010000
# --- Helper Function using Faraday (ensure this is defined) ---
# def send_luigis_box_event(payload) ... end
add_to_cart_payload = {
id: SecureRandom.uuid,
type: "click",
tracker_id: TRACKER_ID,
client_id: CLIENT_ID,
action: {
type: "add-to-cart",
resource_identifier: "SKU_12345" # ID of item added
},
platform: "backend-ruby-faraday"
}
puts "Sending 'Add to Cart' Event..."
send_luigis_box_event(add_to_cart_payload)

This is the final and most important conversion. When a transaction is successfully completed, send a transaction event. This event should contain details about the entire transaction.

{
"id": "03dd16c3-4dd5-44c0-87c4-b3a652c06a87", // A new unique ID for this event
"type": "transaction",
"tracker_id": "YOUR_TRACKER_ID",
"client_id": 6667519810961010000,
"items": [
{
"title": "White shirt, round neck, short sleeves",
"url": "9339993", // Unique ID of the product
"count": 1, // Quantity purchased
"total_price": 19, // Total price for this line item (quantity * unit_price)
"was_discounted": false,
"was_volume_discounted": false
},
{
"title": "Brown overcoat",
"url": "299299",
"count": 2,
"total_price": 268.50,
"was_discounted": true,
"was_volume_discounted": false
}
// ... all other items in the transaction
]
}
  • type: Must be exactly "transaction" for this type of conversion.
  • items: An array containing details for each product in the order.
  • items.url: The unique ID of the purchased product, matching your catalog.
  • items.count: The quantity of this specific product purchased.
  • items.total_price: The total price for this line item (i.e., unit price multiplied by quantity), after any applicable discounts.
  • items.was_discounted: Boolean indicating if any discount was applied to this item.
  • items.was_volume_discounted: Boolean indicating if a discount was applied based on quantity.
# (Assuming send_luigis_box_event and config from previous guide are defined)
purchased_items_details = [
{ title: "White shirt...", url: "9339993", count: 1, total_price: 19, was_discounted: false, was_volume_discounted: false },
{ title: "Brown overcoat", url: "299299", count: 2, total_price: 268.50, was_discounted: true, was_volume_discounted: false }
]
transaction_payload = {
id: SecureRandom.uuid,
type: "transaction",
tracker_id: TRACKER_ID,
client_id: CLIENT_ID,
items: purchased_items_details
}
puts "Sending Transaction Event..."
send_luigis_box_event(transaction_payload)
  • Track on confirmation: Fire the transaction event only after payment is successfully confirmed. This prevents tracking abandoned or failed transactions and keeps your data clean.
  • Include all items: The items array in a transaction event should contain every single item from the order to give the AI a complete picture of what was purchased together.
  • Verify with the session explorer: After sending a test conversion or transaction, use the Live Session Explorer in the Luigi’s Box application to confirm that the event was received correctly with all its data.
  • Use descriptive action types: For non-purchase conversions (like “add_to_wishlist”), use clear and consistent names for action.type.

Beyond adding to the cart and purchasing, you can track other important conversions that signal user interest:

  • Analyze performance: Once tracking is in place, you can use the Luigi’s Box Analytics dashboard to see how your search and recommendation features are driving these key conversions.