mirror of
https://github.com/tlsnotary/tlsn-plugin-demo.git
synced 2026-01-09 21:37:55 -05:00
35 lines
931 B
TypeScript
35 lines
931 B
TypeScript
import { useEffect } from 'react';
|
|
import { useLocation } from 'react-router-dom';
|
|
|
|
declare global {
|
|
interface Window {
|
|
_paq?: any[];
|
|
}
|
|
}
|
|
|
|
const MatomoTracking = () => {
|
|
const location = useLocation();
|
|
|
|
useEffect(() => {
|
|
if (typeof window !== 'undefined') {
|
|
const _paq = (window._paq = window._paq || []);
|
|
_paq.push(['setTrackerUrl', 'https://psedev.matomo.cloud/matomo.php']);
|
|
_paq.push(['setSiteId', '16']);
|
|
const script = document.createElement('script');
|
|
script.async = true;
|
|
script.src = 'https://cdn.matomo.cloud/psedev.matomo.cloud/matomo.js';
|
|
document.head.appendChild(script);
|
|
}
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (typeof window !== 'undefined' && window._paq) {
|
|
window._paq.push(['setCustomUrl', window.location.pathname]);
|
|
window._paq.push(['trackPageView']);
|
|
}
|
|
}, [location.pathname]);
|
|
return null;
|
|
};
|
|
|
|
export default MatomoTracking;
|