Highlighted

How to split values to variables from URL query string param, which itself is a delimited string?

Silver Contributor
Silver Contributor

Hi folks - I can't seem to find an answer to this issue, which I'd probably normally try to write a bit of script to handle:

 

I have an affiliate network partnered with an agency sending us URLs to our landing pages like so:

 

subs.domain.com/index.php?cid1=a/b/c/[AFFILIATEID]/d/e/f/g/[PARTNERID]/h/i

 

I know how to grab the cid1 value, but how can I split the value by the forward slashes in order to grab the AFFILIATEID and PARTNERID values?

3 REPLIES 3
Highlighted

How to split values to variables from URL query string param, which itself is a delimited string?

Employee Emeritus

@redfuel318

You can solve this with some JavaScript, Data Sources and Mappings.  Your use case is similar to the Tealium Pathname Tokenizer, however your data is within a querystirng parameter and not within the URL pathname.  Here is one way to solve your use case.

 

1) Add some data sources to your TiQ Data Layer:

"_cid1_0","UDO Variable","Token 0 from querystring parameter cid",""
"_cid1_1","UDO Variable","Token 1 from querystring parameter cid",""
"_cid1_2","UDO Variable","Token 2 from querystring parameter cid",""
"_cid1_3","UDO Variable","Token 3 from querystring parameter cid",""
"_cid1_4","UDO Variable","Token 4 from querystring parameter cid",""
"_cid1_5","UDO Variable","Token 5 from querystring parameter cid",""
"_cid1_6","UDO Variable","Token 6 from querystring parameter cid",""
"_cid1_7","UDO Variable","Token 7 from querystring parameter cid",""
"_cid1_8","UDO Variable","Token 8 from querystring parameter cid",""
"_cid1_9","UDO Variable","Token 9 from querystring parameter cid",""
"_cid1_10","UDO Variable","Token 10 from querystring parameter cid",""

tmp-token1-20151221T120014.png

 

2) Map the Token(s) to your tag.  In this example I am mapping to Google Analytics, but you could use any tag vendor in the marketplace.

tmp-token2-20151221T120014.png

 

3) Add the extension to do the Tokenize Magic

if(typeof b['qp.cid1'] !== 'undefined'){
  var d = b['qp.cid1'].split('/');
  for (var c = 0; c < d.length; c++) {
    b['_cid1_' + c] = (typeof d[c] != 'undefined') ? d[c] : '';
  }
}

tmp-token5-20151221T120014.png

 

4) Test.  To test we can look at the Data Layer in the console and we can also look at the outbound data for Google Analytics.

tmp-token4-20151221T120014.png

 

 

This is just one way to solve your use case.  Let us know how this works out for you.

 

Happy Tagging!
Brian

Highlighted

How to split values to variables from URL query string param, which itself is a delimited string?

Silver Contributor
Silver Contributor

Highly delayed, but working on this implementation now. Will update on success of solution.

Highlighted

How to split values to variables from URL query string param, which itself is a delimited string?

Employee Emeritus

No worries @redfuel318! We look forward to hearing how it turned out. Keep us posted. 

Remember to give me a kudo if you like my post! Accepting my post as a solution is even better! Also remember that search is your friend.