(() => {
if (!window.__ElevarIsGtmSuiteCalled) {
window.__ElevarIsGtmSuiteCalled = true;
const init = () => {
window.__ElevarDataLayerQueue = [];
window.__ElevarListenerLoadQueue = [];
if (!window.dataLayer) window.dataLayer = [];
}
init();
window.__ElevarTransformItem = event => {
if (typeof window.ElevarTransformFn === "function") {
try {
const result = window.ElevarTransformFn(event);
if (typeof result === "object" && !Array.isArray(result) && result !== null) {
return result;
} else {
console.error("Elevar Data Layer: `window.ElevarTransformFn` returned a value " + "that wasn't an object, so we've treated things as if this " + "function wasn't defined.");
return event;
}
} catch (error) {
console.error("Elevar Data Layer: `window.ElevarTransformFn` threw an error, so " + "we've treated things as if this function wasn't defined. The " + "exact error is shown below.");
console.error(error);
return event;
}
} else {
return event;
}
}
window.ElevarPushToDataLayer = item => {
const enrichedItem = {
event_id: window.crypto.randomUUID ? window.crypto.randomUUID() : String(Math.random()).replace("0.", ""),
event_time: new Date().toISOString(),
...item
};
const transformedEnrichedItem = window.__ElevarTransformItem ? window.__ElevarTransformItem(enrichedItem) : enrichedItem;
const listenerPayload = {
raw: enrichedItem,
transformed: transformedEnrichedItem
};
const getListenerNotifyEvent = () => {
return new CustomEvent("elevar-listener-notify", {
detail: listenerPayload
});
};
if (transformedEnrichedItem._elevar_internal?.isElevarContextPush) {
window.__ElevarIsContextSet = true;
window.__ElevarDataLayerQueue.unshift(transformedEnrichedItem);
if (window.__ElevarIsListenerListening) {
window.dispatchEvent(getListenerNotifyEvent());
} else {
window.__ElevarListenerLoadQueue.unshift(listenerPayload);
}
} else {
window.__ElevarDataLayerQueue.push(transformedEnrichedItem);
if (window.__ElevarIsListenerListening) {
window.dispatchEvent(getListenerNotifyEvent());
} else {
window.__ElevarListenerLoadQueue.push(listenerPayload);
}
}
if (window.__ElevarIsContextSet) {
while (window.__ElevarDataLayerQueue.length > 0) {
window.dataLayer.push(window.__ElevarDataLayerQueue.shift());
}
}
}
const configElement = document.getElementById("elevar-gtm-suite-config");
if (!configElement) {
console.error("Elevar: DL Config element not found");
return;
}
const initialProductAnchorElements = [];
const setElements = () => {
if (initialProductAnchorElements.length === 0) {
const freshElements = Array.from(
document.querySelectorAll(
`a[href*="/products/"]:not(a[href*="/collections/products/"]:not(a[href*="/collections/products/products/"]))`
)
);
if (freshElements.length === 0) {
initialProductAnchorElements.push(null);
} else {
initialProductAnchorElements.push(...freshElements);
}
}
};
if (document.readyState === "loading") {
document.addEventListener("readystatechange", setElements);
} else {
setElements();
}
const config = JSON.parse(configElement.textContent);
const script = document.createElement("script");
script.type = "text/javascript";
script.src = config.gtm_suite_script;
script.async = false;
script.defer = true;
script.onerror = () => {
console.error("Elevar: DL JS script failed to load");
};
script.onload = async () => {
if (!window.ElevarGtmSuite) {
console.error("Elevar: `ElevarGtmSuite` is not defined");
return;
}
const cartData = {
attributes:{},
cartTotal: "0.0",
currencyCode:"USD",
items: []
}
;
await window.ElevarGtmSuite.handlers.cartAttributesReconcile(
cartData,
config.event_config.save_order_notes,
config.consent_enabled,
config.apex_domain
);
if (config.event_config.user) {
const data = {cartTotal: "0.0",
currencyCode:"USD",};
window.ElevarGtmSuite.handlers.user(data);
}
if (config.event_config.product_add_to_cart_ajax) {
window.ElevarGtmSuite.handlers.productAddToCartAjax(
config.event_config.save_order_notes,
config.consent_enabled,
config.apex_domain
);
}
if (config.event_config.cart_reconcile) {
window.ElevarGtmSuite.handlers.cartItemsReconcile(cartData);
}};
document.head.appendChild(script);
}
})();
class='template-password'>