Skip to content

Instantly share code, notes, and snippets.

@bwll
Created December 10, 2016 00:10
Show Gist options
  • Save bwll/433431511a9fb220997c731467c5d224 to your computer and use it in GitHub Desktop.
Save bwll/433431511a9fb220997c731467c5d224 to your computer and use it in GitHub Desktop.
Callback function for activating a Page in Optimizely X when Demandbase object has loaded
function callbackFn(activate, options) {
// Interval in ms for polling Demandbase visitor data
var POLL_INTERVAL = 50;
// Max number of poll attempts
var MAX_POLL_COUNT = 5;
var pollCount = 0;
function poll() {
pollCount++;
if (window.optimizely &&
window.optimizely.get('visitor') &&
optimizely.get('visitor')['vendor.demandbase'] &&
!options.isActive) {
activate();
} else if (pollCount < MAX_POLL_COUNT) {
setTimeout(poll, POLL_INTERVAL);
}
}
poll();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment