Expand my Community achievements bar.

SOLVED

Regular expressions (change URL name to name)

Avatar

Level 2

Hi All,

We have a POC of adobe catalyst analytics :)

We have implemented the tag manager Tealium, and we will proceed to implement the tag "Adobe SiteCatalyst"

We will not tagging pages manually with names (homepage, search, list...), but we would like to know if there is a possibility of using regualrs expressions to rename the URL full to name.

 

PAGE: www.coches.net change to to Homepage.

PAGE: www.coches.net/help change to Help.

PAGE: www.coches.net/contact change to contact.

...

 

 

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi Ivan,

you do not need to use RegEx. If your case is as simple as described you can go for the document.location object in the browser. 
 

document.location.pathname will contain what you need.
Your code should look something like this: 
 

var pageName = document.location.pathname; 
// Will replace pageName with homepage if pageName equals "/" or will remove the slashes 
// This will only work for the first level if you need deeper structures (like www.coches.net/help/customers) to work you should define how this shall look like in your report
pageName = pageName == "/" ? "Homepage" : pageName.split("/").join(""); 
// Will set the first character of pageName to uppercase
pageName = pageName.charAt(0).toUpperCase() + pageName.slice(1);

 

Just go to any website and paste this code to the Console and you will se this work for the first folder level. 
If you have something like www.domain.com/a/b you will get ab 

 

I hope this helps.

 

Best 
Simon

View solution in original post

5 Replies

Avatar

Correct answer by
Level 2

Hi Ivan,

you do not need to use RegEx. If your case is as simple as described you can go for the document.location object in the browser. 
 

document.location.pathname will contain what you need.
Your code should look something like this: 
 

var pageName = document.location.pathname; 
// Will replace pageName with homepage if pageName equals "/" or will remove the slashes 
// This will only work for the first level if you need deeper structures (like www.coches.net/help/customers) to work you should define how this shall look like in your report
pageName = pageName == "/" ? "Homepage" : pageName.split("/").join(""); 
// Will set the first character of pageName to uppercase
pageName = pageName.charAt(0).toUpperCase() + pageName.slice(1);

 

Just go to any website and paste this code to the Console and you will se this work for the first folder level. 
If you have something like www.domain.com/a/b you will get ab 

 

I hope this helps.

 

Best 
Simon

Avatar

Level 2

Hi Simon, thanks you!.

I can not always apply that nomenclature, we have a tagging plan standard, such as the listing: "http://www.coches.net/ocasion/?MakeId=0&ModelId=0&PrvId=0&Version=&BodyTypeId=0&FuelTypeId=0&MaxKms=..." in the tagging standard use pageName "list", and this no appear on the URL.

And the same detail (in our nomenclature we put on the "detail" tagging, but the url not appear: http://www.coches.net/mercedes-benz-clase-slk-slk-200-k-2p-gasolina-2010-en-valencia-31885499-covo.a....

Thanks you very much! your solutions is very interesting :)

Thanks!

Avatar

Level 2
Hi,
I've seen this option ( Page Name , attach capture) , i dont know if it could also its a solution.
Or should do in "admin / classification rule builder

Thanks!!!

Avatar

Level 2

Hi Ivan,

this depends.
How many pages are we talking about? 
What you can do in the screenshot you provided I would call monkey work;)

If you have really limited pages you can do so, but I would recommend the classification rule builder for this. 
Once you need to change the naming you will just have to change the rule and everything will be re-classified.

Now you have to decide if you want to do this by hand;)

 

Best

Simon 

Avatar

Level 2

The problem is in the list and detail page, have different URLs as much as in this case vehicles:

Pagename list, examples URLs. 

 

pagename: detail, example URLs.

 

For detail page maybe its more complicated.

I thinking you about it on the best solution ? I was using classification rule (attached screenshot) but your opinion is very important for me. :)

 

Thanks you very much!

For detail page maybe its more complicated.