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.

Leave a Reply