Archives

 

Getting Started With the Omniture PHP Measurement Library

The Omniture PHP Measurement Library lets you use PHP to record your visitor’s activity on your Web site. At first glance it can look a little intimidating, but it really is not that complicated. Once you have it implemented, all that you will see in the source code of your pages is the image request for the standard Omniture tracking pixel. This is what it looks like implemented.

Here is how to get started with it. From the Code Manager, download the OmnitureMeasurement.class.php file and add it to your server in a place so it can be referenced from every page of your site. Next you will need to include the Omniture PHP code on every page of your site.

Here is what a basic version of the PHP page code would look like:

<?php
require_once 'OmnitureMeasurement.class.php';
$s = new OmnitureMeasurement();
$s->account = 'ACCOUNT NAME HERE';
$s->botDetection = true;

$s->pageName = "Homepage";
$s->server = "Server";
$s->channel = "Channel";

$s->events = "events";
$s->prop1 = "prop1";
$s->prop2 = "prop2";
$s->eVar1 = "eVar1";
$s->eVar2 = "eVar2";

$s->currencyCode = 'USD';
$s->imageDimensions = '5x5';
$s->trackingServer = 'dominionenterprises.112.2o7.net';
$s->sendFromServer = false;
$s->debugTracking = false;
$s->track();
?>

Lets break it down by section so you will see what is going on here. Here is the first section of the code:

<?php
require_once 'OmnitureMeasurement.class.php';
$s = new OmnitureMeasurement();
$s->account = 'ACCOUNT NAME HERE';
$s->botDetection = true;

The first thing we have here is the call to the Omniture Measurement class require_once ‘OmnitureMeasurement.class.php’;. This is what makes the Omniture PHP tracking work. As I said you can download it from the Admin section of SiteCatalyst. That is followed by a line of code that will get the tracking started $s = new OmnitureMeasurement();. Next is the place where you enter the report suite id that is associated with the site you plan on tracking. Finally we have a line to detect bots. When this is set to true, the Measurement Library detects if the HTTP User-Agent field is a bot, and does not send bot-generated data to Omniture. If this is not included it is set to false by default. If you decide to not include that, then be prepared to see Googlebot show up in your reporting.
Googlebot User Agent

$s->pageName = "Homepage";
$s->server = "Server";
$s->channel = "Channel";

This next section should be pretty self explanatory. This is where I set the pageName, the server, and the channel variables. On my 404 error page this is where I also include the pageType variable, which would look like $s->pageType=”errorPage”;.

EXTRA: For a lot of my sites I like to use the folder name of the URL as the page name. Here is how you can do that using PHP. I insert this code before the Omniture tracking section:

<?php
$pNme = parse_url($url, PHP_URL_PATH);
if ($pNme=="/")$pNme = "Home Page";
?>

Then in the measurement library code I include:

$s->pageName = $pNme;

This pulls the file name from the URL and uses that as the page name. I also added a line that looks if all it finds is a slash / then I know they are on the Home Page and use that instead.

$s->events = "events";
$s->prop1 = "prop1";
$s->prop2 = "prop2";
$s->eVar1 = "eVar1";
$s->eVar2 = "eVar2";

This next section is where we are going to add the Custom Traffic variables, Custom Conversion variables, and Success Events. Again, this section should be pretty straight forward. If you know how to set props and eVars on the page and in the s_code file, you should know what to do here.

$s->currencyCode = 'USD';
$s->debugTracking = false;
$s->imageDimensions = '5x5';
$s->trackingServer = '112.2o7.net';
$s->sendFromServer = false;
$s->debugTracking = false;
$s->track();

This final section contains some pretty important elements. The first thing you will see is where you declare the Currency Code used for purchases or currency events. You can see I have mine set to US currency, USD. Next I have the call that specifies the width and height of the image request, in pixels. By default, this variable is 1×1. You can see I have mine changed to 5×5 to ensure support for all mobile devices. Next I enter my tracking server info. You should be able to find that in your s_code.js file.

The next two lines are pretty cool. Let’s say you do not to show any Omniture code on the page. You have the option to not have any thing appear in the source code. When $s->sendFromServer is set to true, the Measurement Library makes a direct HTTP request from the server instead of rendering an image tag to the Web browser. If you view the source of the page you will not see anything but the visitor will still be fully tracked. You can see a live example of it here.

