Context for storefront events
The Storefront Events SDK uses context objects to provide details about your storefront and shopper interactions. Use the functions on this page to read and update those values.
Storefront instance context requirements
The fields needed to scope storefront events depend on your Adobe Commerce setup. Include the scope fields for your platform in the StorefrontInstance context before you publish events. A field being optional in the shared SDK type does not mean you can omit it for every platform.
websiteCode, storeCode, and storeViewCodeviewId and localeviewId and locale for Adobe Commerce Optimizer catalog scoping; Adobe scope codes where needed for PaaS transaction routingstoreViewCode and viewId as interchangeablePaaS / Adobe Commerce as a Cloud Service (SaaS)
For Adobe Commerce on cloud infrastructure (PaaS) and Adobe Commerce as a Cloud Service (SaaS) storefronts, provide the Adobe scope codes, including storeViewCode. This field identifies the store view used to scope the event. Do not rely on storeViewId alone as a substitute for storeViewCode.
const storefrontCtx = {
// Include the other required StorefrontInstance fields for your setup.
websiteCode: 'website',
storeCode: 'store',
storeViewCode: 'default'
};
mse.context.setStorefrontInstance(storefrontCtx);
Adobe Commerce Optimizer
For Adobe Commerce Optimizer storefront events, include viewId and locale in the storefront context. Use the catalog view ID for viewId. Do not use storeViewCode in its place.
const storefrontCtx = {
// Include the other required StorefrontInstance fields for your setup.
viewId: '12345678-1234-1234-1234-123456789abc',
locale: 'en-US'
};
mse.context.setStorefrontInstance(storefrontCtx);
If a scope field is missing
A missing scope field might not produce a clear error when an event is published, and the event data might not be scoped as you expect.
For PaaS and Adobe Commerce as a Cloud Service (SaaS), a missing storeViewCode can prevent the event from appearing in catalog aggregations. For Adobe Commerce Optimizer, a missing viewId can cause events to be scoped incorrectly.
data-variant=important
data-slots=text
Verify the context
Before you rely on event data, inspect a published event's StorefrontInstance context and confirm that it contains the scope fields required for your storefront setup:
- PaaS / Adobe Commerce as a Cloud Service (SaaS):
websiteCode,storeCode, andstoreViewCode - Adobe Commerce Optimizer:
viewIdandlocale - Adobe Commerce Optimizer + PaaS: Confirm that the appropriate fields are present for the event's catalog or transaction path
The shared StorefrontInstance type can mark platform-specific fields as optional because it supports multiple storefront setups. Follow the platform-specific requirements in this section when you implement the context.
Functions
The following functions get and set context data.
mse.context.getCategory
Gets the Category context.
Syntax:
mse.context.getCategory();
mse.context.getCustomUrl
Gets the CustomUrl context.
Syntax:
mse.context.getCustomUrl();
mse.context.getMagentoExtension
Gets the MagentoExtension context.
Syntax:
mse.context.getMagentoExtension();
mse.context.getOrder
Gets the Order context.
Syntax:
mse.context.getOrder();
mse.context.getPage
Gets the Page context.
Syntax:
mse.context.getPage();
mse.context.getProduct
Gets the Product context.
Syntax:
mse.context.getProduct();
mse.context.getRecommendations
Gets the Recommendations context.
Syntax:
mse.context.getRecommendations();
mse.context.getReferrerUrl
Gets the ReferrerUrl context.
Syntax:
mse.context.getReferrerUrl();
mse.context.getSearchInput
Gets the SearchInput context.
Syntax:
mse.context.getSearchInput();
mse.context.getSearchResults
Gets the SearchResults context.
Syntax:
mse.context.getSearchResults();
mse.context.getShopper
Gets the Shopper context.
Syntax:
mse.context.getShopper();
mse.context.getShoppingCart
Gets the ShoppingCart context.
Syntax:
mse.context.getShoppingCart();
mse.context.getStorefrontInstance
Gets the StorefrontInstance context.
Syntax:
mse.context.getStorefrontInstance();
mse.context.getContext
Gets a custom Context.
nameContext nameSyntax:
mse.context.getContext(name);
mse.context.setCategory
Sets the Category context.
contextCategory contextSyntax:
mse.context.setCategory(categoryCtx);
mse.context.setCustomUrl
Sets the CustomUrl context.
contextCustomUrl contextSyntax:
mse.context.setCustomUrl(customUrlCtx);
mse.context.setMagentoExtension
Sets the MagentoExtension context.
contextMagentoExtension contextSyntax:
mse.context.setMagentoExtension(magentoExtensionCtx);
mse.context.setOrder
Sets the Order context.
contextOrder contextSyntax:
mse.context.setOrder(orderCtx);
mse.context.setPage
Sets the Page context.
contextPage contextSyntax:
mse.context.setPage(pageCtx);
mse.context.setProduct
Sets the Product context.
contextProduct contextSyntax:
mse.context.setProduct(productCtx);
mse.context.setRecommendations
Sets the Recommendations context.
contextRecommendations contextSyntax:
mse.context.setRecommendations(recommendationsCtx);
mse.context.setReferrerUrl
Sets the ReferrerUrl context.
contextReferrerUrl contextSyntax:
mse.context.setReferrerUrl(referrerUrlCtx);
mse.context.setSearchInput
Sets the SearchInput context.
contextSearchInput contextSyntax:
mse.context.setSearchInput(searchInputCtx);
mse.context.setSearchResults
Sets the SearchResults context.
contextSearchResults contextSyntax:
mse.context.setSearchResults(searchResultsCtx);
mse.context.setShopper
Sets the Shopper context.
contextShopper contextSyntax:
mse.context.setShopper(shopperCtx);
mse.context.setShoppingCart
Sets the ShoppingCart context.
contextShoppingCart contextSyntax:
mse.context.setShoppingCart(shoppingCartCtx);
mse.context.setStorefrontInstance
Sets the StorefrontInstance context.
contextStorefrontInstance contextSyntax:
mse.context.setStorefrontInstance(storefrontCtx);
mse.context.setContext
Sets a custom Context.
namenamecontextSyntax:
mse.context.setContext(ctx);