Today I wanted to discuss one of the optional parameters in the s.t and s.tl function calls within Omniture: The Custom Object Parameter.
Business Requirement
There are a lot of times with Omniture implementations when you need to send a beacon call (be it a full page view or just a custom link call) but don’t want to overwrite the values that are already in the ‘s’ object. For example, let’s say that you have a page that has several features on it where you need to send a custom link call for each feature when it is used. For each one of these features, you need to send the page name on a prop for a reference to the page that the feature was used on. Now let’s assume that there is also a feature on that page that needs to send a full page view, such as a help document that is displayed in a modal popup div.
The Problem
The problem in the above example is that anytime the help document loads, you will be changing the s.pageName variable, thus making it difficult to set the pageName into a traffic variable any time one of the features on the page is used. Let me demonstrate -
/* Page Name set on page load */
s.pageName="Home Page";
/* Feature on page used */
s.linkTrackVars('prop1');
s.prop1=s.pageName;
s.tl(this,'o','Feature Used'); //Page Name 'Home Page' successfully sent in Custom link call
/* Help popup div displayed */
s.pageName='Help Popup';
s.t();
/*Another Feature on page used */
s.linkTrackVars('prop1');
s.prop1=s.pageName;
s.tl(this,'o','Feature Used'); //Page Name 'Home Page' is no longer available and 'Help Popup' is sent instead
Solution
There are a couple of different ways to solve this problem. One of these solutions is to store the page name in a JavaScript variable so that you can reference it for later. However, this means you are storing the value twice on the page (at least until the visitor uses the help document).
Another solution is one that Omniture has already provided for you: the custom object parameter. You can create an object of any name with the same properties as the s object and pass it in to the s.tl and s.t functions without actually overwriting the values in the s object. This object can be sent as the first and only parameter on the s.t function and the optional fourth parameter on the s.tl function. Let’s look at an example.
/* Option 1: Create your own defined object and pass it into the function call */
// Custom link call for a used Feature
var customObject;
customObject.linkTrackVars = 'prop1';
customObject.prop1 = s.pageName; //Notice that the property on the object has the same name: 'prop1'
s.tl(this,'o','Feature Used',customObject); //Notice the use of the optional Fourth parameter for the custom object
// Page View call for the Help Popup
var customObject;
customObject.pageName = 'Help Popup';
s.t(customObject); // Notice the use of the optional parameter for the custom object
/* Option 2: Create an anonymous object defined in the function call (Preferred method) */
// Custom link call for a used feature
s.tl(this,'o','Feature Used',{
linkTrackVars:'prop1',
prop1:s.pageName
});
// Page View call for the Help Popup
s.t({
pageName:'Help Popup'
});
That’s it!! Using this simple little trick can save you a lot of time and headache in your implementation endeavors. I have actually made this a standard implementation technique for all of my custom link calls in order to allow for any flexibility that may be needed in the future.
Any thoughts or comments? Please let me know below. Thanks for reading.
If you have an Omniture tip or trick that you would like to share please let us know! We’ll feature you in our next Omniture Tips and Tricks post!
Pingback: Tim Patten » Blog Archive » Omniture Tip’s and Tricks ~ The Custom Object Parameter - In the Pursuit of Endless Insight into Web Analytics and Development
I couldn’t get any of this code to work. Does it require a certain level of Omniture code to work?
thanks, Craig
Hi Craig,
Sorry to hear that. This functionality has been available since H.15 and I have successfully tested it in the latest version of the s_code. What version are you currently running?
Thanks, Tim
You need to explicitly make customObject an actual Object.
Use: var customObject = {};
What about loading an mbox into a modal where all the variables are pulled in via ajax and dont exist at page load? My dilemma i’m hitting now is omniture’s document.write it performs. I need to be able to load the mbox into a div on a modal window i’m opening, but the product information isn’t known until the user clicks the product.
thoughts?