Without any code on the page it can be difficult to debug the code to make sure everything is being passed in successfully. That’s where the next variable comes in, $s->debugTracking. With this set to false then we do not see anything. If it is set to true then you will see an output on the page of the metrics that are being passed into Omniture. You can see a live example of it here.

The problem with that is you either have it off all the time, or you have it on where all of your visitors can see a bunch of code on the page. What I like to do is to add in a little bit of extra code that will only allow the debug code to appear only for me. I do this based off of my ip address. I include this bit of code before the Omniture code:

$ip=$_SERVER['REMOTE_ADDR'];
if ($ip=="xxx.xxx.xx.xxx") {
	$atHome = true;
} else {
	$atHome = false;
}

And then In the Omniture code I have it set as:

$s->debugTracking = $atHome;

What this does is allows me to see the variables that are being set every time I visit the site, but none of my visitors have to see it.

The last thing you will see listed in this section is $s->track(); which is the call to fire off the code. Without this nothing works. This is the equivalent of having the line var s_code=s.t();if(s_code)document.write(s_code) in the standard JavaScript tracking. In other words, make sure you include this line.

OK, what else can we do with this? Well as many people know I am a big fan of using plug-ins. Here is one to get you started. One of the more useful ones is the Time Parting plug-in. As I have written about before, I like combining all of the time variables so I only use a single prop/eVar, so it looks something like s.prop1=”thursday|10:00pm” and then using a SAINT classification to break it out. How do we replicate this using the PHP Library? Here you go.

Above the Omniture Measurement code I include this:

$dayname = date('l');
$dayname = strtolower($dayname);
$hourname = date('g');
$minname = date('i');
$ampmname = date('a'); 

if ($minname <= "14") {
	$mintype = "00";
} else if ($minname >= "15" && $minname <= "29"){
	$mintype = "15";
} else if ($minname >= "30" && $minname <= "44"){
	$mintype = "30";
} else if ($minname >= "45" && $minname <= "59"){	
	$mintype = "45";
}
$fulldayparting = "$dayname|$hourname:$mintype$ampmname"; 

Then in one of the available props in the code I have:

$s->prop16 = $fulldayparting; 

This returns something like thursday|10:00pm, exactly like the Javascript plug-in does. I also like to copy this same value to an eVar, but I only want to do it once per visit. I like using the eVar for when the visit started, and the prop for every page view. Here is how I get that same value recorded only once per visit.

At the top of all my ‘extra’ code that I have included before the Omniture measurement code, I include this:

$sesionnumber = $_SESSION['count'];
if ($sesionnumber == '1') {
     $fulldaypartingsession = $fulldayparting;
} else {
     $fulldaypartingsession = '';
}

And then with the available eVars I include:

$s->eVar16 = $fulldaypartingsession;

What this does is on the first page of the session it will set the Time Parting value, but will just leave it blank for the rest of the session giving you a good session start time.

Hopefully this is enough to get you started. There are a lot of other cool PHP tricks that will allow you to replicate most of the functions of the Javascript tracking. Make sure you download and read the PHP Measurement Library Implementation Guide from the Omniture Help Section for additional details.

Enjoy!

Track Hash Query Parameters in Omniture SiteCatalyst

Do you have a site that uses a hash symbol in the URL with query parameters and you want a way to track them in SiteCatalyst? Well you have come to the right place.

What am I talking about? Lets say you have a URL that looks like this:
http://webanalyticsland.com/#cid=Hash_Param_Test
and you want to capture the value of cid=. The standard getQueryParam plugin will not work in this case. It looks for a question mark in the URL, and as you can see this one did not have one.

To capture this value we can use the getHashQueryParam s_code.js plug-in. What this plug-in does is looks for the hash symbol # at the end of the URL, then looks for the parameter you have listed in the function, then inserts the value in to the associated variable. This works just like the standard getQueryParam plugin, but looks for the hash instead.

Here’s how to use it. Insert this line of code in the s_doPlugins(s) section of your s_code.js file. Make sure you use the correct variable you want the metrics recorded in and which query string you want it to be associated with. I’m using s.prop17 and cid in this example.

