Adobe Commerce only. Learn more.

Storefront Events SDK

This package serves as the foundation for eventing on an Adobe Commerce storefront. It provides access to a common data layer, and an event publishing and subscription service. Handling these events is up to you, but we provide the Storefront Event Collector package that can listen for events and send them to Adobe Commerce for processing.

Installation

This SDK can be used as a hosted script, or bundled in a JavaScript application. The script version is hosted on unpkg, and the bundled version is hosted on npm.

To load the SDK as a script, use the following snippet.

1
<script src="https://unpkg.com/@adobe/magento-storefront-events-sdk/dist/index.js"></script>

To install the script as a dependency, run this command.

1
npm install @adobe/magento-storefront-events-sdk

Quick Start

Once imported, you have access to the four main functions of the Events SDK.

The following code example shows how to get started.

Relevant context data must be populated before publishing events that require it.

1
2
3
4
5
6
7
8
9
10
11
12
13
import mse from "@adobe/magento-storefront-events-sdk";

// subscribe to events
mse.subscribe.pageView(pageViewHandler);

// set context data
mse.context.setPage(/* page context */);

// publish events
mse.publish.pageView();

// unsubscribe from events
mse.unsubscribe.pageView(pageViewHandler);

Support

If you have any questions or encounter any issues, reach out here: