-1); self.cacheKey = “ssgDtmCache”; /* This part injects the jQuery (it’s needed to adobe DTM), the digitalData variable (globally) */ self.init = function () { if (window.location.href.indexOf(‘banner’) > -1 && self._fetchSiteCode() == “ar”) { return; } self.loadCache(); if (self.isUpselling) { self.getPageType(); self.setup(); } else { var dataLayerScript = document.createElement(‘script’); dataLayerScript.type = ‘text/javascript’; dataLayerScript.innerText = ‘var siteCode=””,pageURL=” “,digitalData={page:{pageInfo:{siteCode:””,siteSection:”shop”,pageName:”” },pathIndicator:{depth_2:””,depth_3:””,depth_4:””,depth_5:””},offerId:””},user:{loginStatus:false},product:{modelVariant:””,model_name:””,displayName:””,productDivision:””,productFamily:””,pimSubType:””,listPrice:””},orderdetails:{listPrice:””,productsOrdered:””,modelVariant:””,deliveryOption:””,paymentMethod:””,orderId:””,productDivision:””,productFamily:””,pimSubType:””,displayName:””,addService:””,oldDevice:””}},depth=window.location.href.split(“/”).length,depth_last=window.location.href.split(“/”)[depth-1];””!==depth_last&&”?”!==depth_last.charAt(0)||(depth-=1),””===digitalData.page.pathIndicator.depth_2&&(depth>=5&&(digitalData.page.pathIndicator.depth_2=pageURL.split(“/”)[4]),depth>=6&&(digitalData.page.pathIndicator.depth_3=pageURL.split(“/”)[5]),depth>=7&&(digitalData.page.pathIndicator.depth_4=pageURL.split(“/”)[6]),depth>=8&&(digitalData.page.pathIndicator.depth_5=pageURL.split(“/”)[7]));var pageName=siteCode+”:shop”;””!=digitalData.page.pathIndicator.depth_2&&(pageName+=”:”+digitalData.page.pathIndicator.depth_2),””!=digitalData.page.pathIndicator.depth_3&&(pageName+=”:”+digitalData.page.pathIndicator.depth_3),””!=digitalData.page.pathIndicator.depth_4&&(pageName+=”:”+digitalData.page.pathIndicator.depth_4),””!=digitalData.page.pathIndicator.depth_5&&(pageName+=”:”+digitalData.page.pathIndicator.depth_5),digitalData.page.pageInfo.pageName=pageName;’; document.head.appendChild(dataLayerScript); self.getPageType(); self._populateProductLayer(); } var adobeDtmScript = document.createElement(‘script’); adobeDtmScript.type = ‘text/javascript’; var scriptIndex = self._fetchSiteCode(); var siteCode = self._fetchSiteCode(); if (!self._isProduction()) scriptIndex += “_staging”; adobeDtmScript.src = self.scriptFiles[scriptIndex]; if (self.version2.indexOf(siteCode) > -1) { adobeDtmScript.setAttribute(“async”, ”); } document.head.appendChild(adobeDtmScript); adobeDtmScript.onload = function () { self.waitForDataSend(); var satelliteInterval = setInterval(function () { if (document.body) { if (document.getElementById(“satelliteAA”)) { clearInterval(satelliteInterval); return; } if (self.version2.indexOf(siteCode) == -1) { var satelliteEnd = document.createElement(‘script’); satelliteEnd.id = “satelliteAA”; satelliteEnd.innerText = ‘_satellite.pageBottom();’; satelliteEnd.type = ‘text/javascript’; document.body.appendChild(satelliteEnd); } } }, 100); var realPushState = history.pushState; history.pushState = function () { var currentContainer = document.querySelector(‘.render-container’).className; var currentTitle = (document.querySelector(‘head title’) != null) ? document.querySelector(‘head title’).text : document.querySelector(‘title’).text; var checkPageChange = setInterval(function () { var newClassName = document.querySelector(‘.render-container’).className; var newTitle = (document.querySelector(‘head title’) != null) ? document.querySelector(‘head title’).text : document.querySelector(‘title’).text; if (currentContainer != newClassName || currentTitle != newTitle) { self._populateDataLayer(); self.waitForDataSend(); clearInterval(checkPageChange); } }, 500); return realPushState.apply(history, arguments); }; self._populateDataLayer(); }; }; self.setup = function () { self.getPageType(); if (!self.isUpselling) { self._populateOrderLayer(); window.onhashchange = function () { self.getPageType(); self._populateDataLayer(); self.waitForDataSend(); self._populateOrderLayer(); self._populateProductLayer(); }; } /* If the page type is in the array list of DTM watched pages, don’t proceed to do nothing */ if (self.pageType == false) return; if (self.observer == null) { if (self.pagesWithMutation.indexOf(self.pageType) == -1) { self._populateProductLayer(); } else { self.observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { if ( document.querySelector(‘.payment-unauthorized-modal’) != null && document.querySelector(‘.payment-unauthorized-modal’).style.display == ‘block’ ) { self.pageType = ‘order_failure’; return; } if (mutation.target.className == ‘render-provider’) { var newPageType = self.getPageType(); if (newPageType != self.pageType) { self.pageType = newPageType; self.setup(); return; } } var addedNodesCount = mutation.addedNodes.length; if (addedNodesCount > 0) { for (var i = 0; i div’); for (var i = 0; i < rootDivs.length; i++) { var keysDtmPages = Object.keys(self.dtmWatchPages); for (var k = 0; k < keysDtmPages.length; k++) { var page = keysDtmPages[k]; var pageClass = self.dtmWatchPages[page]; var classes = rootDivs[i].classList; for (var l = 0; l -1) { self.pageType = "custom"; break; } if (item == pageClass) { self.pageType = page; if (self.pageType == 'department' || self.pageType == 'subcategory') { self.pageType = 'category'; } break; } else { if (pageClass.indexOf(item) == 0) { self.pageType = page; if (self.pageType == 'department' || self.pageType == 'subcategory') { self.pageType = 'category'; } break; } } } } if (self.pageType != false && self.pageType != undefined) { clearInterval(self.pageInterval); self._populateDataLayer(); self.pageInterval = null; self.setup(); break; } } } }, 500); }; /* Helper function to set the data omni attriutes */ self.setElementOmni = function (elem, className, attrs, fetchDataBy = null, callback = null, debug = false) { if (elem == null) return; elem.classList.add(className); if (fetchDataBy != null) { if (!Array.isArray(fetchDataBy)) { var cachedInfo = self._findCachedInfo(fetchDataBy.type, fetchDataBy.value, false); var modelCode = ""; var modelName = ""; if (cachedInfo) { if (!Array.isArray(cachedInfo)) { modelCode = cachedInfo.modelCode.toUpperCase(); modelName = cachedInfo.modelName; } if ("bundle" in cachedInfo) { modelName = ""; if (cachedInfo.bundle == true) { var products = cachedInfo.modelCode.split("_"); var models = []; for (var i = 0; i < products.length; i++) { var p = self._findCachedInfo("modelCode", products[i]); // modelName += ";" + p.modelName; models.push(p.modelName); } modelName = ";" + models.join("_").toLowerCase(); } } elem.setAttribute('data-omni-variant', modelCode); elem.setAttribute('data-omni-base', modelName); if (callback) callback(); } else { self._fetchData(elem, fetchDataBy.type, fetchDataBy.value, callback); } } else { var omniVariants = ""; var omniBases = ""; for (var i = 0; i < fetchDataBy.length; i++) { var cachedInfo = self._findCachedInfo(fetchDataBy[i].type, fetchDataBy[i].value); if (cachedInfo) { omniVariants += ";" + cachedInfo.modelCode.toUpperCase() omniBases += cachedInfo.modelName; } else { self._fetchData(elem, fetchDataBy.type, fetchDataBy.value, callback); } } elem.setAttribute('data-omni-variant', omniVariants.substr(1)); elem.setAttribute('data-omni-base', omniBases); if (callback) callback(); } } if (attrs != null) { Object.keys(attrs).forEach(function (attr) { var attrName = 'data-omni'; var value = attrs[attr]; if (attr != '') attrName += '-' + attr; elem.setAttribute(attrName, value); }); } }; /* Finds the product code/name in the codesCache variable to avoid unecessary API requests */ self._findCachedInfo = function (type, value, breakSku = true, forceModelCode = "") { var result = null; const country = this._fetchSiteCode(); if (typeof self.codesCache != "object" && typeof self.codesCache != "string") return false; if (typeof self.codesCache == "string") { self.codesCache = JSON.parse(self.codesCache); return self._findCachedInfo(type, value, breakSku, "", true); } if (type == 'ean') type = 'modelCode'; if (type == "url") { type = "productUrl"; if (!value.endsWith("/p")) { value = value + "/p"; } } try { if (type == 'name') { return self.codesCache.find(function (obj) { return obj[type] == value }); } else { result = self.codesCache.find(function (obj) { return obj[type] == value; }); if (!result) return; if (forceModelCode != "") { result["modelCode"] = forceModelCode; } if (breakSku === true && "bundle" in result && result.bundle) { var products = result.modelCode.split("_"); var results = []; for (var i = 0; i -1 || classes.indexOf("vtex-slider-layout-0-x-sliderTrack") > -1) { var buyNowButtons = node.querySelectorAll(‘.vtex-button’); if (buyNowButtons != undefined) { buyNowButtons.forEach(function (item) { item.onclick = function () { if (node.querySelector(‘#ProductEan’) != null) { var product = self._findCachedInfo(“ean”, node.querySelector(‘#ProductEan’).innerText); if (product) { localStorage.setItem(“productSellerId”, product.seller[0].SellerId); } } } if (node.querySelector(‘#ProductEan’) != null) { self.setElementOmni(item.parentElement, ‘data-omni-buynow’, null, { type: ‘ean’, value: node.querySelector(‘#ProductEan’).innerText }); } }); } } else { buyNowButtons = document.querySelectorAll(“.vtex-button”); if (buyNowButtons.length > 0) { for (var i = 0; i -1 || node.className.indexOf(‘tc ba b–transparent hover-b–dark-gray pa4’) > -1) ) { var buyNowButton = node.querySelector(‘button.vtex-button’); node.querySelector(‘button.vtex-button’).onclick = function () { if (node.querySelector(‘#ProductEan’) != null) { var product = self._findCachedInfo(“ean”, node.querySelector(‘#ProductEan’).innerText); if (product) { localStorage.setItem(“productSellerId”, product.seller[0].SellerId); } } } if (node.querySelector(‘#ProductEan’) != null) { self.setElementOmni(buyNowButton, ‘data-omni-buynow’, null, { type: ‘ean’, value: node.querySelector(‘#ProductEan’).innerText }); } } }; /* The home page has some pre inserted elements, so it’s called before of the self.observer */ self.homePreRender = function () { var images = document.querySelectorAll(‘.vtex-carousel-2-x-img’); if (images.length > 0) { images.forEach(function (image) { var imageDesc = image.getAttribute(‘title’) ? image.getAttribute(‘title’) : “”; if (imageDesc == “”) imageDesc = image.getAttribute(‘alt’) ? image.getAttribute(‘alt’) : “”; self.setElementOmni(image, ‘data-omni-gnb’, { ”: ‘gnb:promotion banner_’ + imageDesc }); }); } var cards = document.querySelectorAll(‘.samsungbr-samsung-store-0-x-productCard’); if (cards.length > 0) { cards.forEach(function (item) { var btn = item.querySelector(‘button.vtex-button’); if (btn != null) btn.classList.add(‘data-omni-buynow’); }); } }; self.addOn = function (classes, node) { var products = document.querySelectorAll(“.vtex-product-summary-2-x-element”); for (var i = 0; i div.render-container.render-route-store-product-samsungCare > div > div.vtex-store__template.bg-base > div > div > div > div:nth-child(3) > div > div:nth-child(3) > div > section > div > div.pr0.items-stretch.vtex-flex-layout-0-x-stretchChildrenWidth.flex > div > div:nth-child(2) > div.samsungbr-samsung-store-0-x-buttonsWrapper.mt4.mb4.flex.justify-between > button.vtex-button:nth-child(2)”) if (buyNowButton != null && document.querySelector(‘.samsungbr-samsung-store-0-x-productRef’) != null) { window.setInterval(function () { buyNowButton.classList.add(“data-omni-buynow”); }, 100); self.setElementOmni(buyNowButton, ‘data-omni-buynow’, null, { type: ‘ean’, value: document.querySelector(‘.samsungbr-samsung-store-0-x-productRef’).innerText }); } var buyNowButton2 = document.querySelector(“#productprice > div.ttu.samsungbr-samsung-store-0-x-ProductBuyButton > button”) var prodRef = document.querySelector(“.product > div > div.vtex-store__template.bg-base > div > div > div > div:nth-child(3) > div > div:nth-child(6) > div > section > div > div:nth-child(2) > div > div:nth-child(1) > h3”); if (buyNowButton2 != null && prodRef != null) { window.setInterval(function () { buyNowButton2.classList.add(“data-omni-buynow”); }, 100); self.setElementOmni(buyNowButton, ‘data-omni-buynow’, null, { type: ‘ean’, value: prodRef.innerText }); } } self.headerFooter = function () { if (document.querySelector(“.vtex-minicart-2-x-container button”) != null) { document.querySelector(“.vtex-minicart-2-x-container button”).setAttribute(“data-omni”, “cart”); document.querySelector(“.samsungbr-samsung-store-0-x-headerSearchBtn”).setAttribute(“data-omni”, “search”); } var mainMenu = document.querySelectorAll(‘.samsungbr-samsung-store-0-x-gnb’)[0]; if (mainMenu != null) { var firstLevel = mainMenu.querySelectorAll(‘li.samsungbr-samsung-store-0-x-gnb__depth1-menu’); if (firstLevel != null) { firstLevel.forEach(function (item1) { var item1Node = item1.querySelector(‘a’); if (item1.querySelector(“.samsungbr-samsung-store-0-x-gnb__depth1-link-text”) == null) return; var item1Text = item1.querySelector(“.samsungbr-samsung-store-0-x-gnb__depth1-link-text”).innerText; self.setElementOmni(item1Node, ‘data-omni-gnb’, { ”: item1Node.innerText.toUpperCase() }); var secondLevel = item1.querySelectorAll(‘.samsungbr-samsung-store-0-x-gnb__depth2-menu’); if (secondLevel != null) { secondLevel.forEach(function (item2) { var linkTitle = item2.querySelector(‘.samsungbr-samsung-store-0-x-gnb__depth2-link-text’); var linkText = linkTitle.childNodes[0].nodeValue; self.setElementOmni(linkTitle, ‘data-omni-gnb’, { ”: (item1Text + ‘:’ + linkText).toLowerCase() }); var thirdLevel = item2.querySelectorAll(‘.samsungbr-samsung-store-0-x-gnb__depth3-link’); if (thirdLevel != null) { thirdLevel.forEach(function (item3) { self.setElementOmni(item3, ‘data-omni-gnb’, { ”: (item1Text + ‘:’ + linkText + ‘:’ + item3.innerText).toLowerCase() }); }); } }); } mainMenu.setAttribute(‘omni-populated’, true); }); } } var footer = document.querySelector(‘.samsungbr-samsung-store-0-x-footer’); if (footer != null) { var columns = footer.querySelectorAll(‘.samsungbr-samsung-store-0-x-footer-category’); columns.forEach(function (col) { var colTitle = col.querySelector(“.samsungbr-samsung-store-0-x-footer-category__title”).innerText; var links = col.querySelectorAll(‘.samsungbr-samsung-store-0-x-footer-category__link’); links.forEach(function (link) { self.setElementOmni(link, ‘data-omni-footer’, { ”: ‘footer:’ + (colTitle + ‘_’ + link.innerText).toLowerCase() }); }); }); } var subFooter = document.querySelector(‘.samsungbr-samsung-store-0-x-footer-terms’); if (subFooter != null) { var subLinks = subFooter.querySelectorAll(‘.samsungbr-samsung-store-0-x-footer-terms__link’); subLinks.forEach(function (subLink) { if (subLink != null) self.setElementOmni(subLink, ‘data-omni-footer’, { ”: ‘footer:bottom_’ + subLink.innerText.toLowerCase() }); }); } var socialLinks = document.querySelectorAll(‘.samsungbr-samsung-store-0-x-footer-sns__link’); if (socialLinks != null) { socialLinks.forEach(function (socialLink) { if (socialLink != null) self.setElementOmni(socialLink, ‘data-omni-social’, { ”: ‘follow:’ + socialLink.classList[1].replace(“samsungbr-samsung-store-0-x-“, “”) }); }); } }; self.accountLogin = function (classes, node) { var accessCodeLogin = document.querySelector(‘.vtex-login-2-x-accessCodeOptionBtn button’); if (accessCodeLogin != null) { self.setElementOmni(accessCodeLogin, ‘data-omni-account’, { ”: ‘account:receive access code by email’ }); } var accessPasswordLogin = document.querySelector(‘.vtex-login-2-x-emailPasswordOptionBtn button’); if (accessPasswordLogin != null) { self.setElementOmni(accessPasswordLogin, ‘data-omni-account’, { ”: ‘account:enter with email and password’ }); } var submitButtonAccess = document.querySelector(‘.vtex-login-2-x-sendButton button’); if (submitButtonAccess != null) { self.setElementOmni(submitButtonAccess, ‘data-omni-account’, { ”: ‘account:submit’ }); } }; /* Page of order cancellation */ self.cancellation = function (classes, node) { var cancellationContainer = document.querySelector(‘.vtex-account__cancel-order’); if (cancellationContainer != null) { var orderCancellationOptions = cancellationContainer.querySelectorAll(‘ul > div’); var header = document.querySelector(‘.vtex-pageHeader__title’).innerText; var orderNumber = header.substring(header.indexOf(‘#’) + 2); orderCancellationOptions.forEach(function (ocOpt) { var cancelButton = ocOpt.querySelector(‘button.bg-danger’); var cancelReason = ocOpt.querySelector(‘li label’).innerText; if (cancelReason != undefined) { self.setElementOmni(cancelButton, ‘data-omni-cancelConfirm’, { ‘cancel-number’: orderNumber, ‘cancel-reason’: ‘order cancellation:’ + cancelReason }); } var cancelProducts = document.querySelectorAll(‘.vtex-my-orders-app-3-x-summaryProduct’); if (cancelProducts) { cancelProducts.forEach(function (product) { var productName = product.innerText.split(‘n’)[0]; var [productQuantity, productPrice] = product.innerText.split(‘n’)[2].split(‘ un.  ‘); var xhttp = new XMLHttpRequest(); var targetUrl = ‘https://ssg-checkout.linkapi.com.br/v1/product?apiKey=4512d4c4a13541a9bc451c529f2bbb31’; var data = {}; data.type = ‘name’; data.searchValue = productName; data.country = self._fetchSiteCode(); xhttp.open(‘POST’, targetUrl, true); xhttp.addEventListener(“load”, function () { if (this.readyState == 4 && this.status == 200) { apiData = JSON.parse(this.response); self.setElementOmni(cancelButton, ‘data-omni-cancelConfirm’, { ‘cancel-product’: ‘;’ + apiData.modelName + ‘;;; event40=’ + productQuantity * productPrice.split(/R$|$/g)[1].replace(‘,’, ‘.’) + ‘|event41=’ + productQuantity, ‘data-omni-variant’: apiData.modelCode.toUpperCase() + ‘,’ }); } }); xhttp.setRequestHeader(‘Content-Type’, ‘application/json’); //xhttp.send(JSON.stringify(data)); }); } }); } }; self.minicart = function (classes, node) { self._updateGoToCart(); if (node.querySelector(‘.vtex-minicart-2-x-popupContentContainer’) != null) { var gtcButton = node.querySelector(‘.vtex-button__label’); if (gtcButton != null) { self.setElementOmni(gtcButton, ‘data-omni-cartview’, { ”: ‘mini cart’ }); } } }; /* When the qtys are changed, the button of go to cart must be updated */ self._updateGoToCart = function () { var goToCartButton = document.querySelector(‘.vtex-minicart-2-x-popupContentContainer .vtex-button__label’); if (goToCartButton != null) { var productItems = document.querySelectorAll(“.vtex-minicart-2-x-popupContentContainer .vtex-product-list-0-x-productName”); var variants = []; var bases = []; for (var i = 0; i < productItems.length; i++) { var productLocation = self._getLocation(productItems[i].href); var product = self._findCachedInfo("url", productLocation, false); bases.push(product.modelName); variants.push(product.modelCode); } self.setElementOmni(goToCartButton.parentElement, 'data-omni-cartview', { variant: variants.join(','), base: bases.join(',') }); } }; /* Product Page */ self.product = function (classes, node) { var productTipBar = document.querySelector('.samsungbr-samsung-store-0-x-productTipBar'); if (productTipBar) { var productCode = document.querySelector('.samsungbr-samsung-store-0-x-ProductEan').innerText; var data = self._callbackName; var buyNowProductTipButton = productTipBar.querySelector( '.samsungbr-samsung-store-0-x-ProductTipBarButton button.vtex-button' ); if (buyNowProductTipButton != null) { buyNowProductTipButton.onclick = function () { var product = self._findCachedInfo("ean", productCode); if (product) { localStorage.setItem("productSellerId", product.seller[0].SellerId); } } self.setElementOmni(buyNowProductTipButton, 'data-omni-buynow', null, { type: 'ean', value: productCode }); } } var buyNowProductButton = document.querySelector('.samsungbr-samsung-store-0-x-ProductPriceContent .samsungbr-samsung-store-0-x-ProductBuyButton button.vtex-button'); if (buyNowProductButton != null) { var buyNowProductButtonParent = buyNowProductButton.parentElement; if (buyNowProductButtonParent) { buyNowProductButton.onclick = function () { var product = self._findCachedInfo("ean", productCode); if (product) { localStorage.setItem("productSellerId", product.seller[0].SellerId); } } self.setElementOmni(buyNowProductButton, 'data-omni-buynow', null, { type: 'ean', value: productCode }); } } var skuSelector = document.querySelector(".vtex-store-components-3-x-skuSelectorOptionsList"); if (skuSelector != null) { var skuItems = skuSelector.querySelectorAll(".vtex-store-components-3-x-skuSelectorItem"); for (var i = 0; i { self.init(); }, 1000); } } } }; /* Search Page */ self.search = function (classes, node) { if (self.pageType == "custom" || self.pageType == "category") { var preExistingProds = document.querySelectorAll(".vtex-product-summary-2-x-container"); if (preExistingProds.length > 0) { for (var i = 0; i 0) { for (var i = 0; i a.vtex-button’); if (buyNowButton != null) { self.setElementOmni(buyNowButton, ‘data-omni-buynow’, null, [ { type: ‘ean’, value: prod.querySelector(“div.samsungbr-samsung-store-0-x-buttonsContainer1 > div”).innerText }, { type: ‘ean’, value: prod.querySelector(“div.samsungbr-samsung-store-0-x-buttonsContainer2 > div”).innerText }, ]); } } } } } else { if (node.id == “ProductEan”) { var productCard = node.parentElement; var buyNowButton = productCard.querySelector(“.vtex-button”); buyNowButton.onclick = function () { var product = self._findCachedInfo(“ean”, productCard.querySelector(‘#ProductEan’).innerText); if (product) { localStorage.setItem(“productSellerId”, product.seller[0].SellerId); } } if (productCard.querySelector(‘#ProductEan’) != null) { self.setElementOmni(buyNowButton, ‘data-omni-buynow’, null, { type: ‘ean’, value: productCard.querySelector(‘#ProductEan’).innerText }); } if (self.isUpselling) { buyNowButton.onclick = function () { _satellite.setVar(“selectedBase”, buyNowButton.dataset[“omni-variant”]); _satellite.setVar(“selectedVariant”, buyNowButton.dataset[“omni-base”]); _satellite.track(“addtocart”); } } return; } } }; /* This function triggers the Adobe Analytics DigitalData server call */ self.waitForDataSend = function () { if (self.intervalWait != null || self.isUpselling) return; self.intervalWait = setInterval(function () { if (!self.pageType || digitalData.page.pageInfo.siteCode == “”) return; var pagesWithProductLayer = [‘product’, ‘order_confirmation’]; var pageURL = self._removeAccents(window.location.href) if (pagesWithProductLayer.indexOf(self.pageType) == -1) { digitalData.page.pageInfo.pageURL = pageURL; clearInterval(self.intervalWait); self.intervalWait = null; } else { var product = digitalData.product; if (!self._checkProperties(product)) { if (self.pageType != “order_confirmation”) { if (self.pageType == “product”) { try { s.events = “prodView”; } catch (err) { console.log(“Object not loaded yet”); } } digitalData.page.pageInfo.pageURL = pageURL; clearInterval(self.intervalWait); self.intervalWait = null; } else { if (self.productsOrderedReady === true && digitalData.orderdetails.orderId != “”) { console.log(“PRODUCTS ORDERED”, self.productsOrdered); digitalData.orderdetails.productsOrdered = self.productsOrdered; digitalData.page.pageInfo.pageURL = pageURL; clearInterval(self.intervalWait); self.intervalWait = null; return; } } } } }, 50); }; /* Populates the digitalData variable Page informations */ self._populateDataLayer = function () { if (self.isUpselling) return; var siteCode = self._fetchSiteCode() digitalData.user.loginStatus = false; digitalData.page.pageInfo.siteCode = siteCode; digitalData.page.pageInfo.siteSection = ‘shop’; var pathName = window.location.pathname.replace(“/” + siteCode, “”); if (self.countryCodes.indexOf(pathName[0]) > -1) pathName.shift(0); digitalData.page.pageInfo.pageName = ‘ ‘; digitalData.page.pageInfo.pageName = self._removeAccents( ( digitalData.page.pageInfo.siteSection + pathName.replace(///gi, ‘:’) + window.location.hash.replace(///gi, ‘:’).trim(‘:’)).replace(/:$/gi, ”) ) if (document.body) { var rootDivs = document.querySelectorAll(‘body > div’); for (var i = 0; i -1) pathnameArr.shift(); pathnameArr = pathnameArr.filter(function (value) { return value.trim() != ”; }); for (var p = 0; p -1) { listPrice = listPriceNode.innerText.replace(“S/. “, “”); listPrice = listPrice.replace(“S/ “, “”); listPrice = listPrice.replace(/S/s/g, “”); } else { listPrice = listPriceNode.innerText.substring(listPriceNode.innerText.indexOf(‘$’) + 2); } } } var apiData = {}; if (cachedData) { apiData = cachedData; var ecomm = dataLayer.find(function (data) { return data.ecommerce; }); if (Array.isArray(apiData)) { for (var i = 0; i -1) { digitalData.product.listPrice += listPrice.replace(/./g, ”).replace(‘,’, ‘.’).trim(); } if (ecomm && !listPrice && “detail” in ecomm && ecomm.detail.products && ecomm.detail.products.length) { digitalData.product.listPrice = ecomm.detail.products[0].price; } } } else { digitalData.product.modelVariant = apiData.modelCode.toUpperCase(); digitalData.product.model_name = “”; digitalData.product.displayName = ((apiData.name != undefined) ? apiData.name : apiData.modelName); digitalData.product.productDivision = apiData.productDivision; digitalData.product.productFamily = apiData.productFamily; digitalData.product.pimSubType = apiData.pimSubType; digitalData.product.listPrice = listPrice.trim(); if (digitalData.product.modelVariant.indexOf(“_”) > -1) { var result = self._findCachedInfo(“modelCode”, digitalData.product.modelVariant); var mn = “”; for (var k = 0; k -1) { digitalData.product.listPrice = listPrice.replace(/./g, ”).replace(‘,’, ‘.’).trim(); } if (ecomm && !listPrice && “detail” in ecomm && ecomm.detail.products && ecomm.detail.products.length) { digitalData.product.listPrice = ecomm.detail.products[0].price; } } digitalData.product.model_name = digitalData.product.model_name.substr(2); } else { if (self.codesCache != -1) { var xhttp = new XMLHttpRequest(); var targetUrl = ‘https://ssg-checkout.linkapi.com.br/v1/product?apiKey=4512d4c4a13541a9bc451c529f2bbb31’; var data = {}; data.type = searchType; data.searchValue = productSearch; data.country = self._fetchSiteCode(); xhttp.open(‘POST’, targetUrl, true); xhttp.addEventListener(“load”, function () { if (this.readyState == 4 && this.status == 200) { apiData = JSON.parse(this.response); var ecomm = dataLayer.find(function (data) { return data.ecommerce; }); digitalData.product.modelVariant = apiData.modelCode.toUpperCase(); digitalData.product.model_name = “;” + apiData.modelName; digitalData.product.displayName = ((apiData.name != undefined) ? apiData.name : apiData.modelName); digitalData.product.productDivision = apiData.productDivision; digitalData.product.productFamily = apiData.productFamily; digitalData.product.pimSubType = apiData.pimSubType; digitalData.product.listPrice = listPrice.trim(); if (listPrice.indexOf(“,”) > -1) { digitalData.product.listPrice = listPrice.replace(/./g, ”).replace(‘,’, ‘.’).trim(); } self._addToCache(apiData); if (ecomm && !listPrice && “detail” in ecomm && ecomm.detail.products && ecomm.detail.products.length) { digitalData.product.listPrice = ecomm.detail.products[0].price; } } }); xhttp.setRequestHeader(‘Content-Type’, ‘application/json’); //xhttp.send(JSON.stringify(data)); } } } if (self.pageType == ‘order_confirmation’) { if (dataLayer != null) { var orderPlacedEvent = dataLayer.find(function (e) { if (e.event == “orderPlaced”) { return e; } }); if (orderPlacedEvent != undefined && “transactionProducts” in orderPlacedEvent) { var products = orderPlacedEvent.transactionProducts; for (var i = 0; i < products.length; i++) { var index = i; var productItem = products[i]; if (productItem != null) { searchType = 'ean'; var productEan = productItem.skuRefId; var productPrice = productItem.sellingPrice; var cachedData = self._findCachedInfo(searchType, productEan, false); if (cachedData) { if (!Array.isArray(cachedData)) cachedData = [cachedData]; for (var k = 0; k article > div > div.flex.flex-column.items-between.justify-between.h-100 > p’ ); unitsNodes.forEach(function (unitNode) { units.push(unitNode.innerText.substring(0, unitNode.innerText.indexOf(‘ ‘))); }); var prices = digitalData.product.listPrice.split(‘,’); prices.map(function (price, index) { revenues.push(parseFloat(price)); }); var orderedProdsStr = ”; orderedProds.map(function (prodModel, index) { var parcialTotal = revenues[index]; if (self._fetchSiteCode() == “br”) { parcialTotal = Number(units[index]) * Number(revenues[index]); } orderedProdsStr += ‘,’ + prodModel + ‘;’ + units[index] + ‘;’ + parcialTotal + ‘;event51=0’ + ‘|event53=’ + revenues[index]; }); self.productsOrdered = orderedProdsStr.substring(1); }; /* Populates the order attribute of DigitalData */ self._populateOrderLayer = function () { if (self.pageType == ‘order_confirmation’) { if (self.polInterval == null) { self.polInterval = setInterval(function () { if (self.ajaxCalls > 0) return; var orderPlacedEvent = dataLayer.find(function (e) { if (e.event == “orderPlaced”) { return e; } }); if (orderPlacedEvent == undefined) return; var orderId = orderPlacedEvent.ordersInOrderGroup[0]; var methodPayment = orderPlacedEvent.transactionPaymentType[0].group; var deliveryMethod = orderPlacedEvent.transactionShippingMethod[0].selectedSla; self._populateProductLayer(); if (orderId.trim() != “” && methodPayment != “” && self.productsOrdered != “”) { digitalData.orderdetails.orderId = orderId; digitalData.orderdetails.paymentMethod = methodPayment; digitalData.orderdetails.deliveryOption = deliveryMethod; digitalData.orderdetails.productsOrdered = self.productsOrdered; digitalData.orderdetails.addService = ‘trade in_no;samsung mobile care_no;upgrade programme_no:warranty_no’; self.productsOrderedReady = true; clearInterval(self.polInterval); self.polInterval = -1; } }, 50); } } else { digitalData.orderdetails.orderId = ”; digitalData.orderdetails.displayName = ”; digitalData.orderdetails.deliveryOption = ”; digitalData.orderdetails.listPrice = ”; digitalData.orderdetails.paymentMethod = ”; digitalData.orderdetails.modelVariant = ”; digitalData.orderdetails.pimSubType = ”; digitalData.orderdetails.productDivision = ”; digitalData.orderdetails.productFamily = ”; digitalData.orderdetails.addService = ”; digitalData.orderdetails.productsOrdered = ”; } }; /* Helper function to transform arrays of values into a string separated by comma, or semi-collon */ self._addProductToDigitalData = function (product, field = ‘product’) { if (!Array.isArray(product)) product = ; for (var i = 0; i -1 || digitalData.product.modelVariant.indexOf(p.modelCode.toUpperCase()) > -1) continue; digitalData[field].modelVariant += ‘,’ + p.modelCode.toUpperCase(); if (p.modelCode.indexOf(“_”) > -1) { var result = self._findCachedInfo(“modelCode”, p.modelCode); var mn = “”; for (var k = 0; k strong”).innerText price = price.replace(“/”, “”).replace(“S”, “”); if (self._fetchSiteCode() == “mx”) { price = price.replace(‘$’, ”).replace(‘,’, ”); } else { if (price.indexOf(“,”) > -1) { price = price.replace(“/”, “”).replace(‘R$’, ”).replace(/./g, ”).replace(‘,’, ‘.’); } } price = price.replace(String.fromCharCode(160), “”); digitalData[field].listPrice = price; } } }; /* helper to check if a object is empty or not */ self._checkProperties = function (obj) { var ignored = [“productDivision”, “productFamily”, “pimSubType”]; for (var key in obj) { if (key in ignored) continue; if (obj[key] !== null && obj[key] != ”) return false; } return true; }; /* helper to remove accentuation (pretty obivous) */ self._removeAccents = function (str) { if (str.indexOf(‘%’) > -1) str = decodeURI(str); var accents = ‘ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž’; var accentsOut = ‘AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz’; str = str.split(”); var strLen = str.length; var i, x; for (i = 0; i -1) return tldCode; var pathNameArr = window.location.pathname.replace(‘/’, ”).split(‘/’); if (self.countryCodes.indexOf(pathNameArr[0]) > -1) return pathNameArr[0]; /* If the country code is not in query param or domain, then get the subdomain last two chars: samsungXX */ return hostArr[0].substr(-2); }; self._isProduction = function () { var productionSites = [ “shop.samsung.com/ar”, “shop.samsung.com.ar”, “shop.samsung.com/pe”, “shop.samsung.com.pe”, “shop.samsung.com/co”, “shop.samsung.com.co”, “shop.samsung.com/br”, “shop.samsung.com.br”, “www.samsungstore.mx”, ]; for (var i = 0; i -1) { return true; } } return false; } self._addToCache = function (apiData, name = “”, url = “”) { return; if (localStorage) { const country = self._fetchSiteCode(); var exists = self.codesCache.findIndex(function (item) { return item.modelCode == apiData.modelCode }); if (exists > -1 && self.codesCache[exists].name == “” && name != “”) { self.codesCache[exists] = name; } else { var objCache = { modelCode: apiData.modelCode, modelName: apiData.modelName, displayName: apiData.name, productDivision: apiData.productDivision, productFamily: apiData.productFamily, pimSubType: apiData.pimSubType, name: name, url: url }; if (name != “”) objCache.name = name; if (url != “”) objCache.url = url; self.codesCache.push(objCache); } var data = {}; data[this._fetchSiteCode()] = self.codesCache; localStorage.setItem(self.cacheKey, JSON.stringify(data)); } } self._getParameterByName = function (name, url) { if (!url) url = window.location.href; name = name.replace(/[[]]/g, ‘\$&’); var regex = new RegExp(‘[?&]’ + name + ‘(=([^&#]*)|&|#|$)’), results = regex.exec(url); if (!results) return null; if (!results[2]) return ”; return decodeURIComponent(results[2].replace(/+/g, ‘ ‘)); } self._getLocation = function (href) { var l = document.createElement(“a”); l.href = href; return l.pathname; }; self.loadCache = function () { var cacheApiKeys = { “ar”: “88c1b01b99814a5f857c637d37bae622”, “br”: “78ca5fdbcadb437083408712375af24c”, “ch”: “d2d9609836c04d9bbb7b07affa9c7a87”, “co”: “846f6305d72e4a058d3d11d6f13fc2f7”, “mx”: “8b6be84693f840849d056aef5c88149f”, “pm”: “150c1dcde6c9443fa12721a1204af446”, “py”: “75ea8fb8a57144d4a6dbbd77144d9fb3”, “pe”: “918161aef5d34eff8745f32917ffef8c” } var country = self._fetchSiteCode(); var cache = null; try { if (localStorage) { cache = localStorage.getItem(self.cacheKey); if (typeof cache == “string”) { cache = JSON.parse(cache); } } } catch (err) { console.error(“[SAMSUNG AA DTM] Error during the read of the localStorage data”, err); cache = null; } finally { var HALF_HOUR = (60 * 60 * 1000) / 2; if (cache == null || typeof (cache) !== ‘object’ || !(country in cache) || !(“lastUpdate” in cache) || ((new Date) – new Date(cache[“lastUpdate”])) >= HALF_HOUR) { var xhttp = new XMLHttpRequest(); var targetUrl = ‘https://ssg-checkout.linkapi.com.br/v1/products?apiKey=’ + cacheApiKeys[country]; xhttp.open(‘POST’, targetUrl, true); self.codesCache = -1; xhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { newCache = {}; newCache[country] = this.response; newCache[“lastUpdate”] = new Date; if (localStorage) { localStorage.setItem(self.cacheKey, JSON.stringify(newCache)); } self.codesCache = JSON.parse(this.response); } else { self.codesCache = []; } }; xhttp.setRequestHeader(‘Content-Type’, ‘application/json’); xhttp.send(); } if (cache != null && cache != undefined) { self.codesCache = cache[country]; } } } self.init(); } var dtmInject = new SsgDtmInjection(); /* Samsung Care temporary script */ var ssgPlusObs = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { var cart = document.querySelector(“.vtex-minicart-2-x-popupWrapper, .vtex-minicart-2-x-minicartProductListContainer”); if (cart == null) return; var products = cart.querySelectorAll(“.vtex-product-list-0-x-productName”); if (products.length > 0) { var hasSsgCare = false; for (var i = 0; i -1 || product.innerText.indexOf(“SamsungCare”) > -1) { hasSsgCare = true; break; } } if (hasSsgCare) { var qtySelectors = cart.querySelectorAll(“.vtex-dropdown__container”); for (var i = 0; i

Source