s.prop17=getHashQueryParam('cid');

Next enter this code in the plug-in’s section of your s_code file:

/*
 * Plugin: getHashQueryParam
 */
function getHashQueryParam(a){
var QueryString=window.location.search.substring(1);
if(QueryString==''){var WinExtra=window.location.hash;
if(WinExtra.length > 0){if(WinExtra.indexOf(a)>-1){
QueryString=WinExtra.substr(WinExtra.indexOf(a))}}}
var returnValue='';var keyValPairs=QueryString.split('&');
if(!keyValPairs){ keyValPairs = new Array();  
keyValPairs[keyValPairs.length]=QueryString}
for(var counter=0;counter<keyValPairs.length;counter++){
var keyVal=keyValPairs[counter].split('=');if(keyVal[0]==a){
returnValue=keyVal[1];break;}}return returnValue;}

Here is an example of it live in action. After you click on the link, open the debugger you will see the value entered in s.prop17.

Enjoy!

Don’t Forget Your SiteCatalyst Utility Functions!

Have you ever tried to use a new plug-in and found it did not work? You were probably missing a utility function. Utility functions are designed to work with SiteCatalyst plug-ins. There are 6 utility functions that are commonly used. They are apl, p_c, p_gh, split, replace, and join.

These functions do things like join elements of an array into a string delimiter by a string, replaces characters in a string, splits a string on a specific character, append a value to any delimited lists, and more. THese utility functions are referenced by several standard plug-ins.

Here’s how I do it. I take all these utility functions and wrap them all up in one neat package, and include this as one of my standard plug-ins to add when creating a s_code file. This way not thing is missed, nothing is forgotten and all of my plug-ins will work no problem.

Here’s what it looks like:

/*
 * Utility Functions: apl, p_c, p_gh, split, replace, join
 */
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."
+"length;i++){n=a[i];m=m||(u==1?(n==v):(n.toLowerCase()==v.toLowerCas"
+"e()));}}if(!m)L=L?L+d+v:v;return L");
s.p_c=new Function("v","c",""
+"var x=v.indexOf('=');return c.toLowerCase()==v.substring(0,x<0?v.le"
+"ngth:x).toLowerCase()?v:0");
s.p_gh=new Function(""
+"var s=this;if(!s.eo&&!s.lnk)return '';var o=s.eo?s.eo:s.lnk,y=s.ot("
+"o),n=s.oid(o),x=o.s_oidt;if(s.eo&&o==s.eo){while(o&&!n&&y!='BODY'){"
+"o=o.parentElement?o.parentElement:o.parentNode;if(!o)return '';y=s."
+"ot(o);n=s.oid(o);x=o.s_oidt}}return o.href?o.href:'';");
s.split=new Function("l","d",""
+"var i,x=0,a=new Array;while(l){i=l.indexOf(d);i=i>-1?i:l.length;a[x"
+"++]=l.substring(0,i);l=l.substring(i+d.length);}return a");
s.repl=new Function("x","o","n",""
+"var i=x.indexOf(o),l=n.length;while(x&&i>=0){x=x.substring(0,i)+n+x."
+"substring(i+o.length);i=x.indexOf(o,i+l)}return x");
s.join = new Function("v","p",""
+"var s = this;var f,b,d,w;if(p){f=p.front?p.front:'';b=p.back?p.back"
+":'';d=p.delim?p.delim:'';w=p.wrap?p.wrap:'';}var str='';for(var x=0"
+";x<v.length;x++){if(typeof(v[x])=='object' )str+=s.join( v[x],p);el"
+"se str+=w+v[x]+w;if(x<v.length-1)str+=d;}return f+str+b;");

I just make sure that is block is included in every s_code file. Then I am assured that every plug-in I use can find the correct utility function it needs to work properly.

Enjoy!

Optimize the Time Parting Plugin to get More Detail and Use Less Variables

The Time Parting Plug-in is one of the more popular SiteCatalyst plug-ins available. A standard implementation of the Time Parting plug-in will consume 3 variables. One for Time of Day, one for the Day of Week, and one for Weekday/Weekend. How can we improve this to get more information, and more importantly use less variables? Here is how I have been doing it.

