Search code examples
spartacus-storefront

Custom Event on CDS (Context Driven Services) on Spartacus Storefront


I set the CDS on Spartacus, following the guide on the official Spartacus documentation. But I could not figure out how to set a “View Product Page” event that is triggered when a product is viewed. Any one knows the right way to configure it on Spartacus ?


Solution

  • I am not familiar with CDS, but as far as I know, you can subscribe and react to ProductDetailsPageEvent using Spartacus event service.

    Kindly refer to below source code written in your app.module.js:

    export class AppModule {
      constructor(events: EventService) {
    
        const event$ = events.get(ProductDetailsPageEvent);
        event$.subscribe((event) => console.log('ProductDetailsPageEvent is fired: '
           + event));
      }
    }
    

    details could be found in Spartacus document:

    https://sap.github.io/spartacus-docs/event-service/#page-title

    Best Regards, Jerry