For organizations where alignment is critical, there are a few technical considerations and adjustments to make in order to best align to metrics in the two systems.
Misalignment can always be traced back to when the two client tools are dispatching the impressions/conversions back to their respective servers.
This challenge can be solved by aligning the two event calls as closely as possible.
Optimizely offers the hold/send API for managing this.
Since Adobe is loaded first, we know the s variable is already defined by the time Optimizely Project JavaScript runs. We don't have to await it being defined. Hold events at the top of Project JS, register an Adobe pre-track handler that calls sendEvents.
window.optimizely = window.optimizely || [];
window.optimizely.push({type: "holdEvents"});
s.registerPreTrackCallback(function() {
// right before Adobe call
window.optimizely.push({type: "sendEvents"});
});Add the holdEvents call to the top of Project JavaScript
window.optimizely = window.optimizely || [];
window.optimizely.push({type: "holdEvents"});Add this JavaScript code to your Adobe Analytics s_code.js file in the plug-ins section (or directly on your page after the s_code.js loads, but before the Adobe Analytics s.t(); call is made)
window.optimizely = window.optimizely || [];
window.optimizely.push({type: "sendEvents"});Uses
setIntervalpolling
We need to wait for the s variable to be defined in order to register our pre-track handler. We can wrap our registerPreTrackCallback invocation with waitUntil, in order to guarantee that it can be called on the s variable.
window.optimizely = window.optimizely || [];
window.optimizely.push({type: "holdEvents"});
var waitFor = function(v, cb, expiredCb) {
var POLL,
WAIT_TIMEOUT = 2000,
POLL_INTERVAL_MS = 50;
if(typeof v !== 'undefined') {
cb(v);
return;
}
POLL = setInterval(function() {
if(typeof v !== 'undefined') {
cb(v);
clearInterval(POLL)
}
}, POLL_INTERVAL_MS);
setTimeout(function() {
clearInterval(POLL);
typeof expiredCb !== 'undefined' ? expiredCb() : null;
}, WAIT_TIMEOUT);
}
waitFor(window.s, function(sVariable) {
sVariable.registerPreTrackCallback(function() {
// right before Adobe call
window.optimizely.push({type: "sendEvents"});
});
}, function() {
// Adobe s variable polling expired, release events
window.optimizely.push({type: "sendEvents"});
});