[Beta] Clean URLs for analytics

This commit is contained in:
Dan Abramov
2023-01-24 11:13:12 +00:00
parent af255ea9d6
commit 5b8126a115
2 changed files with 4 additions and 2 deletions

View File

@@ -8,8 +8,9 @@ import {ga} from '../../utils/analytics';
export function Feedback({onSubmit = () => {}}: {onSubmit?: () => void}) {
const {asPath} = useRouter();
const cleanedPath = asPath.split(/[\?\#]/)[0];
// Reset on route changes.
return <SendFeedback key={asPath} onSubmit={onSubmit} />;
return <SendFeedback key={cleanedPath} onSubmit={onSubmit} />;
}
const thumbsUpIcon = (

View File

@@ -42,7 +42,8 @@ export default function MyApp({Component, pageProps}: AppProps) {
useEffect(() => {
const handleRouteChange = (url: string) => {
ga('set', 'page', url);
const cleanedUrl = url.split(/[\?\#]/)[0];
ga('set', 'page', cleanedUrl);
ga('send', 'pageview');
};
router.events.on('routeChangeComplete', handleRouteChange);