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
| Parameter | Description | Required |
|---|---|---|
event name | Name of the event | Required |
properties | JavaScript object of properties describing the order | Required |
Event names
ThoughtMetric tracks four conversion events that you can optimize your marketing against.
| Event name | Description |
|---|---|
viewContent | A visit to a web page you care about. For example, a product or landing page. |
addToCart | The addition of an item to a shopping cart or basket. For example, clicking an Add to Cart button on a website. |
lead | A 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. |
order | The completion of a purchase, usually signified by receiving an order or purchase confirmation, or a transaction receipt. |
Supported properties
| Field name | Description | Type | Required (for order event) |
|---|---|---|---|
transaction_id | Unique identifier for the transaction | string | Required |
total_price | Total value of the order | number | Required |
currency | The base currency that your store is configured to use | string | Required |
orderCurrency | Currency that the order was placed in (USD, GBP) | string | Required |
subtotal_price | The subtotal price of the order | number | Recommended |
total_discounts | Total discount amount of the order, as a positive number | number | Recommended |
total_shipping | Total shipping amount of the order | number | Recommended |
total_tax | Total tax amount of the order | number | Recommended |
item_quantity | Total number of items in the order | number | Recommended |
items | Array of items sold | [{ product_name: "Shoes", variant: "red", sku: "shoe-red", discounts: 0, quantity: 1, unit_price: 49.00}] | Recommended |
discount_codes | Discount codes used on the purchase | array | Recommended |
lead_id | Identifier for the lead, such as an email | string | Recommended |
status | The payment status of the order. Valid values are "paid", "failed", and "refunded". | string | Recommended |
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', {
});