Question

I'm using omniture and tracking various properties to the "s" variable for tracking. The example code I'm following calls a function called s.clearVars() after each tracking event. But I get an error saying that clearVars is not a valid function. Does anyone know what I'm supposed to call to clear the tracking object? Or how to clear all properties from a javascript object.

Was it helpful?

Solution

Don't clear the entire s object, it contains a lot of functions that are listening to dom events and if you clear those, you'll lose a lot of functionality. I'm guessing you just want to clear all of the custom variables that you are populating on the page (props, evars, events, products, etc). The s.clearVars function is a "plugin" that Omniture consulting wrote that clears all of these values for you. You could contact your Omniture Account manager and ask him for the code, he may or may not give it to you, depending on whether he wants to sell you some consulting hours or if he knows what you are talking about, or you could do this yourself with a couple of simple loops:

function ClearVars(){
  for (var i=0; i < 75; i++) {
    s['prop'+i]='';
    s['eVar'+i]='';
    if(i<=5)
      s['hier'+i]='';
   }
   svarArr = ['pageName','channel','products','events','campaign','purchaseID','state','zip','server','linkName'];
  for (var i=0; i < svarArr.length ; i++) {
     s[svarArr[i]]=''; 
  }
}

Please note I haven't tested the code. Just shot it from the hip.

OTHER TIPS

Small Correction to Vector Frogs (amazing) code.

The second for loop need to have i=0 to clear out the pageName variable.

Great Script V_FRog!

this will reset the entire object as per your original request:

s=s_gi(s_account);

I think the best answer for how to clear the properties off of a JS object is to just create a new object all together.

Check out this post: How to quickly clear a Javascript Object?

s = {};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top