Skip to content

Instantly share code, notes, and snippets.

@leadbi
Last active February 15, 2018 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leadbi/39fcf8b13957fb892bae17d20598f95f to your computer and use it in GitHub Desktop.
Save leadbi/39fcf8b13957fb892bae17d20598f95f to your computer and use it in GitHub Desktop.
Remove UTM params from query
(function () {
// remove url param
function removeUrlParam(url, paramName) {
var pattern = new RegExp('\\b(' + paramName + '=).*?(&|$)');
if (url.search(pattern) >= 0) {
return url.replace(pattern, '');
}
return url;
}
var replaceList = [
'utm_email',
'utm_referrer',
'utm_domain',
'utm_company',
'utm_fullname',
'utm_firstname',
'utm_lastname',
'utm_channel',
];
var url = window.location.href;
for (var index = 0; index < replaceList.length; index++) {
url = removeUrlParam(url, replaceList[index]);
}
var url_parts = url.split('?');
url = url_parts[1] ? url : url_parts[0];
// check if the push history exists
window.history.pushState && window.history.pushState(null, null, url);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment