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...
The text I want the variable to hold is only the text before 2014 and after â --â with an underscore (_)
How would I go about setting this tracking in Tealium
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.
Then it replaces your single dashes, with an underscore (if dash exists using regular expression global setting) per your requirements as you described.
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
utag.data.urlpartial=tp.replace(new RegExp("-","g"), "_");
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!