Magento2 Event Observer – How to Call Pre Dispatch Event on All Front Pages

frontendmagento2

How to call pre dispatch event before all the front-side pages and it's action.

Let's say Before front side index page or product detail page is load. i want a event before all the front-end action.

Even before Index page load.

How to achieve that ?

Note :

I want to call my dispatch event before all the front end actions, whenever any front action calls – it should call my dispatch event first.

Eg- Before Index page, CMS pages, every single front-end pages.

Best Answer

You have to use this for all page on front end.

<event name="controller_action_predispatch">
        <observer name="<observername>" instance="<observerpath>" />
</event>

You can see in this file :

vendor/magento/module-persistent/etc/frontend/events.xml

It's same which you asked. It's call every time to checked customer session.

Related Topic