24
24
use Magento \Framework \Event \ObserverInterface ;
25
25
26
26
/**
27
- * Observer for `controller_action_layout_render_before_catalogsearch_result_index '
27
+ * Observer for `catalog_product_collection_load_after '
28
28
*
29
29
* @see http://developer.matomo.org/guides/tracking-javascript-guide#internal-search-tracking
30
30
*/
@@ -59,6 +59,11 @@ class SearchResultObserver implements ObserverInterface
59
59
*/
60
60
protected $ _view ;
61
61
62
+ /**
63
+ * @var \Magento\Framework\App\Request\Http $request
64
+ */
65
+ private $ request ;
66
+
62
67
/**
63
68
* Constructor
64
69
*
@@ -71,12 +76,14 @@ public function __construct(
71
76
\Chessio \Matomo \Model \Tracker $ matomoTracker ,
72
77
\Chessio \Matomo \Helper \Data $ dataHelper ,
73
78
\Magento \Search \Model \QueryFactory $ queryFactory ,
74
- \Magento \Framework \App \ViewInterface $ view
79
+ \Magento \Framework \App \ViewInterface $ view ,
80
+ \Magento \Framework \App \Request \Http $ request
75
81
) {
76
82
$ this ->_matomoTracker = $ matomoTracker ;
77
83
$ this ->_dataHelper = $ dataHelper ;
78
84
$ this ->_queryFactory = $ queryFactory ;
79
85
$ this ->_view = $ view ;
86
+ $ this ->request = $ request ;
80
87
}
81
88
82
89
/**
@@ -88,6 +95,11 @@ public function __construct(
88
95
*/
89
96
public function execute (\Magento \Framework \Event \Observer $ observer )
90
97
{
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
+
91
103
if (!$ this ->_dataHelper ->isTrackingEnabled ()) {
92
104
return $ this ;
93
105
}
0 commit comments