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.eVar1=s.getValOnce(s.prop1,'s_evar1',0);
s.prop2=s.getTimeParting('d','-5',currentYear); // Set Day
s.eVar2=s.getValOnce(s.prop2,'s_evar2',0);
s.prop3=s.getTimeParting('w','-5',currentYear); // Set Weekend/Weekday
s.eVar3=s.getValOnce(s.prop3,'s_evar3',0);

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();"
+"if(cd>spr&&cd<fl){z=z+1}else{z=z};utc=cd.getTime()+(cd.getTimezoneO"
+"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"
+"5&&thismin<30){mint='15'}if(thismin>30&&thismin<45){mint='30'}if(th"
+"ismin>45&&thismin<60){mint='45'}"
+"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"
+"dstring}}};"
);

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.

Leave a Reply