Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

value from the url

Avatar

Level 3

Hi,

I am capturing the value of the pageName from URLs and separating it by ":"

 

.Current url is https://www.xyz.jp/abc/def/

 

Expected pageName = xyz:jp:abc:def

 

How can I go about getting the above format value?

0 Replies

Avatar

Community Advisor

This sounds a lot like your previous question: https://experienceleaguecommunities.adobe.com/t5/adobe-analytics-questions/replace-forward-slash-wit...

 

Are you still having issues with this?

 

 

Edit: The only difference is really that in this case you aren't removing the ".com" or ".jp" from the URL...  in the original code there is a specific "replace" that replaces the ".com" with "" to remove it from the string... in this case you want to keep ".jp".... the original code will do this.. it only replaces the .com unless you explicitly add additional replaces for each domain variant... 

Your original:

Current url is https://www.xyz.com/abc/def/

Expected pageName = xyz:abc:def

 

AND the new:

Current url is https://www.xyz.jp/abc/def/

Expected pageName = xyz:jp:abc:def

 

will work with the code that was provided for both scenarios

 

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;

 

 

IF you wanted to also remove .jp from the equation:

var url = window.location.href;

// removes the https://www. and .com in the url 
url = url.replace("https://www.", "").replace(".com","").replace(".jp","");

// replaces all / with :, and removes the last instance of : at the end of the string
var pageName = url.replace(/\//g, ":").replace(/:$/g, ""); 

return pageName;