Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { FilesProvider } from './contexts/Files';
import DownloadView from './views/DownloadView';
import HomeView from './views/HomeView';
import NotFoundView from './views/NotFoundView';
import { useEffect } from 'react';
import { cleanUrlParam } from './utils/cleanUrl';

function DownloadRedirectWrapper() {
const { sendId } = useParams();
Expand All @@ -15,6 +17,10 @@ function DownloadRedirectWrapper() {
}

function App() {
useEffect(() => {
cleanUrlParam();
}, []);

return (
<>
<BrowserRouter>
Expand Down
26 changes: 26 additions & 0 deletions src/utils/cleanUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Remove Google Analytics/Tag Manager tracking query parameters
* to keep the URL looking clean for the users after page has loaded
*/

export function cleanUrlParam() {
const url = new URL(window.location.href);
let hadChanges = false;

const currentKeys = Array.from(url.searchParams.keys());

currentKeys.forEach((param) => {
if (param === '_gl' || param === '_gcl_au' || param === '_fplc' || param.startsWith('_ga')) {
url.searchParams.delete(param);
hadChanges = true;
}
});

if (hadChanges) {
const newUrl = url.searchParams.toString()
? `${url.pathname}?${url.searchParams.toString()}${url.hash}`
: `${url.pathname}${url.hash}`;

window.history.replaceState({}, document.title, newUrl);
}
}
Loading