Optimize Event Handlers

The Webtrends CAPI file (wt_capi.js) allows you to execute script code when certain Optimize events happen.

You can bind to Optimize CAPI events in either the page HTML or via Optimize pre-process code, pre/post-render scripts, or streamed-in level content. When embedding the event handler code directly in the test page, it is required to use the addEventHandler method after the wt_capi.js file is loaded, but prior to the WTOptimize.setup() call.

Keep in mind that timing is everything when binding to event handlers. Some Optimize events only fire once. If you bind to an event that has already fired, your code/callback will never happen.


To bind to an Optimize CAPI event, use the following syntax shown below.

WTOptimize.addEventHandler(WTEvent.<event name here>, <callback reference here>);

Event Types


Register a callback on the Optimize conversion event. This is useful for sending an analytics track to your analytics solution.

function wto_onconversion() {
// Your code here
WTOptimize.addEventHandler(WTEvent.CONVERSION, wto_onconversion);

Register a callback for when Optimize reveals the page to the visitor. Use to run JavaScript code to further adjust element styling (after Optimize has rotated content in), or binding DOM event handler code to tested elements.

function wto_onreveal() {
// Your code here
WTOptimize.addEventHandler(WTEvent.RENDER, wto_onreveal);

Register a callback for when an error condition happens in Optimize. A common use for this scenario is performing element styling that may have been dependent on Optimize not erroring out. The snippet shown below registers against several events not described above, but does encompass all possible error scenarios in Optimize.

function wto_onerror() {
// Your code here
WTOptimize.addEventHandler(WTEvent.INVALID, wto_onerror);
WTOptimize.addEventHandler(WTEvent.DONE, null, wto_onerror);
WTOptimize.addEventHandler(WTEvent.PAGEVIEW, null, wto_onerror);


Tracked pageviews and conversions are considered Optimize events; however there are exceptions to this rule.

Scenario Considered an Optimize Event?
Page view shows the following:

Test Experiment

Segmented Experiment

Target Experiment




Page view does not show an Optimize experiment:

Test times out and shows default content

wt_capi.js and WTOptimize.setup() exist on page that is not associated with an active test



Page Load Conversions

A conversion page with wt_capi.js and WTOptimize.setup() is loaded in browser and tracks an Optimize page view

The conversion page with wt_capi.js and WTOptimize.setup() is loaded in browser, but does not track due to timeout



Click Conversions

Visitor clicks a page element with an Optimize conversion tag

A test page with several links tagged with Optimize conversion tag is loaded in browser, but no links are clicked



Custom Scripted Conversions

If triggered for an active test or target


Throttled Test Traffic

Tests using a segment to “throttle” traffic, throwing traffic into a catch-all segment showing non-challenger or default content

Yes, but that event usage is subtracted from the monthly total.