Monthly Archives for April 2009


Reduce the Number of Cookies SiteCatalyst sets with Cookie Combining Plugin

The more advanced we get with our SiteCatalyst implementation, the greater the amount of cookies that can be set. Every time you use a getValOnce a cookie is set. If you are using that a bunch there can easily be over 20 cookies set on a single page ( I have seen as many as 45). If this is a concern for you, then Cookie Combining Utility to the rescue.

This one is pretty easy to implement. Just add both chunks to the Plugin section of your s_code.js file and that’s all there is too it.

 * Function - read combined cookies
s.c_r=new Function("k",""
+"var s=this,d=new Date,v=s.c_rr(k),c=s.c_rr('s_pers'),i,m,e;if(v)ret"
+"urn v;k=s.ape(k);i=c.indexOf(' '+k+'=');c=i<0?s.c_rr('s_sess'):c;i="
+"c.indexOf(' '+k+'=');m=i<0?i:c.indexOf('|',i);e=i<0?i:c.indexOf(';'"
+"urn v;");

 * Function - write combined cookies
s.c_w=new Function("k","v","e",""
+"var s=this,d=new Date,ht=0,pn='s_pers',sn='s_sess',pc=0,sc=0,pv,sv,"
+"c,i,t;d.setTime(d.getTime()-60000);if(s.c_rr(k)) s.c_wr(k,'',d);k=s"
+".ape(k);pv=s.c_rr(pn);i=pv.indexOf(' '+k+'=');if(i>-1){pv=pv.substr"
+".indexOf(' '+k+'=');if(i>-1){sv=sv.substring(0,i)+sv.substring(sv.i"
+"ndexOf(';',i)+1);sc=1;}d=new Date;if(e){if(e.getTime()>d.getTime())"
+"{pv+=' '+k+'='+s.ape(v)+'|'+e.getTime()+';';pc=1;}}else{sv+=' '+k+'"
+"='+s.ape(v)+';';sc=1;}if(sc) s.c_wr(sn,sv,0);if(pc){t=pv;while(t&&t"
+".indexOf(';')!=-1){var t1=parseInt(t.substring(t.indexOf('|')+1,t.i"
+"Time(ht);s.c_wr(pn,pv,d);}return v==s.c_r(s.epa(k));");

Just add that code and watch the number of cookies being set on each page drop right down.

Three SiteCatalyst Plugins To Add Detail To Visits

Here are three different plugins that have to do with your site visits. If you have not read it yet, be sure to check out Omniture’s Matt Belkin’s view on visits. It is one of the most important metrics to use, and here are a few plugins that will give you a little more insight to your site’s visits.

1. New/Repeat Visit
This plugin takes a look at each visit and sets the value of either “New” or “Repeat” right in a prop or eVar. One thing about this plugin is that it will set the value on every page view. One thing I recommend is to contact Client Care and have them enable visits for for the prop you plan to use with this plugin. Here is what you should get:
New/Repeat Visit Report

Here is the actual code:


 * Plugin: getNewRepeat
s.getNewRepeat=new Function(""
+"var s=this,e=new Date(),cval,ct=e.getTime(),y=e.getYear();e.setTime"
+"'s_nr',ct,e);return 'New';}if(cval.length!=0&amp;&amp;ct-cval<30*60*1000){s"
+".c_w('s_nr',ct,e);return 'New';}if(cval<1123916400001){e.setTime(cv"
+"al+30*24*60*60*1000);s.c_w('s_nr',ct,e);return 'Repeat';}else retur"
+"n 'Repeat';");

2. Visit Number
This plugin counts the number of visits that an individual visitor has. This is neat to see how users on their 9th or 10th visit interact with the site, as opposed to their 3rd or 4th visit. The report you will get with this is just a list of numbers, which you can correlate with other traffic items.

Here is the actual code:


 * Plugin: getVisitNum
s.getVisitNum=new Function("" 
+"var s=this,e=new Date(),cval,cvisit,ct=e.getTime(),c='s_vnum',c2='s" 
+" i=cval.indexOf('&amp;vn='),str=cval.substring(i+4,cval.length),k;}cvis" 
+"true',e);return str;}else return 'unknown visit number';}else{if(st" 
+";e.setTime(ct+30*60*1000);s.c_w(c2,'true',e);return str;}else{s.c_w" 
+",'true',e);return 1;}}"); 

3. Days Since Last Visit
This report looks at all of your visits, and tells you how long it has been since the previous visit. As with the previous two, this is going to be set on every page of the site, so make sure you enable visits. Here is what the report would look like:
Days Since Last Visit Report
As you can see it takes each visit and categorizes each one as being First Visit, Less than 1 day, Less than 7 days, More than 7 days, and More than 30 days.

Here is the actual code:


 * Plugin: Days since last Visit
