I would use multiple "replace" functions:
var url = window.location.href;
// removes the https://www. and .com in the url
url = url.replace("https://www.", "").replace(".com","");
// replaces all / with :, and removes the last instance of : at the end of the string
var pageName = url.replace(/\//g, ":").replace(/:$/g, "");
return pageName;
Other people may debate about using Regex Replace, but the it's still better than looping through the entire string and replacing each instance....