Last active
February 15, 2018 13:50
-
-
Save leadbi/39fcf8b13957fb892bae17d20598f95f to your computer and use it in GitHub Desktop.
Remove UTM params from query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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