s.getDaysSinceLastVisit=new Function("c",""
+"var s=this,e=new Date(),es=new Date(),cval,cval_s,cval_ss,ct=e.getT"
+"etTime(ct+30*60*1000);f0='Cookies Not Supported';f1='First Visit';f"
+"2='More than 30 days';f3='More than 7 days';f4='Less than 7 days';f"
+"5='Less than 1 day';cval=s.c_r(c);if(cval.length==0){s.c_w(c,ct,e);"
+"s.c_w(c+'_s',f1,es);}else{var d=ct-cval;if(d>30*60*1000){if(d>30*da"
+"y){s.c_w(c,ct,e);s.c_w(c+'_s',f2,es);}else if(d<30*day+1 &amp;&amp; d>7*day"
+"){s.c_w(c,ct,e);s.c_w(c+'_s',f3,es);}else if(d<7*day+1 &amp;&amp; d>day){s."
+"c_w(c,ct,e);s.c_w(c+'_s',f4,es);}else if(d<day+1){s.c_w(c,ct,e);s.c"
+"+'_s',cval_ss,es);}}cval_s=s.c_r(c+'_s');if(cval_s.length==0) retur"
+"n f0;else if(cval_s!=f1&amp;&amp;cval_s!=f2&amp;&amp;cval_s!=f3&amp;&amp;cval_s!=f4&amp;&amp;cval_s"
+"!=f5) return '';else return cval_s;");

Any of these can also be used to populate an eVar, and you can use them with the getValOnce plugin to grab each value one time per visit, then you can use these in conjunction with any of your success events to give you a greater insight on your site’s visits.

Please consult Client Care before using any of these to see if they are a good fit for your site and what you are trying to accomplish with your analytics investment.

Dayparting Plugin in SiteCatalyst

This is a really cool plugin I have used many times. This is what I consider to be one of the three or four core plugins that I think should be part of the standard SiteCatalyst installation, and I have included it in every implementation I have done. What this does is it looks at every page view on the site and grabs the hour down to 15 minute block, the day of week, and classifies whether it is a weekday or the weekend.

Let’s take a look at it. This bit of code is the main call to the plugin. This is pretty close to how the plugin originally looked, with one minor change. There is a part that had a hard coded year, that I replaced with a function that grabs the current year and uses that. The advantage to doing this is you do not have to update it every year. If you have many sites you keep an eye on then that is really not to practical. Here is the main call:

var theDate=new Date()	
var currentYear=(theDate.getFullYear())
s.prop1=s.getTimeParting('h','-5',currentYear); // Set Hour 
s.prop2=s.getTimeParting('d','-5',currentYear); // Set Day
s.prop3=s.getTimeParting('w','-5',currentYear); // Set Weekend/Weekday

What you see here is I have it set up to populate sprop’s 1, 2, and 3 with the three variables that this plugin populates. Another addition that can be done that I acutally do, is to add in a getValOnce to copy each variable over to an evar. That would look like:

var theDate=new Date()	
var currentYear=(theDate.getFullYear())
s.prop1=s.getTimeParting('h','-5',currentYear); // Set Hour 
s.prop2=s.getTimeParting('d','-5',currentYear); // Set Day
s.prop3=s.getTimeParting('w','-5',currentYear); // Set Weekend/Weekday

As you can see here I grab each value and copy it to an evar on the first page of the visit. Now using this call does no good without the actual plugin itself, so here it is:

 * Plugin: getTimeParting 1.4 - Set timeparting values based on time zone (15 min)
s.getTimeParting=new Function("t","z","y",""
+"dc=new Date('1/1/2000');var f=15;var ne=8;if(dc.getDay()!=6||"
+"dc.getMonth()!=0){return'Data Not Available'}else{;z=parseInt(z);"
+"if(y=='2009'){f=8;ne=1};gmar=new Date('3/1/'+y);dsts=f-gmar.getDay("
+");gnov=new Date('11/1/'+y);dste=ne-gnov.getDay();spr=new Date('3/'"
+"+dsts+'/'+y);fl=new Date('11/'+dste+'/'+y);cd=new Date();"
+"ffset()*60000);tz=new Date(utc + (3600000*z));thisy=tz.getFullYear("
+");var days=['Sunday','Monday','Tuesday','Wednesday','Thursday','Fr"
+"iday','Saturday'];if(thisy!=y){return'Data Not Available'}else{;thi"
+"sh=tz.getHours();thismin=tz.getMinutes();thisd=tz.getDay();var dow="
+"days[thisd];var ap='AM';var dt='Weekday';var mint='00';if(thismin>1"
+"if(thish>=12){ap='PM';thish=thish-12};if (thish==0){th"
+"ish=12};if(thisd==6||thisd==0){dt='Weekend'};var timestring=thish+'"
+":'+mint+ap;var daystring=dow;var endstring=dt;if(t=='h'){return tim"
+"estring}if(t=='d'){return daystring};if(t=='w'){return en"

This plugin is really cool to see a simple way to find out at what time of day the traffic comes to your site. With a little creativity you will be surprised the new business questions you are able to answer.

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:


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:
this function would return:

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.

Quick Tip: Correlating Servers with 404 Error Pages in SiteCatalyst

Looking for a quick win? Try correlating your 404 pages with your servers report. On larger sites, multiple servers are used to deliver the pages with some kind of load balancing. The problem that can come of this is when there is a code push, errors can occur and the push does not make it out to all of the servers and errors ensue. By being able to break down your 404 error pages by the server that is deloivering them can help spot troublesome machines, or code pushes that didn’t quite make it out to every machine.

Not using the s.server variable yet? Get on it!