Skip to content

Commit fc9079f

Browse files
authored
Merge pull request #77 from cryptomator/feature/drop-utm-params
Remove utm params from address bar at load
2 parents 864461f + cfa83c4 commit fc9079f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

source/_static/js/remove-utm.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function removeUTMParams() {
2+
const url = new URL(window.location.href);
3+
const params = url.searchParams;
4+
const utmParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'];
5+
let modified = false;
6+
utmParams.forEach(param => {
7+
if (params.has(param)) {
8+
params.delete(param);
9+
modified = true;
10+
}
11+
});
12+
if (modified) {
13+
const newQuery = params.toString() ? '?' + params.toString() : '';
14+
const newUrl = url.pathname + newQuery + url.hash;
15+
window.history.replaceState({}, document.title, newUrl);
16+
}
17+
}
18+
if ('requestIdleCallback' in window) {
19+
requestIdleCallback(removeUTMParams);
20+
} else {
21+
// Fallback if not supported
22+
window.addEventListener('load', () => {
23+
removeUTMParams();
24+
});
25+
}

source/_templates/layout.html

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
{%- block extrahead %}
44
<script defer data-domain="docs.cryptomator.org" src="https://plausible.skymatic.de/js/script.file-downloads.outbound-links.js" integrity="sha384-+tt0STxxWB96REUfXF1ykJzPEC5cT+TVotVR/JnYqAP04zxND4o8a0JcHg+aq46t" crossorigin="anonymous"></script>
55
<script src="https://umami.skymatic.de/script.js" data-website-id="2df416f9-7a9c-4e58-9a45-7106f7e0a139" integrity="sha384-/WQteTtaLX4nU22mvCeTi4Yz3iK/J3yZ2rKq5jDxPMlizEQGzgJOlSofJxh+bx4B" crossorigin="anonymous" defer></script>
6+
<script src="../../_static/js/remove-utm.js" integrity="sha384-/GnxN3ANEPnKJ3hynuMg+gv/GYWn0RiaxFN+2i1RrxUqwCcThs/GCsMaP6aKlHxH" defer></script>
67
{% endblock %}
78

0 commit comments

Comments
 (0)