E-commerce Events

Creating An Order

Order Object

Construct a set of objects that contain your line item and order details, ultimately creating a final order object which you will report to Button below.

The structure of this order object is nearly identical to orders reported server-side. The only difference is that reporting the btn_ref, Button's opaque tracking token, is not needed. As long as ButtonJS was on the page the user's landing page, it is picked up automatically by the library.

📘

Object Definitions

Please view the definitions for each displayed field. View definitions

// Create line item 1
let lineItem1 = {
  identifier: 's6-18860485p21a12v65a13v54',
  sku: 's6-18860485p21a12v65a13v54',
  description: 'Keep Calm and Droid On - R2-D2 Art',
  category: ['Home Decor'],
  total: 3799,
  quantity: 1,
  attributes: {
    promo_code: 'maythefourthbewithyou',
    brand: 'Ariel Sinha'
  }
};

// Create line item 2
let lineItem2 = {
  identifier: 's6-19791302p77a224v780',
  sku: 's6-19791302p77a224v780',
  description: 'Leia Skywalker Bar Stool',
  category: ['Furniture'],
  total: 39800, // total = item unit price * quantity
  quantity: 2,
  attributes: {
    promo_code: 'maythefourthbewithyou',
    brand: 'Ariel Sinha'
  }
};

// Create a customer (email is lowercased, then hashed via SHA-256)
let customerObject = {
  id: 'customer-1234',
  email_sha256: '814FA0649630F8B219E30952E92FEEFB70005C386C726F92FA93D1C18018EADE',
  device_id: '12345678-1234-5678-1234-567812345678',
  is_new: true,
};

// Create the order and add optional properties
// Order total will be calculated from line-item totals
let order = {
  order_id: 'order-1a2b3c',
  customer_order_id: 'receipt-123456',
  currency: 'USD',
  purchase_date: '2020-07-301T12:00:00Z',
  customer: customerObject,
  line_items: [lineItem1, lineItem2]
};

Reporting The Order

After creating the order object, you can then report your order to Button. If so desired, you can include a callback function as the third argument - however this is entirely optional.

// Report the order directly to Button.
bttnio('reportOrder', order, optionalCallback)

🚧

Report All Orders

Button recommends you call this method for each order tracked on your website. Attempting to conditionally fire this method (i.e. based on the presence of tracking information) could result in unexpected issues.

Button's system is designed to detect and subsequently process orders based on whether Button was involved with the user's activity on site.

Order Object Definitions


Did this page help you?