diff --git a/Observer/SearchResultObserver.php b/Observer/SearchResultObserver.php
index 8e0b28f..9cb73e9 100644
--- a/Observer/SearchResultObserver.php
+++ b/Observer/SearchResultObserver.php
@@ -24,7 +24,7 @@
use Magento\Framework\Event\ObserverInterface;
/**
- * Observer for `controller_action_layout_render_before_catalogsearch_result_index'
+ * Observer for `catalog_product_collection_load_after'
*
* @see http://developer.matomo.org/guides/tracking-javascript-guide#internal-search-tracking
*/
@@ -59,6 +59,11 @@ class SearchResultObserver implements ObserverInterface
*/
protected $_view;
+ /**
+ * @var \Magento\Framework\App\Request\Http $request
+ */
+ private $request;
+
/**
* Constructor
*
@@ -71,12 +76,14 @@ public function __construct(
\Chessio\Matomo\Model\Tracker $matomoTracker,
\Chessio\Matomo\Helper\Data $dataHelper,
\Magento\Search\Model\QueryFactory $queryFactory,
- \Magento\Framework\App\ViewInterface $view
+ \Magento\Framework\App\ViewInterface $view,
+ \Magento\Framework\App\Request\Http $request
) {
$this->_matomoTracker = $matomoTracker;
$this->_dataHelper = $dataHelper;
$this->_queryFactory = $queryFactory;
$this->_view = $view;
+ $this->request = $request;
}
/**
@@ -88,6 +95,11 @@ public function __construct(
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
+ // Skip executes in case the current page isn't the search result page
+ if ($this->request->getFullActionName() !== 'catalogsearch_result_index') {
+ return $this;
+ }
+
if (!$this->_dataHelper->isTrackingEnabled()) {
return $this;
}
diff --git a/etc/frontend/events.xml b/etc/frontend/events.xml
index 3efc1ee..9fa455b 100644
--- a/etc/frontend/events.xml
+++ b/etc/frontend/events.xml
@@ -46,7 +46,7 @@
-
+