Created
October 9, 2025 18:42
-
-
Save meganmcchesney/81616d260cb21ab055f4402efded9955 to your computer and use it in GitHub Desktop.
ADI - Web Experimentation script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| readme.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// Prepare global variables
window.personas = window.personas || [];
window.roles = window.roles || [];
// Attach navigation listener
window.navigation.addEventListener("navigate", (event) => {
console.group("Optimizely Configured Commerce: Navigation");
console.log("Activating for URL: ", window.location.pathname + window.location.search + window.location.hash);
window.optimizely.push({ type: "activate" });
console.groupEnd();
});
// Fetch session, cart, and branch data, then update Optimizely with combined attributes
function updateOptimizelyAttributes() {
Promise.all([
fetch('/api/v1/sessions/current').then(r => r.json()),
fetch('/api/v1/carts/current').then(r => r.json()),
fetch('/api/v1/ShopMyBranch').then(r => r.json())
]).then(([sessionData, cartData, branchData]) => {
window.optimizely = window.optimizely || [];
}
updateOptimizelyAttributes();
function findPropertyCaseInsensitive(obj, targetKey) {
if (!obj) return null;
const keys = Object.keys(obj);
const foundKey = keys.find(key => key.toLowerCase() === targetKey.toLowerCase());
return foundKey ? obj[foundKey] : null;
}
//New code starting 092525 for Scroll Event
// --- Optimizely Web: Scroll Depth Tracking (gated) ---
// Initializes only if an allow-listed experiment is active OR a variation sets a flag.
// Sends scroll_25 / scroll_50 / scroll_75 / scroll_100 once per pageview.
(function () {
if (window.__optlyScrollBootstrapInstalled) return;
window.__optlyScrollBootstrapInstalled = true;
})();
``