-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use trackSiteSearch of matomo with search results count
- Loading branch information
Showing
4 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
window.PluginManager.register('MatomoAnalytics', () => import('./plugin/MatomoAnalyticsPlugin')); | ||
|
||
window.PluginManager.override('SearchWidget', () => import('./plugin/override/header/SearchWidgetPluginExtension'), '[data-search-widget]'); |
26 changes: 26 additions & 0 deletions
26
src/Resources/app/storefront/src/plugin/override/header/SearchWidgetPluginExtension.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import SearchWidgetPlugin from 'src/plugin/header/search-widget.plugin'; | ||
|
||
export default class SearchWidgetPluginExtension extends SearchWidgetPlugin { | ||
init() { | ||
super.init(); | ||
|
||
this.$emitter.subscribe('afterSuggest', event => { | ||
let term = null; | ||
let count = false; | ||
|
||
const dataField = document.getElementsByClassName('matomo-search-suggest-helper')[0]; | ||
if (dataField) { | ||
const value = JSON.parse(dataField.dataset['value']); | ||
term = value['term']; | ||
count = value['count']; | ||
} | ||
|
||
window._paq = window._paq || []; | ||
window._paq.push(['trackSiteSearch', | ||
term, | ||
'suggestSearch', | ||
count | ||
]); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/Resources/views/storefront/layout/header/search-suggest.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% sw_extends "@Storefront/storefront/layout/header/search-suggest.html.twig" %} | ||
|
||
{% block layout_search_suggest_result_total %} | ||
{{ parent() }} | ||
|
||
{% set matomoHelperData = { | ||
term: page.searchTerm, | ||
count: page.searchResult.total | ||
} %} | ||
<div class="matomo-search-suggest-helper" data-value="{{ matomoHelperData|json_encode }}"></div> | ||
{% endblock %} |