I use a combination of stacking the variables and SAINT uploads. For those of you who are not familiar with SAINT, Omniture describes it as, “…an acronym for SiteCatalyst Attribute Importing and Naming Tool. This tool enables you to download the classifications template, apply attributes to it, and then upload the data, thereby enhancing your SiteCatalyst reports with the new attributes.” This will allow us to upload a lot of detail about any variable you record.

Here’s how I’m doing it on this site. First I am using the 2.0 version of the plug-in and not the 1.4 version that I describe in a previous post. The 2.0 version includes support for Daylight Savings time and globalizes the year. You can find the 2.0 version from the SiteCatalyst Knowledge Base. If you prefer to use the 1.4 version, you can find it on this site.

/* Set Time Parting Variables */
s_hour=s.getTimeParting('h','-5'); 
s_day=s.getTimeParting('d','-5');
s_timepart=s_day+"|"+s_hour;
s.prop16=s_timepart.toLowerCase();
if (s.visEvent) s.eVar16=s.prop16;   

Ok, let me explain whats going on here. As I said before the Time Parting plug-in captures 3 variables. If you notice in my code I am only using two of them. I don’t need to capture Weekday/Weekend anymore. I will take care of that later. The other two, I capture in two blank variables I created, s_day and s_hour. Next I combine the two of them in a single variable I call s_timepart, separated by a pipe. Then to ensure everything is consistent I copy the variable in all lower case to the prop that I am going to use. This next part is a little different. In the eVar I only want capture this value once per visit. Typically a simple getValOnce will be enough to get it done. Well then what happens when the visit extends from one time part into another? In that situation the Time Parting value will be different and therefore getValOnce will capture this as a new value since it has changed. I don’t want that to happen, I only want it once per visit. So this is when I tie in using the get Visit Start plug-in. This guarantees I will only capture the value only one time per visit.

This will return a report that looks like this:
Time Parting Report in SiteCatalyst

