How To Add Page Views And Visits To All SiteCatalyst eVars

Here is a simple way to add Page Views and Visits to all of your eVar reports (see the update below). While Client Care has the ability to turn on a few things, flip some switches here and there to add visits to some reports, I like having full control over it as much as possible myself (and I’m not really in the mood to wait on hold to get it done). To make this happen we are going to have to use 2 events and a pair of plug-ins. Hopefully you should have a couple of events available to use, and you can find the plug-in code on the SiteCatalyst Plugins page. Here’s how to do it.

First lets get Page Views. To do this we are going to use the Append List plug-in. The Append List (or apl) plug-in utility provides a simple mechanism to append a value to any delimited lists, with the option of a case sensitive or case-insensitive check to insure the value doesn’t already exist in the list. The apl plug-in is referenced by several standard plug-ins but can be used directly in a variety of situations. This is an Omniture supported plug-in and you can find more information about it by accessing the Knowledge Base.


L = source list, empty list is accepted
v = value to append
d = list delimiter
u (optional, defaults to 0) Unique value check. 0=no unique check, value is always appended. 1=case insensitive check, append only if value isn’t in list. 2=case sensitive check, append only if value isn’t in list.

What we are going to do is in the s_code.js file, set up this plug-in to fire off an event on every single page view of the site, exactly mimicking the standard Page View metric.

/* Set Page View Event */,'event1',',',1);

Here is the plug-in code:

* Plugin Utility: apl v1.1
s.apl=new Function("L","v","d","u",""
+"var s=this,m=0;if(!L)L='';if(u){var i,n,a=s.split(L,d);for(i=0;i<a."
+"e()));}}if(!m)L=L?L+d+v:v;return L");

UPDATE: In my eagerness to share this with everyone I skipped the testing process I usually do. Upon testing I realized I a critical, basic error in my logic. By doing it this way, you are setting an event prior to any of the eVars, so they would not be associated with each other, and there for show up as “None” in your report. It is such a simple oversight that I am actually embarrassed that I missed. So now I throw it out to you, the Omniture community, how do you guys think we should try to figure this one out? Or is it even possible to do? Let me know what you think!

Just to be super clear, this will work if you want to add visits to some of your Traffic Sources reports. For example if you want visits from the original referring domains, this will work perfectly for that.

Now lets get Visits. I thought a lot about how to get this. One method you could use would be do the exact same thing we did to get the Page Views event. Set it up on a different event, then call up Omniture Client Care to have them set that event to only record once per visit. Again I wanted to try to avoid using Client Care. I also did not want to go that route since I want this to mimic the Visits metric as close as possible, so I want it to be cookie based. Here I decided to use the Get Visit Start plug-in.

What the Get Visit Start plug-in was designed to do is to determine first page of a visit. It returns 1 on the first plug-in call of the visit, otherwise returns nothing. It uses a 30 minute cookie if possible, otherwise reverts to a session cookie. Always returns nothing if 30 minute or session cookie can’t be set, so it functions very much like the standard Visit’s metric. What I have done is set the plug-in up to populate a variable, then use basic JavaScript to determine if there is a value to the variable that was just set, and if so fire off the Append List plug-in. The theory behind this is the Get Visit Start plug-in will only return a value one time per visit, on the first page view, and at that one and only time fire off a single event.


c=cookie name for tracking (“s_visit” is standard)

Here is how I have it set up. I made up a variable s.visEvent to hold the value of the Get Visit Start Plugin, then fire off event6 if it has a value.

/* Set Visit Event */
if (s.visEvent),'event6',',',1);

Here is the plug-in code:

 * Get Visit Start
s.getVisitStart=new Function("c",""
+"var s=this,v=1,t=new Date;t.setTime(t.getTime()+1800000);if(s.c_r(c"
+")){v=0}if(!s.c_w(c,1,t)){s.c_w(c,1,0)}if(!s.c_r(c)){v=0}return v;");

Pretty simple. Typically I would have just used the Get Val Once plug-in when I want to get a value of a variable only once per visit, but it didn’t want to work well with the variable.


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.