Highlighted

Capturing part of the URL and saving it as a Custom dimension in Universal Analytics

I want to save part of the URL as a custom dimension in universal analytics. All of the URLs ending with 2014 but I want the text before that saved in to the dimension. Ex: URLs ending like below (full url : http://www.open.edu.au/courses/it/swinburne-university-of-technology-bachelor-of-technology-informat... science-construction-management--cur-cme-deg-2014 bachelor-of-arts--maq-art-deg-2014 education-early-childhood--cur-ece-deg-2014 technology-information-systems--swi-cis-deg-2014 information-systems-strategy--inf30009-2014 bodies-changing-selves--cltx300-2014 The text I want the variable to hold is only the text before 2014 and after â --â with an underscore (_) cur_cme_deg maq_art_deg cur_ece_deg swi_cis_deg inf30009 cltx300 How would I go about setting this tracking in Tealium
3 REPLIES 3
Highlighted

Capturing part of the URL and saving it as a Custom dimension in Universal Analytics

Employee Emeritus
Hello Pradeep; You might get several different correct approaches to this, but this was my way of how I got your scenario to work. 1. First, create a Data Source to map to your custom dimension in the Google Universal Tag. In my example, my Data Source is called "urlpartial" which will be the final variable that will hold your string the way you described. In my example, I am mapping to custom dimension 1. 2. Next, you will need a JavaScript Code extension to parse out the string as you require, and then set that to your UDO variable "urlpartial". 3. The code that I used in the extension is below. This uses JavaScript to find the segments of the url you are looking for with "--" and "-" as the markers (I assumed that all of your URL's have a final dash"-" before the 2014 with your samples above and use that as a final marker as you can see in code below). Then it replaces your single dashes, with an underscore (if dash exists using regular expression global setting) per your requirements as you described. {code:javascript} var fd=window.location.pathname.indexOf('--');//find double dash fd=fd+2;//increment to start after double dash var ld=window.location.pathname.lastIndexOf('-');//find last single dash var tp=window.location.pathname.substring(fd,ld); utag.data.urlpartial=tp.replace(new RegExp("-","g"), "_"); {code} This worked in my sandbox and sends the string to custom dimension 1 of GUA. I have some screenshots attached as well to show you how I did this in a second post below (as a .pdf file was only way I could attach the shots) Hope this helps! -bahman
Highlighted

Capturing part of the URL and saving it as a Custom dimension in Universal Analytics

Great, Thanks for this. Works perfectly.
Highlighted

Capturing part of the URL and saving it as a Custom dimension in Universal Analytics

Employee Emeritus
Fantastic, glad to hear it worked for you. -Bahman