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_rr=s.c_r;
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(';'"
+",i);m=m>0?m:e;v=i<0?'':s.epa(c.substring(i+2+k.length,m<0?c.length:"
+"m));if(m>0&&m!=e)if(parseInt(c.substring(m+1,e<0?c.length:e))<d.get"
+"Time()){d.setTime(d.getTime()-60000);s.c_w(s.epa(k),'',d);v='';}ret"
+"urn v;");
/*
* Function - write combined cookies
*/
s.c_wr=s.c_w;
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"
+"ing(0,i)+pv.substring(pv.indexOf(';',i)+1);pc=1;}sv=s.c_rr(sn);i=sv"
+".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"
+"ndexOf(';')));t=t.substring(t.indexOf(';')+1);ht=ht<t1?t1:ht;}d.set"
+"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.
Popularity: 41% [?]
Posted by VaBeachKevin - April 27th, 2009

This code is subject to an infinite recursion error when the same cookie is set but in a different path due to the manner in which it finds the current cookie value.
This will trigger the error:
var
/* Sets the s_pers cookie in the .domain.com and path = / */
_i= s.getVisitNum()
/* Read the value */
,_o= s.c_r(“s_pers”)
/* Sets the expiration time of the s_invisit attribute to 1 and encodes it */
, _c= encodeURIComponent(_o.replace(/s_invisit=true\|\d+/, “s_invisit=true|1″))
;
/* sets a new cookie called s_pers in the current path and current domain */
document.cookie=”s_pers=” + _c + “;”
/* Infinite recursion triggered here */
s_ut.c_r(“s_invisit”);