We now have a total of 672 possible options in this report. The next thing we want to do is to classify these using SAINT. I set up 5 different categories to use. Weekday/Weekend (this is why we don’t need to capture it in the code, Day of Week, Hour of Day, Hour Part and AM/PM.
SAINT Setup

I then created the template to use that contains all of these values.
SAINT Template
You can download a copy of the template that I use here.
Upload the template and that’s all there is to it. Do you have more conversions in the bottom of the hour or the top of the hour? How about morning vs afternoon? Which whole hour is the most profitable? Now you have an easy way to break down your time parting with finer granularity, at the sime time saving your self a couple of variables.

Enjoy!

Additional Methods To Measure Interaction Using The Get Time To Complete Plug-In

Recently there was a great article on the Omniture Blog all about Capturing Time Spent on . . . well, just about anything. It’s a great post and definitely worth checking out. After reading it I was wondering if there was another way to do it? Of course there is! I present the Time To Complete Plug-in.

The getTimeToComplete plug-in will track the time it takes a user to complete some process on your site. The “clock” begins when you call the plug-in with the value “start” and stops when the plug-in with the value “stop”. The plug-in can be used to track the time to complete a checkout process, to track the time to complete an application process, to track the time a user spends viewing/using Rich Internet Applications (RIA), or to track the time between a download and a purchase.

s.getTimeToComplete( v, cn, e )

v is the Value – ‘start’ or ‘stop’
cn is the Cookie Name – example: ‘ttc’
e is the Expiration – days to expiration of the cookie, 0 for session
This function will return an empty string ” or a value in days, hours, minutes or seconds

There is a bunch of different ways to use this plug-in. I like this first method because you do not have to add a single of code to the page to make it work (I have found it is much easier to get a development team to simply upload a new s_code file as opposed to adding additional code to the site.) Lets say you want to track a form on your site. Lets say the form is at /my-form.php. Once the visitor fills out the form, they are taken to the thank you page which lets say is at /my-form-thanks.php. I would add this bit of code to the s_code file:

if (window.location.pathname=='/my-form.php') s.ttc='start';
if (window.location.pathname=='/my-form-thanks.php') s.ttc='stop';
s.prop1=s.getTimeToComplete(s.ttc,'ttc',0);

What this does is looks for the path in the URL for /my-form.php and sets start in s.ttc. When the plug-in see’s this it set’s the cookie ttc with a start time Then when the URL path is /my-form-thanks.php stop is set. When the plug-in see’s stop, it then reads the ttc plug-in and records the time difference in s.prop1. The time value that you will get will have days and hours rounded to .2 (e.g. 1.4 days), minutes to .5 (e.g. 2.5 minutes), and seconds to 5 (e.g. 15 seconds).

NOTE:When this is implemented, if you check the debugger you will not see any value for s.prop1 until you have reached the stop point of the process.

Here is another way to use the code. Let’s say you have some events set right on the pages of your site. We want to know how long it takes to get from when event1 is set to when event2 is set. I would add this code into the s_code file:

if(s.events.indexOf('event1')>-1) s.ttc='start';
if(s.events.indexOf('event2')>-1) s.ttc='stop';
s.prop1=s.getTimeToComplete(s.ttc,'ttc',0);

What this does is look for when event1 happens, then set start in s.ttc. When event2 happens stop is set, and the time value is set in s.prop1.

NOTE: Another thing to remember is this can be used to record the time of many different processes or paths on your site. If you do that I suggest using a different cookie name and variable value in each one so there are no issues.

Here is the actual plug-in code:
The getTimeToComplete plug-in returns the time to complete a task. When v is ‘start’ a cookie is written with the timestamp. When v is ‘stop’ the cookie is read and the expired time is returned in days, hours, minutes, or seconds.

/*
 * Plugin: getTimeToComplete
 */
s.getTimeToComplete=new Function("v","cn","e",""
+"var s=this,d=new Date,x=d,k;if(!s.ttcr){e=e?e:0;if(v=='start'||v=='"
+"stop')s.ttcr=1;x.setTime(x.getTime()+e*86400000);if(v=='start'){s.c"
+"_w(cn,d.getTime(),e?x:0);return '';}if(v=='stop'){k=s.c_r(cn);if(!s"
+".c_w(cn,'',d)||!k)return '';v=(d.getTime()-k)/1000;var td=86400,th="
+"3600,tm=60,r=5,u,un;if(v>td){u=td;un='days';}else if(v>th){u=th;un="
+"'hours';}else if(v>tm){r=2;u=tm;un='minutes';}else{r=.2;u=1;un='sec"
+"onds';}v=v*r/u;return (Math.round(v)/r)+' '+un;}}return '';");

I really like this plug-in because you end up with a report that is completely dedicated to the time it takes to complete that exact action.

Enjoy!

Enhance Your SiteCatalyst S_Code Using Server-Side Scripting

I receive a lot of questions from people working on their own SiteCatalyst implementations and I’m always happy to help. One that I got recently is “why is your s_code file a php file”? I figured there were not too many people out there doing it like this or even know about this, so I thought I would help out those that were interested in what the advantages of using server side code to enhance your data collection.

The reason I use a php file to house all of my s_code script is simple. I want to be able to do what is not easily done with using standard JavaScript. Here are a couple of examples.

First things first. How do I get a php file to act like JavaScript? It’s actually pretty easy. First thing you do is in the top of your file add this small bit of code:

<?php header('Content-type: application/javascript'); ?>

The purpose of this line is just to say ‘hey, unless instructed otherwise, treat everything you are going to see here as JavaScript. Next change your file extension from .js to .php. That’s all you need to do to start adding in some php scripting into your file.

Here are some things I am using it for. I like capturing the IP address of my visitors. I like to track this because I have had problems with spammers, scraper bots and general bad visitors in the past, and I just like keeping my eye on things. Here is the code to capture IP address.

s.eVar17="<?php echo $_SERVER['REMOTE_ADDR']?>";

I also have this matched with the get Val Once plug-in.

Another thing I like to capture is User Agent. How many people come to my site from a specific build of IE6? Is Googlebot executing my JavaScript when crawling my site? Here is how I capture User Agent.

s.eVar23="<?php echo $_SERVER['HTTP_USER_AGENT']?>";

Again I match this up with the get Val Once plug-in.

Another thing I like to do is use php to populate the configuration variables of the Time Parting plug-in. The latest version of the plug-in, 2.0, uses specific daylight savings time variables (the 2.0 version is available from the Omniture Help section. The version I host here on the site is the older 1.4 version). The 3 variables that need to be configured for the plug-in are Daylight Savings Time start day for the current year, Daylight Savings Time end day for the current year, and the Current Year. Now all of these can be hard coded, but I’d rather do a little bit of one time coding and never have to worry about it again. Here is how I set those variables using php.

s.dstStart="<?php echo date('m/d/Y', strtotime("Second Sunday March 0"));?>";
s.dstEnd="<?php echo date('m/d/Y', strtotime("First Sunday November 0"));?>";
s.currentYear="<?php echo date('Y');?>";

All of these take advantage of the date() functionality of php. Combine that with a little bit of extra code, and with the fact that I know that daylight savings time always begins the second Sunday of March and ends on the first Sunday of November, I never need to touch those variables again.

Increase SiteCatalyst Clickmap Functionality with Dynamic Object IDs Plug-in

ClickMap. Pretty useful tool. It gives you a neat overlay that shows you what links are clicked on a page and the associated traffic. I wonder how we can make it better? Knock knock. Oh who is that at the door? Why its the Dynamic Object IDs Plugin. Please step right in.

The Dynamic Object IDs Plug-in dynamically adds an object ID to the click thru URL. You can see it using the debugger. It is designed to improve the function of the Clickmap.

Let’s take a look at an example. From the home page of this site, there are 3 links that take you to the Contact page. I click the last one on the page, then open the debugger on the page I land on. Here you can see that the click thru URL has been appended with the number of the order that it happened to appear in on the page. So now when I have multiple links on a single page each one is easily spotted in the debugger, even though they all have the same anchor text and click thru URL.
Dynamic Object ID Plug-in

Now what do we get? If you look at the clickmap report, Site Content>Links>ClickMap, you will now see a number attached to each URL.
Clickmap Report
Now you know exactly which link was clicked.

Here is how I have it implemented on this site. Before the function s_doPlugins(s) I include the code:

/* DynamicObjectIDs config */
function s_getObjectID(o) {
	var ID=o.href;
	return ID;
}
s.getObjectID=s_getObjectID

Then within the s_doPlugins(s) function, I include:

/* To setup Dynamic Object IDs */
s.setupDynamicObjectIDs();

And finally in the Plug-ins section I have the plug-in code itself.

/*
 * DynamicObjectIDs
 */
s.setupDynamicObjectIDs=new Function(""
+"var s=this;if(!s.doi){s.doi=1;if(s.apv>3&&(!s.isie||!s.ismac||s.apv"
+">=5)){if(s.wd.attachEvent)s.wd.attachEvent('onload',s.setOIDs);else"
+" if(s.wd.addEventListener)s.wd.addEventListener('load',s.setOIDs,fa"
+"lse);else{s.doiol=s.wd.onload;s.wd.onload=s.setOIDs}}s.wd.s_semapho"
+"re=1}");
s.setOIDs=new Function("e",""
+"var s=s_c_il["+s._in+"],b=s.eh(s.wd,'onload'),o='onclick',x,l,u,c,i"
+",a=new Array;if(s.doiol){if(b)s[b]=s.wd[b];s.doiol(e)}if(s.d.links)"
+"{for(i=0;i<s.d.links.length;i++){l=s.d.links[i];c=l[o]?''+l[o]:'';b"
+"=s.eh(l,o);z=l[b]?''+l[b]:'';u=s.getObjectID(l);if(u&&c.indexOf('s_"
+"objectID')<0&&z.indexOf('s_objectID')<0){u=s.repl(u,'\"','');u=s.re"
+"pl(u,'\\n','').substring(0,97);l.s_oc=l[o];a[u]=a[u]?a[u]+1:1;x='';"
+"if(c.indexOf('.t(')>=0||c.indexOf('.tl(')>=0||c.indexOf('s_gs(')>=0"
+")x='var x=\".tl(\";';x+='s_objectID=\"'+u+'_'+a[u]+'\";return this."
+"s_oc?this.s_oc(e):true';if(s.isns&&s.apv>=5)l.setAttribute(o,x);l[o"
+"]=new Function('e',x)}}}s.wd.s_semaphore=0;return true");

To see this code in the s_code file running this site, you can check it out here.

Ok great. Now what else can we do with this plug-in? Lets say I want to track how many contact form submissions I received from clicking the third Contact link that appears on the Home Page? Well I could add a custom onclick function. I could add a tracking code on the end of the click thru URL. But how can I use this new plug-in to track this?

Recently there was a post on the Omniture blog about using Dynamic Variables. Using these variables we can now grab the value of oid, which is the click thru URL with the new object id added to it, and you can get the pid which is the page the click happened on. I have it set up on this site:

s.prop20=s.eVar20="D=oid";
s.prop22=s.eVar22="D=pid";

Now with a simple subrelation I can get what link was clicked on what page and what events occurred, all without adding any additional code to the page.

Enjoy!

The getCartOpen and resetGetCartOpen SiteCatalyst Plugins

In our quest to make our SiteCatalyst implementation more powerful and lighten the load on the developers and programmers (who for some reason always have more important things to do then add more Omniture code to the site), there are a couple of plug-ins I like to use to help to set the scOpen event.

The scOpen event is used to populate the Carts Report and metric with the number of times visitors view a new shopping cart during an eCommerce process. The scAdd event should be used when adding items into a shopping cart. But what if every time you add an item to the shopping cart, you are taken to the shopping cart? Well then you should set both events the first time. But only first time the shopping cart is opened, the scOpen event should be set. If the shopping cart has already been opened, the scOpen event should not be set again during that visit. So how do we make sure that the scOpen event is only set on that very first instance of the cart being viewed?

What we have here are the getCartOpen and resetGetCartOpen SiteCatalyst plug-ins. What the getCartOpen plug-in does is looks for the very first instance of the scAdd event being set and adds the scOpen event at that same time. Each time after that the scAdd event is set, the scOpen event will not be set again. But what if the visitor completes an order and wants to place another during the same visit? That’s where the resetGetCartOpen plug-in comes in. It looks for an instance of the purchase event and then allows the scOpen event to be set again if a new shopping cart is created.

This first line which goes in the calls to plugins section of the s_code.js file, calls the getCartOpen plugin and returns the events string with scOpen added the first time scAdd occurs during a visit.

/*Get Cart Open*/
s.events=s.getCartOpen("s_scOpen");

And here is the getCartOpen plug-in code that should be added to the plug-in code section.

/*
 * Plugin: getCartOpen
 */
s.getCartOpen=new Function("c",""
+"var s=this,t=new Date,e=s.events?s.events:'',i=0;t.setTime(t.getTim"
+"e()+1800000);if(s.c_r(c)||e.indexOf('scOpen')>-1){if(!s.c_w(c,1,t))"
+"{s.c_w(c,1,0)}}else{if(e.indexOf('scAdd')>-1){if(s.c_w(c,1,t)){i=1}"
+"else if(s.c_w(c,1,0)){i=1}}}if(i){e=e+',scOpen'}return e");

This line which goes in the calls to plug-ins section of the s_code.js file, calls the resetGetCartOpen plug-in and resets the scOpen event after a purchase takes place, allowing the scOpen event to be set again if the visitor decides to make another purchase during the same visit.

/*Reset Get Cart Open*/
s.events=s.resetGetCartOpen(); 

And here is the resetGetCartOpen plug-in code that should be added to the plug-in code section.

/*
 * Plugin: resetGetCartOpen
 */
s.resetGetCartOpen=new Function("" 
+"var s=this,t=new Date,e=s.events?s.events:'';t.setTime(t.getTime()+"
+"10000);if(e.indexOf('purchase')>-1){if(s.c_r('s_scOpen')||e.indexOf"
+"('scOpen')>-1){if(!s.c_w('s_scOpen','',t)){s.c_w('s_scOpen','',0);}"
+"}}return e");

For more information on when to use the scOpen and scAdd events, check out the Omniture Knowledge base Answer ID 440.

Enjoy!

Detect Silverlight and Flash with SiteCatalyst Plugin

Tracking your visitor’s Flash version is nothing new. I wrote about it a while ago in the Plugin To Detect Flash in SiteCatalyst post. What I have here is a little more powerful. This is the Rich Internet Application tracking plug-in.

RIA development is becoming more and more popular. Do your Visitors have Flash? What version? How about SilverLight? What version of that? Do they have both? Now you will know. What this SiteCatalyst plug-in does is detects the Silverlight version, and the Flash version. If you want to see it in action, fire up your Omniture JavaScript debugger on this page. You will see s.prop10 and s.prop11 (c10 and c11) populated with the Flash version and Silverlight versions your browser has installed. You will also see the Flash version populated in s.prop9 (c9). This is done using the original flash detection plug-in mentioned above.

Here is how to use it. First in the s_code.js file call the plug-in along with the variables you want to use to store the visitors rich application versions. Here I am using s.prop10 and s.prop11:

s.detectRIA('s_ria','prop10','prop11'); 

Then in the plug-in’s section add the plug-in code:

/*
 * Plugin: detectRIA v0.1 - detect and set Flash, Silverlight versions
 */
s.detectRIA=new Function("cn", "fp", "sp", "mfv", "msv", "sf", ""
+"cn=cn?cn:'s_ria';msv=msv?msv:2;mfv=mfv?mfv:10;var s=this,sv='',fv=-"
+"1,dwi=0,fr='',sr='',w,mt=s.n.mimeTypes,uk=s.c_r(cn),k=s.c_w('s_cc',"
+"'true',0)?'Y':'N';fk=uk.substring(0,uk.indexOf('|'));sk=uk.substrin"
+"g(uk.indexOf('|')+1,uk.length);if(k=='Y'&&s.p_fo('detectRIA')){if(u"
+"k&&!sf){if(fp){s[fp]=fk;}if(sp){s[sp]=sk;}return false;}if(!fk&&fp)"
+"{if(s.pl&&s.pl.length){if(s.pl['Shockwave Flash 2.0'])fv=2;x=s.pl['"
+"Shockwave Flash'];if(x){fv=0;z=x.description;if(z)fv=z.substring(16"
+",z.indexOf('.'));}}else if(navigator.plugins&&navigator.plugins.len"
+"gth){x=navigator.plugins['Shockwave Flash'];if(x){fv=0;z=x.descript"
+"ion;if(z)fv=z.substring(16,z.indexOf('.'));}}else if(mt&&mt.length)"
+"{x=mt['application/x-shockwave-flash'];if(x&&x.enabledPlugin)fv=0;}"
+"if(fv<=0)dwi=1;w=s.u.indexOf('Win')!=-1?1:0;if(dwi&&s.isie&&w&&exec"
+"Script){result=false;for(var i=mfv;i>=3&&result!=true;i--){execScri"
+"pt('on error resume next: result = IsObject(CreateObject(\"Shockwav"
+"eFlash.ShockwaveFlash.'+i+'\"))','VBScript');fv=i;}}fr=fv==-1?'flas"
+"h not detected':fv==0?'flash enabled (no version)':'flash '+fv;}if("
+"!sk&&sp&&s.apv>=4.1){var tc='try{x=new ActiveXObject(\"AgControl.A'"
+"+'gControl\");for(var i=msv;i>0;i--){for(var j=9;j>=0;j--){if(x.is'"
+"+'VersionSupported(i+\".\"+j)){sv=i+\".\"+j;break;}}if(sv){break;}'"
+"+'}}catch(e){try{x=navigator.plugins[\"Silverlight Plug-In\"];sv=x'"
+"+'.description.substring(0,x.description.indexOf(\".\")+2);}catch('"
+"+'e){}}';eval(tc);sr=sv==''?'silverlight not detected':'silverlight"
+" '+sv;}if((fr&&fp)||(sr&&sp)){s.c_w(cn,fr+'|'+sr,0);if(fr)s[fp]=fr;"
+"if(sr)s[sp]=sr;}}");
s.p_fo=new Function("n",""
+"var s=this;if(!s.__fo){s.__fo=new Object;}if(!s.__fo[n]){s.__fo[n]="
+"new Object;return 1;}else {return 0;}");

“We are considering developing some Silverlight applications. What percentage of our visitors have Silverlight, and if so what version?” Now you will have no problems answering that question.

If you would like more information about using SiteCatalyst with Silverlight, check out the white paper Using SiteCatalyst and Silverlight, available in the Omniture Knowledge Base.

Enjoy!