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.
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
Once imported, you have access to the four main functions of the Events SDK.
- Context - Set context data
- Publish - Publish events
- Subscribe - Subscribe to events
- Unsubscribe - Unsubscribe from events
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);
If you have any questions or encounter any issues, reach out here: