Ecwid.OnPageLoad/Ecwid.OnPageLoaded

These events contain callbacks that get called on each page change inside the product browser.

The difference between OnPageLoad and OnPageLoaded is that the former is called when the page is changed (e.g. a link is clicked), while the latter is called later when the corresponding page is loaded inside the product browser.

The callback functions accept one parameter of type Page specifying which page is to be loaded (or has already been loaded). See Page Object details for more info.

If user visits cart page, do something:

Ecwid.OnPageLoaded.add(function(page) {
    if (page.type == "CART") {
      // do something ...
  }
});

📘

If you need more information about a product or category, use REST API. Public access token can be used in the client-side code, and private token on the server-side.

Page object

Describes the page displaying inside the product browser.

Get page type after new page is loaded:

Ecwid.OnPageLoaded.add(function(page){
  console.log("Current page is of type: " + page.type);
});

// prints
// Current page is of type: CATEGORY

Fields:

NameTypeDescription
namestringFor types: CATEGORY, PRODUCT. Name of the opened category or product
nameTranslatedobject <Translations>Translated name of the opened category or product according to current browser language
typestring, one of the following: ACCOUNT_SETTINGS, ADDRESS_BOOK, ORDERS, RESET_PASSWORD, CATEGORY, CART, CHECKOUT_ADDRESS_BOOK, CHECKOUT_PAYMENT_DETAILS, CHECKOUT_PLACE_ORDER, CHECKOUT_ADDRESS, CHECKOUT_DELIVERY, ORDER_CONFIRMATION, ORDER_FAILURE, CHECKOUT_RESULT, DOWNLOAD_ERROR, PRODUCT, SEARCH, FAVORITES, RESET_PASSWORD, SIGN_IN, ACCOUNT_SUBSCRIPTIONThe type of the page. Some pages may have parameters, like: productId of the viewing product. Those parameters are described below.
keywordsstring, optionalfor type==’ORDERS’: the keywords that are used to find orders in the customer account page. for type==’SEARCH’: the keywords that are used to find products on the product search page.
frominteger timestamp, optionalfor type==’ORDERS’: The timestamp of the start of the orders date range.
tointeger timestamp, optionalfor type==’ORDERS’: The timestamp of the end of the orders date range.
offsetfor type==’ORDERS’: the position of the current order list page (starting from 0). for type==’CATEGORY’ and SEARCH’: the position of the current product list page (starting from 0).
categoryIdintegerfor type==’CATEGORY’: the id of the showing product category or 0 if this is the starting page of the catalog and no categories are selected yet. for type==’PRODUCT’: the category internal id the current product has been navigated from. Zero (0) is the root category, −1 meaning that the category is unknown (e.g. a product opened from a search result).
mainCategoryIdintegerfor type==’PRODUCT’ in the OnPageLoaded event: the internal id of category that is considered the default category of this product (in case if the product is assigned to a few different categories). If a product is assigned to a single category, mainCategoryId will be equeal to categoryId; if a product is not assigned to any category, its mainCategoryId is 0 (zero). for type==’PRODUCT’ in the OnPageLoad event: always 0 (zero);
sortstring, one of: ‘normal’, ‘addedTimeDesc’, ‘priceAsc’, ‘priceDesc’, ‘nameAsc’, ‘nameDesc’for type==’CATEGORY’ and ’SEARCH’: the order of the product list, as selected by the user in the ‘sort by’ drop-down. ‘Desc’ suffix stands for the descending order, ‘Asc’ suffix stands for the ascending order.
orderIdintegerfor type==’CHECKOUT_RESULT’ and type==’ORDER_CONFIRMATION’: the internal id of the order (not to be confused with the store order number)
ticketintegerfor type==’CHECKOUT_RESULT’: the security random code that allows to retrieve information about the order
errorTypeone of the following: ‘expired’, ‘invalid’, ‘limit’for type==’DOWNLOAD_ERROR’: the type of the error while downloading an e-good file.
keyinteger, optionalfor type==’DOWNLOAD_ERROR’: the downloading file internal id
productIdintegerfor type==’PRODUCT’: the internal id of the displaying product (not to be confused with SKU).
orderNumberintegerfor type==’ORDER_CONFIRMATION’ the number of the order placed by customer(without prefix and suffix).
vendorOrderNumberstringfor type==’CHECKOUT_RESULT’ and type==’ORDER_CONFIRMATION’ the number of the order placed by customer(with prefix and suffix)
hasPreviousbooleantrue if customer visited some previous pages earlier and current page is not the entry page. false if current page is the first page of entry
variationIdnumberVariation ID if specified in the URL. Learn more
filterParams<FilterParameters>Filter parameters used in product search request. For "CATEGORY" and "SEARCH" pages only
priceFromnumberfor type==’SEARCH’: lower bound of the price range filter
priceTonumberfor type==’SEARCH’: upper bound of the price range filter

FilterParameters

NameTypeDescription
attributes<SelectedAttributes>Information about selected attributes and their values
categoriesArray of stringList of category IDs where customer searches in
includeProductsFromSubcategoriesbooleantrue if the search needs to include products from subcategories. false otherwise
keywordstringThe keyword customer used when searching for products
options<SelectedOptions>Information about selected options and their values
includeProductsFromSubcategoriesbooleanTrue if the result's products are in a subcategory
inventorystringOnly "instock" value. Present if the "Availability" is set to "In stock"
priceFromnumberThe lower bound of the price range filter
priceTonumberThe upper bound of the price range filter

SelectedAttributes

NameTypeDescription
ATTRIBUTE_NAMEstringAttribute name is the field name and array of attribute value(s) is the value of this field

SelectedOptions

NameTypeDescription
OPTION_NAMEstringOption name is the field name and array of option value(s) is the value of this field

Translations

FieldTypeDescription
<ISO_LANG_CODE>stringTranslations for each available language. Empty if no translations are provided. See available languages in store language settings