New Plugin Function To Populate Hierarchy From URL in Omniture SiteCatalyst

I was taking a look at a previous post I did about populating the hierarchy variable from within the s_code file, and I found a few flaws with my logic and figured there has to be a better way to do this. If you happen to run across that old post, ignore it and just come here instead.

SiteCatalyst allows for 5 different hierarchies to be set on your site, each of them using some kind of a delimiter to separate the levels. What I have here will take the folders from the URL and apply them as each level of the hierarchy. I originally had this written as a bunch of JavaScript all scattered about but I decided to combine it all into a nice neat function, and stick that in the Plugin section of the s_code file. I have this set to only go 5 levels deep but I’m sure you can take a look at it and adjust it as you see fit. I also have it set if there is no folder there, basically your on the home page, then the first level of the hierarchy would be “home”.

In the ‘calls to plugins’ section of the s_code file I added:

s.hier1=getHier();

Then in the Plugin section of the s_code file I added:

/*
* Plugin getHier 1.0 - Populates the Hierarchy from folders in the URL
*/

function getHier(){
var folders = new Array();
var path = window.location.pathname;
path = path.replace("http://", "");
path = path.slice(path.indexOf('/') + 1, path.lastIndexOf('/'));
folders = path.split('/');
for (var i = 0; i < folders.length; ++i) {
if (folders[0] != ""){var fld1 = folders[0]};
if (folders[1] != ""){var fld2 = folders[1]};
if (folders[2] != ""){var fld3 = folders[2]};
if (folders[3] != ""){var fld4 = folders[3]};
}
if(fld1){var fl1='|'+fld1} else {var fl1=""};
if(fld2){var fl2='|'+fld2} else {var fl2=""};
if(fld3){var fl3='|'+fld3} else {var fl3=""};
if(fld4){var fl4='|'+fld4} else {var fl4=""};
var hierVal="home"+fl1+fl2+fl3+fl4;
return hierVal;}

Looking at the URL:
http://webanalytics-land.com/channel-name/folder2/folder3/folder4/
this function would return:
s.hier1=home|channel-name|folder2|folder3|folder4

Remember in order for this to work you first need to contact Client Care and have them turn on Hierarchies, have them name it, set how many levels deep it should go, and what the delimiter is going to be.

Now here’s the fine print and a word of caution. SiteCatalyst plugins for the most part are not going to be supported by Omniture. They have two or three they are good with, other than that they are not going to be easily available. A SiteCatalyst plugin really is nothing more than some JavaScript used to automatically populate a variable. What I have here should be looked at as just a ‘proof of concept’. I have not tested this to see what the effects are on any other variables being collected. If you decide to implement this on your site and you disappear from Google and your servers explode, don’t come yelling at me. I have this code running on my company’s Intranet, which I use as my test bed for coding. I do not have this on any production sites.

That being said, I don’t see any issues right away with the code. Yes I’m pretty sure that some JavaScript experts out there could probably take this and fine tune the heck out of it, but it does work. At least it does for me. Enjoy.

Leave a Reply