Skip to content

Commit

Permalink
Revert "feat: track searches in matomo"
Browse files Browse the repository at this point in the history
This reverts commit 543d0d1.
  • Loading branch information
tiberiuichim authored Jul 19, 2023
1 parent 543d0d1 commit 3480480
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions src/MatomoAppExtra.jsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,16 @@
import React from 'react';
import { flattenToAppURL, getBaseUrl } from '@plone/volto/helpers';
import { trackPageView, trackSiteSearch } from './utils';
import { useSelector } from 'react-redux';
import { trackPageView } from './utils';

export const MatomoAppExtra = ({ location, content }) => {
const title = content?.title;
const pathname = location.pathname.replace(/\/$/, '');
const query = location?.search ?? '';

const href = flattenToAppURL(content?.['@id'] || '');
const { search, query, pathname } = useSelector(
(state) => state.router.location,
);
const baseUrl = getBaseUrl(pathname) || '';

const extractSearchableText = (query) => {
// Handle catalog-querystring-like queries, which are
// send in a JSON object
if (query?.query) {
let parsed = JSON.parse(unescape(query.query));
let items = parsed.filter((item) => item.i === 'SearchableText');
if (items.length === 1) {
return items[0].v;
}
}

// check if there is an explicit SearchableText parameter
// in the querystring
if (query?.SearchableText) {
return query.SearchableText;
}

return '';
};
React.useEffect(() => {
const searchableText = extractSearchableText(query);
if (href === pathname) {
// a document (content)
trackPageView({ href: href + query, documentTitle: title });
Expand All @@ -44,10 +20,7 @@ export const MatomoAppExtra = ({ location, content }) => {
const action = pathname.split('/')[pathname.split('/').length - 1];
trackPageView({ href: pathname + query, documentTitle: action });
}
if (searchableText) {
trackSiteSearch({ keyword: searchableText });
}
}, [href, pathname, title, baseUrl, search, query]);
}, [href, pathname, title, baseUrl, query]);

return <React.Fragment />;
};
Expand Down

0 comments on commit 3480480

Please sign in to comment.