removing slashes from pathname

Gold Contributor
Gold Contributor

I want to use pathname in another variable, but first I need to remove the leading and trailing slashes.  How can I do this?

3 REPLIES 3

removing slashes from pathname

Employee Emeritus

Hi @jeremy_myers

 

Are you wanting to remove the slashes from the entire pathname? e.g. /localhost/example/author/admin/

 

Or do you want to remove the leading and trailing slashes of each pathname section? e.g. /example/

 

If it is the ladder, are you already using the pathname tokenizer extension?

 

Thanks

removing slashes from pathname

Gold Contributor
Gold Contributor

I'm trying to just remove the leading and trailing slashes.  I haven't implemented the pathname tokenizer because I thought this would rip apart the whole pathname into separate pieces.  Is that not the case?

removing slashes from pathname

Employee Emeritus

@jeremy_myers,

 

Yes, that's right. The pathname tokenizer splits up the pathname into sections and stores each section in varialbes. 

 

If you would just like to remove the leading and trailing slashes of the utag.data['dom.pathname'], you can add a Set Data Values extension in TiQ to set the new pathname variable to the following:

 

b['dom.pathname'].replace(/^\/|\/$/g, '');

Here is a full example:

 

 

Screen Shot 2016-03-16 at 11.17.25 AM.png

I do not know the details of your use case so if you have any issues with this implementation, let me know the details.

 

Thanks!

 

Public