Basket Object

Prev Next

Basket Object includes the properties of the product(s) in the customer's basket. This object must be implemented on every page that contains the basket, except for the transaction page. After any action involving the basket (adding or removing a product), this object must be updated in every basket.

This guide answers the following questions:

What are the prerequisites?

  • The Insider tag must be implemented.
  • The Insider object must be defined before the Insider tag. Otherwise, the Insider tag cannot read any information from the Insider object.

What are the properties?

The Basket object has the following properties.

KeyPropertyTypeDefinitionRequired
currencyCurrencyStringCurrency used for total basket price, in ISO 4217 format (e.g., USD)Yes
totalTotal priceFloatTotal price of the transaction, including any shipping fees or taxesYes
line_itemsBasket itemsArrayAn array containing the product item(s) in the basketYes
productProduct objectObjectProduct objectYes
idProduct IDStringUnique product ID that should be the same as that on the product pageYes
nameProduct NameStringName of the productYes
taxonomyBreadcrumbArrayCategory tree of the productYes
currencyCurrencyStringCurrency used for product pricing, in ISO 4217 format (e.g. USD)Yes
unit_priceProduct price without any discount(s)FloatPrice of the product without any discount(s)Yes
unit_sale_priceUnit priceFloatUnit price of the productYes
urlProduct page linkStringURL address of the productYes
stockStock information of the productNumberNumber of products left in stockNo
colorProduct colorStringColor of the product (selected by the user)No
sizeProduct sizeStringSize of the product (selected by the user)No
product_image_urlProduct image linkStringURL address of the product imageYes
quantityQuantityNumberNumber of productsYes
subtotalTotal sumFloatTotal sum of the unit sale prices of the productsYes
shipping_costShipping costFloatShipping cost of the items in basketNo
customCustomObjectCustom object that includes custom properties to be collected to Insider database as custom event parametersNo

What are the things to keep in mind?

When integrating the object, the following factors should be considered.

  • The page should return Basket for the type after running window.insider_object.page.type on the browser console. 
  • window.insider_object.basket.total should return the correct basket total.
  • When a voucher is applied, the object should also be updated to display the correct value.
  • window.insider_object.basket.currency should return the correct currency.

Sample Code

Below is a sample code for the Basket object.

window.insider_object = window.insider_object || {};
window.insider_object.basket = {
    "currency": "USD",
    "total": 277.9,
    "shipping_cost": 9.9,
    "line_items": [
        {
            "product": {
                "id": "N1234",
                "name": "Sleep Mask",
                "taxonomy": [
                    "Skincare",
                    "Moisturizers",
                    "Night Creams"
                ],
                "currency": "USD",
                "unit_price": 100,
                "unit_sale_price": 95.2,
                "url": "https://www.mywebsite.com/en-us/sleep-mask/n1234/",
                "stock": 150,
                "color": "Blue",
                "size": "S",
                "product_image_url": "https://www.mywebsite.com/product_images/n1234.png/",
                "custom": {
                    "season": "Winter",
                    "delivery_time": "In 5 days"
                }
            },
            "quantity": 2,
            "subtotal": 190.4
        },
        {
            "product": {
                "id": "M1234",
                "name": "Beauty cream",
                "taxonomy": [
                    "Skincare",
                    "Moisturizers",
                    "Day Creams"
                ],
                "currency": "USD",
                "unit_price": 90,
                "unit_sale_price": 87.5,
                "url": "https://www.mywebsite.com/en-us/beauty-cream/m1234/",
                "stock": 112,
                "color": "Clear",
                "size": "S",
                "product_image_url": "https://www.mywebsite.com/product_images/m1234.png/",
            },
            "quantity": 1,
            "subtotal": 87.5
        }
    ]
}

In addition to the properties defined in the table above, you can add custom properties to any object. Such properties should be added under the custom object, as in the example above.

Your title goes here
The key-value pairs under the custom object are attributed as custom event parameters to the Cart Page View event.
Your title goes here
The value type of any key under the custom object varies depending on the key. Make sure to add the values in the data type that best fits.

How can I monitor if it works correctly?

Once you deploy your integration, you can test it via the Website Integration Wizard. This wizard helps you complete your integration and test it afterwards. If you have already implemented the integration, you can use the wizard only to test it.