Hi,
I am capturing the url as pageName and reading the pageName from the url
.Current url is https://www.xyz.com/abc/def/
Expected pageName = xyz:abc:def
What data element custom code should I write to get to the expected pageName? I want to replace forward slashes with colon. I am already using "window. location.href"
Solved! Go to Solution.
Views
Replies
Total Likes
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....
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....
Thank you!! Very helpful