Update: To further illustrate my discussion below I have created an example page with nothing but a basic form and Omniture code with the Form Analysis plugin. Clicking the submit button with Omniture enabled should alert the Form Object but notice in Firefox, Safari, and Opera the Window Object is instead alerted. Internet Explorer alerts the Form Object in both cases as it should.
How to fix the issue: Omniture has to fix this issue. Somewhere in their code they need to change a direct function call to use that function’s apply method instead so that they can keep the this reference targeting the same object.

I wanted to write about an issue I’ve been debugging with a particular sport’s team site and the issue ended up stemming from a conflict in Omniture’s Site Catalyst Form Analysis Plug-in with existing form validation code on the site. The form in question had a hard-coded event listener that (simplified) looks like this:

<form id="addForm" onsubmit="return validateForm(this)" method="post">
     // form contents here

The function validateForm is being passed one argument, this, which is a reference to the form it’s attached to. This function validates the form and returns true or false (with false halting form submission.) When the Omniture code runs, it removes any listeners on the form and ques them up to run after Omniture’s listener. Since the Omniture code is running in the global namespace (window object) the this keyword of our form validation function is now referencing the global window object instead of the form it was originally attached to. Unfortunately, because of it’s obscured nature – I couldn’t find the specific mechanism directly causing the issue in their code during my Firebug debug session. I have tracked it down to the Form Analysis 2.0 plugin, which tracks form success/abandonment rates. I can see that when the Omniture code is in the page all references to this change to the window object, which is pretty horrific since this is the basis of writing object-oriented code.

Since I can’t see Omniture’s code to fix it, the only end solutions are:

  • Removing all references to the this keyword in the site-specific code
  • Remove the Omniture plugin.

I’m pushing for the latter as developers shouldn’t have to code around an analytics tool, and the Omniture guys really need to fix this. I’ve looked around and found a related Omiture conflict with this in the jQuery JavaScript framework:

“Conflict with Omniture javascript”

As well as Dean Edward’s addEvent2 script:

“Anyone know why this code would conflict with Omniture’s SiteCatalyst javascript files?”

For the above two scenarios, you may be able to move the omniture include above the other js includes so that it loads first, in my situation, I don’t have access to certain parts of the site so my options are limited. Hopefully this page will serve as a resource to others though, who also run across it.