ThoughtMetric

JavaScript API

event()

Send custom events such as orders, add to carts and leads from the pixel.

Use event to send events to ThoughtMetric.

thoughtmetric('event', [event name], [properties])

Parameters

ParameterDescriptionRequired
event nameName of the eventRequired
propertiesJavaScript object of properties describing the orderRequired

Event names

ThoughtMetric tracks four conversion events that you can optimize your marketing against.

Event nameDescription
viewContentA visit to a web page you care about. For example, a product or landing page.
addToCartThe addition of an item to a shopping cart or basket. For example, clicking an Add to Cart button on a website.
leadA submission of information by a customer with the understanding that they may be contacted at a later date by your business. For example, submitting a form or signing up for a trial.
orderThe completion of a purchase, usually signified by receiving an order or purchase confirmation, or a transaction receipt.

Supported properties

Field nameDescriptionTypeRequired (for order event)
transaction_idUnique identifier for the transactionstringRequired
total_priceTotal value of the ordernumberRequired
currencyThe base currency that your store is configured to usestringRequired
orderCurrencyCurrency that the order was placed in (USD, GBP)stringRequired
subtotal_priceThe subtotal price of the ordernumberRecommended
total_discountsTotal discount amount of the order, as a positive numbernumberRecommended
total_shippingTotal shipping amount of the ordernumberRecommended
total_taxTotal tax amount of the ordernumberRecommended
item_quantityTotal number of items in the ordernumberRecommended
itemsArray of items sold[{ product_name: "Shoes", variant: "red", sku: "shoe-red", discounts: 0, quantity: 1, unit_price: 49.00}]Recommended
discount_codesDiscount codes used on the purchasearrayRecommended
lead_idIdentifier for the lead, such as an emailstringRecommended
statusThe payment status of the order. Valid values are "paid", "failed", and "refunded".stringRecommended

Examples

Basic order event

The most basic event call for an order sends only the required fields.

thoughtmetric('event', 'order', {
 transaction_id: '123',
 total_price: 55.00,
 currency: 'USD',
 orderCurrency: 'USD'
});

Detailed order event

This example sends more detailed pricing information along with the order event, including subtotal, discounts, shipping, and tax amounts.

thoughtmetric('event', 'order', {
 transaction_id: '123',
 total_price: 55.00,
 currency: 'USD',
 orderCurrency: 'USD',
 subtotal_price: 49.00,
 total_tax: 1.00,
 total_shipping: 5.00,
 total_discounts: 0.00,
 discount_codes: ["discount1"],
 items: [{ product_name: "Shoes", variant: "red", sku: "shoe-red", discounts: 0, quantity: 1, unit_price: 49.00,  refund_amount: 0, quantity_refunded: 0}] 
});

Add to cart event

This example sends an addToCart event.

thoughtmetric('event', 'addToCart', {
 total_price: 55.00,
 currency: 'USD',
 orderCurrency: 'USD'
});

Lead event

This example sends a lead event.

thoughtmetric('event', 'lead', {
 lead_id: 'john.snow@winterfell.com'
});

View content event

This example sends a viewContent event.

thoughtmetric('event', 'viewContent', {
});