Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript / omniture - how to clear all properties of an object (s object)

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.

like image 279
mheavers Avatar asked Dec 09 '22 05:12

mheavers


1 Answers

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.

like image 156
vectorfrog Avatar answered Apr 27 '23 00:04

vectorfrog