var loadScript = function(url, callback){ var script = document.createElement("script"); script.src = url; script.type = "text/javascript"; script.id = "jquerynew"; document.getElementsByTagName("body")[0].appendChild(script); document.getElementById("jquerynew") .addEventListener("load", function() { callback(); }); }; var myAppJavaScript = function(jQuery){ function uuidv4() { return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)); } function splitString(stringToSplit, separator) { var arrayOfStrings = stringToSplit.split(separator); } function serialize(obj, prefix) { var str = [], p; for (p in obj) { if (obj.hasOwnProperty(p) && obj[p]) { var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p]; str.push((v !== null && typeof v === "object") ? serialize(v, k) : encodeURIComponent(k) + "=" + encodeURIComponent(v)); } } return str.join("&"); } function setCookie(cname, cvalue, exdays,domain=null) { var d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); var expires = "expires=" + d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/;"+(domain?("domain="+window.location.hostname.replace(window.location.hostname.split(".")[0]+".","")):""); } function getCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(";"); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == " ") { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } function isEmpty(obj) { return obj && Object.keys(obj).length === 0 && Object.getPrototypeOf(obj) === Object.prototype; } if(getCookie("hoopCliente")&&!getCookie("client_deal")){ setCookie("client_deal",getCookie("external_ref"),90,1); } if(!getCookie("hoopCliente")&&getCookie("client_deal")){ setCookie("hoopCliente",1,90); } function sendEvent({status = null, name = null, email = null, phone = null, cep = null, cpf = null, prods = null, prod_name = null, prod_sku = null, prod_img = null, prod_category = null, variation_id = null , prod_id = null, id = null, final_value = null, reference = null,client_id = null, ecommerce = null,url_key=null}) { if (getCookie("external_ref") == "") setCookie("external_ref", uuidv4(), 90); var external_ref = getCookie("external_ref"); var utms={}; var queryString = window.location.search; var urlParams = new URLSearchParams(queryString); urlParams.forEach(function(value, key) { if(key=="campaign_id") key="ad_"+key; utms[key] = value; if(key=="hclid"){ setCookie("hoopCliente", 1, 90); } }); if(!isEmpty(utms)){ utms.url = window.location.href; var utc = new Date().toJSON().slice(0,10).replace(/-/g,"/"); utms.date = utc.split("/")[2] + "/" + utc.split("/")[1] + "/" + utc.split("/")[0]; } function readTextFile(file, callback) { var rawFile = new XMLHttpRequest(); rawFile.overrideMimeType("application/json"); rawFile.open("GET", file, true); rawFile.onreadystatechange = function() { if (rawFile.readyState === 4 && rawFile.status == "200") { callback(rawFile.responseText); } } rawFile.send(null); } if(getCookie("isBot")===""){ readTextFile("https://s3-sa-east-1.amazonaws.com/hoopdecor/static/production/files/user-agents-blocked.json", function(text){ var isBot=text.includes(navigator.userAgent); setCookie("isBot",isBot?1:0,90); }); } const data = { api_token: "d0a8fe94b264bf9f29af4b5328ae6c83", company_id: 28532, campaign_id: 341, topic_id: 661, ecommerce: ecommerce, crosClient:getCookie("client_deal"), fbp:getCookie("_fbp"), status: status, external_ref: external_ref, name: name, email: email, phone: phone, cep: cep, cpf: cpf, prods: prods, final_value:final_value, utms: utms, prod_sku: prod_sku, prod_id: prod_id, prod_name: prod_name, prod_img: prod_img, prod_category: prod_category, variation_id: variation_id, reference: reference, url: window.location.href, id: id, client_id:client_id, url_key:url_key, } if(getCookie("isBot")!=="1") fetch("https://hoopdecor.com/api/external/ecommerces?"+serialize(data)) .then(response => response.json()) .then(response => { var oldActions=JSON.parse(getCookie("hoop_actions")?getCookie("hoop_actions"):"[]"); var newActions=oldActions.concat(response); var newValue=[]; try{ newValue=JSON.stringify(newActions); if(newValue.length>1600){ newValue.shift(); } }catch (e) { newValue=[]; } setCookie("hoop_actions",newValue, 10); if(response.length){ setCookie("tracking_id",response[0].deal_id, 10); window.verifyCupons(0); } }); } function HoopTrackModel() { this.plataform = "Vnda"; this.selectedBuy = null; this.data = { name: null, email: null, phone: null, cep: null, cpf: null, cart: [], prod_name: null, prod_sku: null, variation_id: null, prod_img: [], id: null, final_value: null, prod_category:[] } this.functions = { self: this, getCart(){ let self = this.self; if (document.querySelector("#vndajs").getAttribute("data-cart")) { JSON.parse(document.querySelector("#vndajs").getAttribute("data-cart")).items.forEach((item)=>{ self.data.cart.push({"name": item.product_name, "sku": item.variant_sku, "quantity": item.quantity, "value": item.price, "variation_id":item.id , "img": [item.image_url.replace("//","https://")]}); }); } }, getClient(){ let self = this.self; if (document.querySelector("#vndajs").getAttribute("data-cart")) { self.data.client_id=JSON.parse(document.querySelector("#vndajs").getAttribute("data-cart")).client_id; } }, getCategory(){ var array = [] jQuery.each(jQuery(".crumb"),function(index,el){ array.push(jQuery(el).text().trim()); }); return array.slice(1,-1); }, getPage(){ if (jQuery("body").data("page") == "product") { return "product"; }else if(window.location.pathname.split("/").includes("concluido")){ return "purchase"; } else if(window.location.pathname.split("/")[1] == "checkout"){ return "checkout"; } } } this.triggers = { self: this, buy(){ const self = this.self; jQuery("[data-form-product]").on("submit", function(event) { const sku = jQuery(this).find('input[name="sku"]').val(); const quantity = jQuery(this).find('input[name="quantity"]').val() let variantSelected = null; vnda.variants.variant_list.forEach((variant) =>{ if (variant.sku == sku) { variantSelected = variant; } }); self.selectedBuy = variantSelected; self.data.cart.push({"name": variantSelected.full_name, "sku": variantSelected.sku, "quantity": quantity, "value":variantSelected.sale_price, "img":variantSelected.image_url?[variantSelected.image_url.replace("//","https://")]:[jQuery("[property='og:image']").attr("content")]}); jQuery(self).trigger("shopping_cart"); }); }, removeProduct(){ const self = this.self; jQuery('[data-event="removeFromCart"]').on("click", function(){ const info = JSON.parse(jQuery(this).attr("data-event-json")); self.data.cart.forEach((item,index)=>{ if (info.id == item.sku) { self.data.cart.splice(index,1); jQuery(self).trigger("shopping_cart"); } }); }); }, getCartPage(){ const self = this.self; self.data.client_id=__NEXT_DATA__.props.pageProps.client.id; self.data.cart_id=__NEXT_DATA__.props.pageProps.cart.id; self.data.cart = __NEXT_DATA__.props.pageProps.cart.items.map(p=>{return{sku: p.variant_sku, name: p.product_name, quantity: p.quantity, value: p.price, img: [p.image_url.replace("//","https://")]}}); }, productOpen(){ const self = this.self; self.data.prod_name = vnda.variants.variant_list[0].full_name; self.data.prod_sku = vnda.variants.variant_list[0].sku; self.data.variation_id = vnda.variants.variant_list[0].id; self.data.prod_img = vnda.variants.variant_list[0].image_url?[vnda.variants.variant_list[0].image_url.replace("//","https://")]:[jQuery("[property='og:image']").attr("content")]; jQuery(self).trigger("product_open"); }, order(){ const self = this.self; self.data.id = dataLayer.find(obj=>obj.ecommerce).ecommerce.purchase.actionField.id; self.data.final_value = dataLayer.find(obj=>obj.ecommerce).ecommerce.purchase.actionField.revenue; jQuery(self).trigger("purchase"); }, cart(){ const self = this.self; jQuery(self).trigger("shopping_cart"); } } this.observers = { self: this, watchCheckout(){ const self = this.self; let send=0; new MutationObserver(() => { let email=document.getElementsByClassName("description ")[0]?.textContent; let data=document.getElementsByClassName("description ")[1]?.textContent; if(email && email.indexOf("@")){ self.data.email =email; } if(data && data.indexOf("CPF:")){ data=data.split(" - "); self.data.name =data[0]; self.data.phone =data[2]; } if(!send&&self.data.name && self.data.email && self.data.phone){ send=1; jQuery(self).trigger("checkout"); } }).observe(document, {subtree: true, childList: true}) }, watchCart(){ const self = this.self; let countEvents = VNDA_EVENTS.reduce((ac,e)=>{return (e.event == "Update product quantity"?ac+1:ac)},0); new MutationObserver(() => { if (VNDA_EVENTS.reduce((ac,e)=>{return (e.event == "Update product quantity"?ac+1:ac)},0) != countEvents) { countEvents = VNDA_EVENTS.reduce((ac,e)=>{return (e.event == "Update product quantity"?ac+1:ac)},0); const product = VNDA_EVENTS.reduce((ac,e)=>{ if(e.event == "Update product quantity") ac = e; return ac; },0); self.data.cart.find(p=>p.sku==product.sku).quantity = product.quantity; jQuery(self).trigger("shopping_cart"); } }).observe(document, {subtree: true, childList: true}) }, watchCopy(){ let copy= document.querySelector('h1.product-name') if(copy) copy.oncopy=function(){ jQuery(window.hoopTrack).trigger("copy"); }; } } this.events = function(){ jQuery(this).on("shopping_cart", function(event){ sendEvent({status : "shopping_cart", prods : this.data.cart.length?this.data.cart:"empty", ecommerce: "vnda"}); }); jQuery(this).on("product_open", function(event, eventType){ sendEvent({status : "product_open", prod_name : this.data.prod_name, prod_sku : this.data.prod_sku, prod_img : this.data.prod_img, prod_category : this.data.prod_category, ecommerce: "vnda",variation_id:this.data.variation_id}); }); jQuery(this).on("copy", function(event, eventType){ sendEvent({status : "copy", prod_name : this.data.prod_name, prod_sku : this.data.prod_sku, prod_img : this.data.prod_img, prod_category : this.data.prod_category, ecommerce: "vnda",variation_id:this.data.variation_id}); }); jQuery(this).on("checkout", function(event, eventType){ sendEvent({status : "checkout", name : this.data.name, email : this.data.email, phone : this.data.phone, cep : this.data.cep, prods : this.data.cart.length?this.data.cart:"empty", ecommerce: "vnda"}); }); jQuery(this).on("purchase", function(event, eventType){ sendEvent( {status : "purchase",id : this.data.id, final_value : this.data.final_value, ecommerce: "vnda"}); }); jQuery(this).on("clear", function(event, eventType){ sendEvent({}); }); } this.init = function(){ let page = this.functions.getPage(); this.events(); switch (page){ case "product": this.triggers.productOpen(); this.triggers.buy(); this.functions.getCart(); this.observers.watchCopy(); this.functions.getClient(); setTimeout(this.triggers.cart.bind(this.triggers), 1500); break; case "checkout": this.triggers.getCartPage(); jQuery(this).trigger("checkout"); this.observers.watchCheckout(); break; case "purchase": this.triggers.order(); break; default: // jQuery(this).trigger("clear"); this.functions.getCart(); this.functions.getClient(); setTimeout(this.triggers.cart.bind(this.triggers), 1500); break; } } } window.hoopTrack = new HoopTrackModel(); window.hoopTrack.init(); } var target = [2, 1, 1]; var current = typeof jQuery === "undefined" ? [0,0,0] : $.fn.jquery.split(".").map(function(item) { return parseInt(item); }); if (current[0] < target[0] || (current[0] == target[0] && current[1] < target[1])) { loadScript("//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js", function(){ Bugsnag.start({ apiKey: "09eda96dc4d7852fb978301b2241f4c9" }); window.jQueryNoConflict = jQuery.noConflict(true); try{ myAppJavaScript(window.jQueryNoConflict); } catch(e){ Bugsnag.notify(e); } }); } else { myAppJavaScript(jQuery); }