2424use Magento \Framework \Event \ObserverInterface ;
2525
2626/**
27- * Observer for `controller_action_layout_render_before_catalogsearch_result_index '
27+ * Observer for `catalog_product_collection_load_after '
2828 *
2929 * @see http://developer.matomo.org/guides/tracking-javascript-guide#internal-search-tracking
3030 */
@@ -59,6 +59,11 @@ class SearchResultObserver implements ObserverInterface
5959 */
6060 protected $ _view ;
6161
62+ /**
63+ * @var \Magento\Framework\App\Request\Http $request
64+ */
65+ private $ request ;
66+
6267 /**
6368 * Constructor
6469 *
@@ -71,12 +76,14 @@ public function __construct(
7176 \Chessio \Matomo \Model \Tracker $ matomoTracker ,
7277 \Chessio \Matomo \Helper \Data $ dataHelper ,
7378 \Magento \Search \Model \QueryFactory $ queryFactory ,
74- \Magento \Framework \App \ViewInterface $ view
79+ \Magento \Framework \App \ViewInterface $ view ,
80+ \Magento \Framework \App \Request \Http $ request
7581 ) {
7682 $ this ->_matomoTracker = $ matomoTracker ;
7783 $ this ->_dataHelper = $ dataHelper ;
7884 $ this ->_queryFactory = $ queryFactory ;
7985 $ this ->_view = $ view ;
86+ $ this ->request = $ request ;
8087 }
8188
8289 /**
@@ -88,6 +95,11 @@ public function __construct(
8895 */
8996 public function execute (\Magento \Framework \Event \Observer $ observer )
9097 {
98+ // Skip executes in case the current page isn't the search result page
99+ if ($ this ->request ->getFullActionName () !== 'catalogsearch_result_index ' ) {
100+ return $ this ;
101+ }
102+
91103 if (!$ this ->_dataHelper ->isTrackingEnabled ()) {
92104 return $ this ;
93105 }
0 commit comments