Skip to content

Commit 8165cd5

Browse files
committed
Matomo plugin: Add configuration switch
To activate the Matomo plugin, add `matomoSearchAnalytics: true` to the properties in the call to the docsearch function. Per default, the plugin is deactivated.
1 parent e0d2991 commit 8165cd5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/docsearch-react/src/DocSearch.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface DocSearchProps {
4343
navigator?: AutocompleteOptions<InternalDocSearchHit>['navigator'];
4444
translations?: DocSearchTranslations;
4545
getMissingResultsUrl?: ({ query }: { query: string }) => string;
46+
matomoSearchAnalytics?: boolean;
4647
}
4748

4849
export function DocSearch(props: DocSearchProps) {

packages/docsearch-react/src/DocSearchModal.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export function DocSearchModal({
5252
initialQuery: initialQueryFromProp = '',
5353
translations = {},
5454
getMissingResultsUrl,
55+
matomoSearchAnalytics = false,
5556
}: DocSearchModalProps) {
5657
const {
5758
footer: footerTranslations,
@@ -127,7 +128,12 @@ export function DocSearchModal({
127128
[favoriteSearches, recentSearches, disableUserPersonalization]
128129
);
129130

130-
const matomoPlugin = createMatomoPlugin();
131+
var plugins_to_load: any = [];
132+
133+
if (matomoSearchAnalytics) {
134+
const matomoPlugin = createMatomoPlugin();
135+
plugins_to_load.push(matomoPlugin);
136+
};
131137

132138
const autocomplete = React.useMemo(
133139
() =>
@@ -286,7 +292,7 @@ export function DocSearchModal({
286292
);
287293
});
288294
},
289-
plugins: [matomoPlugin],
295+
plugins: plugins_to_load,
290296
}),
291297
[
292298
typesenseCollectionName,

0 commit comments

Comments
 (0)