I am working with Omniture tagging and I've got numerous events on the page. In omniture, the base object is s
this object is created globally by Omniture.
The s
object has a number of "standard" variables that I like to set for it, url, pagetitle, time on site, what have you...
For each event I set one or two additional properties
I thought I was being really clever in writing functions like:
// s is a global variable create by omniture
function ClickFoo(){
var s_ = s; // make a copy of s which has all the standard vars
s_.event = "Click Foo"; // set X number of custom vars
s_.prop1 = "foo";
s_.t(); // the Omniture "submit event" function
}
function ClickBar(){
var s_ = s;
s_.event = "Click Bar";
s_.prop2 = "bar";
s_.t();
}
ClickFoo();
ClickBar();
// at this point, s.prop1 = "foo"
If the user clicks foo
then bar
the s_.prop1
object property is set on the bar submit.
I've been looking at the behavior of this stuff in the JS console and it seems that changes to s_ have an effect on the global object s.
Can anyone explain how the assignment is working so I don't make this mistake in future? Is there a quick way to do this correctly?