Edit in GitHubLog an issue

Subscribing to events

Third-party modules can subscribe to events, allowing you to use other analytics collection schemes.

The venia-sample-eventing module shows how to subscribe to events.

Within main.js, the subscription code is:

Copied to your clipboard
const [observable, { dispatch }] = useEventingContext();
useEffect(() => {
const sub = observable.subscribe(async event => {
switch (event.type) {
case 'CART_PAGE_VIEW':
console.log('Logging event:', {
type: event.type,
...event.payload,
products: formatCartProducts(event.payload.products)
});
break;
case 'CHECKOUT_PAGE_VIEW':
console.log('Logging event:', {
type: event.type,
...event.payload,
products: formatCartProducts(event.payload.products)
});
break;
case 'ORDER_CONFIRMATION_PAGE_VIEW':
console.log('Logging event:', {
type: event.type,
...event.payload,
products: formatCartProducts(event.payload.products)
});
break;
default:
console.log('Logging event:', event);
break;
}
});
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.