Trim a value from url

Silver Contributor
Silver Contributor

Hi,
I have a url like this https://example.com/xxxx/xxxxx/product/12345. I want to extract only 12345 from the url and assign it to other variable. How do i acheive this in Tealium iQ?

 

 

1 REPLY 1

Trim a value from url

Gold Contributor
Gold Contributor

Hi Mageshsm

If the url structure there is always consistent.  You could add the Tealium Extension, Pathname Tokenizer

2021-08-12_14-58-16.png

This would then create 4 utag_data variables on these pages with the value you are looking for in 

utag_data._pathname4

If you have a extension that is a library of functions, you could add a function.  There are many ways this could be done, just depends on how tight the logic needs to be as well as the circumstances on when/where you call it. 

Simple example:

lookForProductID = function() {
    var str = window.location.pathname.split('/');   
    if (str[str.length - 2] === 'product') {
        return str[str.length - 1];
    }
}

prodID = lookForProductID();

Cheers

Kevin

Kevin Allen SAS-DCX-UXD
User Experience & Data Analytics
DevOps Engineer III
kevin.allen@swisscom.com
Swisscom (Schweiz) AG
www.swisscom.ch
Public