Skip to content

Instantly share code, notes, and snippets.

@dannycroft
Created August 2, 2012 13:24
Show Gist options
  • Select an option

  • Save dannycroft/3237084 to your computer and use it in GitHub Desktop.

Select an option

Save dannycroft/3237084 to your computer and use it in GitHub Desktop.
Show Optimizely Settings
(function(){
// Return if the page hasn't loaded
if (document.readyState !== "complete") { alert("Please wait for the page to load"); return; };
// Return if Optimizely isn't available
if (typeof window.optimizely !== "object") { alert("Optimizely isn't available"); return; }
// Collect and assign optimizely data
var data = window.optimizely.data;
var experiments = data.experiments;
var state = data.state;
var active = state.activeExperiments;
var visitor = data.visitor;
// Start wrapper group
console.group("Optimizely Information");
// Log data about all active experiments
console.group("Active Experiments");
for (var i = 0; i < active.length; i++) {
console.group(experiments[active[i]].name);
console.log("id: " + active[i]);
console.log("variation: " + state.variationNamesMap[active[i]]);
console.groupEnd();
}
console.groupEnd();
// Log data about the current visitor
console.group("Visitor Information");
// Loop through each property of the visitor object
for (var detail in visitor) {
// If vistor has a property
if (visitor.hasOwnProperty(detail)) {
// If visitor property is an object
if (typeof visitor[detail] === "object") {
// For each property in vistor property (nested objects)
for (var item in visitor[detail]) {
// If the property isn't just a colon
if (item.length > 2 && typeof visitor[detail][item] !== "function") {
// Logout property information
console.log(item + ": " + (visitor[detail][item] || "n/a"));
}
}
} else {
// Logout property information
console.log(detail + ": " + visitor[detail]);
}
}
}
console.groupEnd();
// End wrapper group
console.groupEnd();
alert("Please open your console");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment