Home ·  About ·  Search ·  Contact ·  SiteCatalyst Plugins ·  Web Analytics Books




Stephane Hamel - April 3rd, 2009 @7:44 am  

Your script actually has some limitations and isn’t optimized:
- what if the hierarchy as more than 4 levels?
- what if the URL ends up with /page.htm?

I’ve been doing JavaScript coding for years, here’s a different version of it:

function getHier(s) {
if(!s)
s = window.location.pathname;
if(/\.[^\/]+$/.test(s))
s = s.substring(0,s.lastIndexOf(“/”));
s = “home”+s.toLowerCase().replace(/\//g,”|”);
return s.replace(/\|$/,”");
}

To test it:
alert(getHier());
alert(getHier(“/page.htm”));
alert(getHier(“/a/b/c/d/”));
alert(getHier(“/a/b/c/d/page.htm”));
alert(getHier(“/a/b/c/d/page.htm#hash”));
alert(getHier(“/a/b/c/d/page.htm?a=1&b=2″));

Cheers,
Stéphane Hamel
http://immeria.net


VaBeachKevin - April 3rd, 2009 @8:17 am  

Thanks for the input! My code is quite bulky, and am 100% positive that it can be improved. This post was done to actually show what a little creative coding can do, the other just to get people aware that they are not limited by the Plugins handed down from Omniture and hopefully get the creative juices flowing for others out there.

I had this set at 5 levels (home plus 4 folders) since you have to set the hierarchy depth when setting it up with Client Care. If this collects 8 levels deep, SiteCatalyst will only report 5 since that’s how I had them enable it for my specific case. In general SEO terms, i don;t think most sites should be going that deep in folders in the first place, but that debate is for another day. I was also planning on going back and adding in some kind of location.href.substring(location.href.lastIndexOf(‘/’)+1); type code to pull out that last level if it is not a folder, but you beat me to it.

Again I appreciate the feedback. Thanks!


Rudi Shumpert - September 4th, 2009 @8:27 am  

Great Post. It got me thinking how to do it on our site.

http://tr.im/xSCz

Pingback And Trackback To This Post
Permalink To This Post

Please Note: comments maybe under moderation so there is no need to resubmit your comments. Feel free to subscribe to this post's comment rss feed for future updates