-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathMatomoPlugin.tsx
More file actions
27 lines (22 loc) · 693 Bytes
/
MatomoPlugin.tsx
File metadata and controls
27 lines (22 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import debounce from 'lodash/debounce';
declare global {
interface Window {
_paq: any;
}
}
var query_cache = "";
function _matomoSiteSearch(query: string, hits: string) {
query_cache = query;
var _paq = window._paq = window._paq || [];
_paq.push(['trackSiteSearch', query, false, hits]);
}
var matomoSiteSearch_debounced = debounce(_matomoSiteSearch, 500);
export function createMatomoPlugin() {
return {
onStateChange({ state }) {
if ( state.isOpen && state.query.length > 2 && query_cache !== state.query ) {
matomoSiteSearch_debounced(state.query, state.context.nbHits);
}
},
};
};