function anonymous(inputs,input,model,_model,initialModel,experienceId,_experienceId,domRef,experience,debug ) { return (async () => { if (!model.id.includes('C3_7b06a4f5-4cb9-817e-8004-d88f6ffc4845')) return; window.ZMAGS_ANALYTICS_API = window.ZMAGS_ANALYTICS_API || {}; ZMAGS_ANALYTICS_API.EXPERIENCE_NAME_CACHE = {}; ZMAGS_ANALYTICS_API.INTERSECTION_OBSERVER = null; ZMAGS_ANALYTICS_API.PLUS_ICONS = [""] ZMAGS_ANALYTICS_API.MUTATION_OBSERVER = null; ZMAGS_ANALYTICS_API.EVENTS_FIRED = ZMAGS_ANALYTICS_API?.EVENTS_FIRED || { "click_events": [] }; function trackLinkEvent(linkURL) { // Document number from URL const urlParts = window.location.href.split('/'); const linkLocation = urlParts[urlParts.length - 3]; // 'cigar-com-select' part of the URL const documentNumber = urlParts[urlParts.length - 2]; // Document number from URL const targetUrlParts = linkURL.split('/'); const targetLinkLocation = targetUrlParts[targetUrlParts.length - 3]; // 'cigar-com-select' part of the URL const targetDocumentNumber = targetUrlParts[targetUrlParts.length - 2]; // Prefix with 'm-' for mobile if applicable let prefix = $(document).width() < 990 ? "m-" : ""; // eVar5/prop5 - Link Location s.prop5 = s.eVar5 = prefix + linkLocation; console.log("eVar5 -> prop5 = " + s.prop5); // eVar6/prop6 - Shop (document number) s.prop6 = s.eVar6 = prefix + "shop " + targetDocumentNumber; console.log("eVar6 -> prop6 = " + s.prop6); // eVar7/prop7 - Concatenation of link location and document number s.prop7 = s.eVar7 = s.eVar5 + ">" + s.eVar6; console.log("eVar7 -> prop7 = " + s.eVar7); // Fire the event s.t(); // Sends the data to Adobe Analytics } function trackProductFindingEvent() { // Document number from URL const urlParts = window.location.href.split('/'); const linkLocation = urlParts[urlParts.length - 3]; // Captures the '2047124' from URL // 'cigar-com-select' part of the URL const documentNumber = urlParts[urlParts.length - 2]; // Prefix with 'm-' for mobile if applicable let prefix = $(document).width() < 990 ? "m-" : ""; // eVar14 - browse s.eVar14 = 'Browse'; console.log("eVar14 = Browse"); // eVar62 - Shop (document number) s.eVar62 = linkLocation; console.log("eVar62 = " + linkLocation); // Fire the event s.t(); // Sends the data to Adobe Analytics } ZMAGS_ANALYTICS_API.getExperienceName = function (contextWindow, experienceId) { if (!ZMAGS_ANALYTICS_API.EXPERIENCE_NAME_CACHE[experienceId]) { const expname = contextWindow?.[`${experienceId}_1_STATE`]?.viewer?.experiences?.[experienceId]?.model?.name || ""; ZMAGS_ANALYTICS_API.EXPERIENCE_NAME_CACHE[experienceId] = expname; } return ZMAGS_ANALYTICS_API.EXPERIENCE_NAME_CACHE[experienceId]; } ZMAGS_ANALYTICS_API.customEvent = function (eventData, isDisplayed) { window.appEventData = window.appEventData || []; //appEventData.push({ // "event": "Content click occurred", // "contentDisplayed": { // "contentInteraction": [ // { // eventData, // "isDisplayed": isDisplayed // } // ] // } //}); } ZMAGS_ANALYTICS_API.trackLink = function (link, experienceName) { const url = link.href; const scene = link.closest("[class^='scene-']")?.className || ""; if (!document.hidden) { //window.appEventData = window.appEventData || []; //appEventData.push({ //"event": "CTA Link Clicked", // "linkInfo": { // "linkContainer": '', // "linkId": 'Select Options', // "linkPage": top.window.location.href // } //}); trackLinkEvent(url); trackProductFindingEvent(); ZMAGS_ANALYTICS_API.EVENTS_FIRED['click_events'].push(event) } }; ZMAGS_ANALYTICS_API.trackSceneChange = function (viewerContainer, experienceId, experienceName) { const activeScene = viewerContainer.querySelector('[class^="scene-"][style*="visibility: inherit"][style*="opacity:"]:not(.scene-background, .scene-overlay), [class^="scene-"][style*="visibility: visible"]:not(.scene-background, .scene-overlay), [class^="scene-"][style*="visibility:visible"]:not(.scene-background, .scene-overlay)')?.className || ""; const ordinal = viewerContainer?.dataset?.ordinal || 1 console.log(`experienceId: `, experienceId, activeScene) if (!ZMAGS_ANALYTICS_API.EVENTS_FIRED[`${experienceId}_${ordinal}_scene_${activeScene}`] && !document.hidden) { const event = { "zmags_exp": experienceName, "zmags_int": "view", "zmags_scene": activeScene } // window.appEventData = window.appEventData || []; // appEventData.push({ // "event": "Content Listing Displayed", // "listingDisplayed": { // "listing": [ // { // "content": { // "contentID": experienceId, // "contentTitle": experienceName // }, // "isDisplayed": true // } // ] // } // }); ZMAGS_ANALYTICS_API.EVENTS_FIRED[`${experienceId}_${ordinal}_scene_${activeScene}`] = true } } ZMAGS_ANALYTICS_API.trackExperienceSceneView = function (viewerContainer, experienceId) { const observerConfig = { attributes: true, childList: true, }; const sceneContaniers = Array.from(viewerContainer.querySelectorAll('.scene-background') || []).map(ele => { if (!ele.parentNode.dataset.analyticsInitiated) { ele.parentNode.dataset.experienceId = experienceId ele.parentNode.dataset.analyticsInitiated = true return ele.parentNode } return null }).filter(ele => ele !== null) sceneContaniers.forEach((container) => { const experienceId = container.dataset.experienceId; const experienceName = ZMAGS_ANALYTICS_API.EXPERIENCE_NAME_CACHE[`${experienceId}`] ZMAGS_ANALYTICS_API.trackSceneChange(container, experienceId, experienceName) container.addEventListener("click", function (event) { const anchorTag = event.target?.closest('a') || {} if (anchorTag.tagName === "A") { ZMAGS_ANALYTICS_API.trackLink(anchorTag, `${experienceId} - ${experienceName}`) } }) ZMAGS_ANALYTICS_API.MUTATION_OBSERVER.observe(container, observerConfig) }) } ZMAGS_ANALYTICS_API.setupTracking = function (context, contextWindow) { const viewerContainers = context.querySelectorAll('[class^="zmags-viewer-container"][data-zmags-initiated]:not([data-analytics-initiated])'); for (let viewerContainer of viewerContainers) { const experienceId = viewerContainer.dataset.experience; ZMAGS_ANALYTICS_API.getExperienceName(contextWindow, experienceId); ZMAGS_ANALYTICS_API.INTERSECTION_OBSERVER.observe(viewerContainer) viewerContainer.dataset.analyticsInitiated = true } const iframes = Array.from(context.querySelectorAll("iframe:not([data-analytics-error])")) iframes.forEach(function (iframe) { try { const iframeDoc = iframe.contentDocument || iframe.contentWindow.document; const iframeWindow = iframe.contentWindow; ZMAGS_ANALYTICS_API.setupTracking(iframeDoc, iframeWindow); } catch (e) { iframe.dataset.analyticsError = true console.log("Failed to access iframe, probably because it is from a different origin."); } }); } function isElementInViewport(element) { const sceneContainer = element.querySelectorAll('[class="scene-background"]')[0] || element const rect = sceneContainer.getBoundingClientRect(); const viewportHeight = window.innerHeight || document.documentElement.clientHeight; return ((rect.top >= 0 && rect.top <= viewportHeight) || (rect.bottom >= 0 && rect.bottom <= viewportHeight)); } const mutationObserver = ZMAGS_ANALYTICS_API.MUTATION_OBSERVER || new MutationObserver((mutationsList, observer) => { const mutation = mutationsList[0] if (!mutation) return; const viewerContainer = mutation.target const experienceId = viewerContainer.dataset.experienceId; const experienceName = ZMAGS_ANALYTICS_API.EXPERIENCE_NAME_CACHE[`${experienceId}`] if (isElementInViewport(viewerContainer)) { setTimeout(() => { ZMAGS_ANALYTICS_API.trackSceneChange(viewerContainer, experienceId, experienceName) }, 500) } }); if (!ZMAGS_ANALYTICS_API.MUTATION_OBSERVER) ZMAGS_ANALYTICS_API.MUTATION_OBSERVER = mutationObserver; function handleIntersection(entries) { entries.forEach(entry => { if (entry.isIntersecting) { const viewerContainer = entry.target const experienceId = viewerContainer.dataset.experience; ZMAGS_ANALYTICS_API.trackSceneChange(viewerContainer, experienceId, ZMAGS_ANALYTICS_API.EXPERIENCE_NAME_CACHE[`${experienceId}`]) ZMAGS_ANALYTICS_API.trackExperienceSceneView(entry.target, experienceId) } }); } const options = { root: null, rootMargin: '0px', threshold: 0 }; const observer = ZMAGS_ANALYTICS_API.INTERSECTION_OBSERVER || new IntersectionObserver(handleIntersection, options); if (!ZMAGS_ANALYTICS_API.INTERSECTION_OBSERVER) ZMAGS_ANALYTICS_API.INTERSECTION_OBSERVER = observer setInterval(function () { ZMAGS_ANALYTICS_API.setupTracking(document, window); }, 500); })() }