This guide describes how to subscribe to the event emitted when an Instant order is placed.
This can fulfil numerous requirements; mainly running custom javascript to dispatch data to analytics providers that Instant does not support out of the box for example.
1. Start by running this following block of code to subscribe to the “instantOrderPlaced’ event. The callback passed as the second parameter to the .on function will be run when an order has been placed.
window.InstantJS.on('instantOrderPlaced', (data) => {
// run your custom code here
});
2. The code running where the “run your custom code” comment is, will now run when an order is placed. The contents of the orderDetails argument will be in the structure below
InstantOrderPlacedItem schema:
{
"price": number, // e.g. 10000 (smallest unit of currency)
"name": string, // e.g. My Product
"id": string, // e.g. ProductID
"quantity": number // e.g. 5
}
InstantOrderPlaced schema:
{
"email": string, // e.g. test@instant.one
"first_name": string, // e.g. Bob
"last_name": string, // e.g. Jane
"phone": string, // e.g. +10000000000
"street": string, // e.g. 1 Park Avenue
"store_name": string, // e.g. My Store
"city": string, // e.g. New York
"region": string, // e.g. New York
"postal_code": string, // e.g. 12345
"country": string, // e.g. US
"id": string, // e.g. 123456
"grand_total": number, // e.g. 10000 (smallest unit of currency)
"shipping_total": number, // e.g. 500 (smallest unit of currency)
"tax_total": number, // e.g. 100 (smallest unit of currency)
"discounts_total": number, // e.g. 1000 (smallest unit of currency)
"subtotal": number, // e.g. 1000 (smallest unit of currency)
"currency": string, // e.g. USD
"coupon_code": string, // e.g. VIP10
"merchant_id": string, // e.g. myid
"store_code": string, // e.g. us
"items": Array of InstantOrderPlacedItem items
}
An example of what InstantOrderPlaced can look like is below.
{
"email": "test@instant.one",
"first_name": "Instant",
"last_name": "Demo",
"phone": "+10000000000",
"street": "1 Park Ave",
"store_name": "My Store",
"city": "New York",
"region": "New York",
"postal_code": "12345",
"country": "US",
"id": "000001450",
"grand_total": 29668,
"shipping_total": 0,
"tax_total": 100,
"discounts_total": 1000,
"subtotal": 29668,
"currency": "USD",
"coupon_code": "VIP10",
"merchant_id": "myId",
"store_code": "us",
"items": [
{
"price": 15674,
"name": "Test Item 2",
"id": "My Item ID",
"quantity": 1
},
{
"price": 13994,
"name": "Test Item 2",
"id": "My Item ID",
"quantity": 1
}
]
}