Hook | Custom Integrations – Data Out

Event hooks

For full details, read: WT.addEventHandler.

Optimize’s internal events system surfaces listenable events that you can hook into. Typically, users do this to then relay information on to other systems.

// Hook into pageview event
WT.addEventHandler("pageview", function(e){
    if(e.state && e.state == "success"){
        // your code here
        // Useful properties available:
        // e.target.params.testAlias // ta_something
        // e.target.params.r_runID // the object ID for your test/target/baseline 
        // e.target.params.experimentID || e.target.params.r_personalizedID || "none" // The experiment ID, if one is available, for the content viewed.
    }
});

The object “e” contains some useful indicators of which test triggered a Pageview – these are listed above in the code.

Note: By default, we do not send friendly names to the browser, only IDs.

Using this code

The preinit section of your tag is the best place to put any integrations using these event hooks – the preinit section runs before any of these events trigger.