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}) { 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: "b5a36183cb21ceab906ca8db1c484060", company_id: 29363, campaign_id: 392, topic_id: 437, ecommerce: ecommerce, crosClient:getCookie("client_deal"), 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, } 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) window.verifyCupons(0); }); } jQuery( document ).ready(function() { var name = null; var email = null; var phone = null; var prod_name = null; var prod_sku = null; var products = []; var pedidoId = null; var siteControler = angular.element(document.querySelector('[ng-controller="siteController as ctrl"]')).scope(); var produtoController = angular.element(document.querySelector('[ng-controller="produtoController as ctrl"]')).scope(); function verifyRotes(){ for (var prop in rotas) { if (rotas[prop] == angular.element(document.querySelector('[ng-controller="siteController as ctrl"]')).scope().localizacao()) { return prop; } } } function watchCart(){ let lastTotal = siteControler.carrinho.pModel.carrinho.total; new MutationObserver(() => { const Total = siteControler.carrinho.pModel.carrinho.total; if (lastTotal !== Total) { lastTotal = Total; getProductsCart(); } }).observe(document, {subtree: true, childList: true}); } function getProductsCart(){ products = []; for (var i = 0; i < siteControler.carrinho.pModel.listaItens.length; i++) { var product = {name: siteControler.carrinho.pModel.listaItens[i].descricao_produto, sku: siteControler.carrinho.pModel.listaItens[i].id_variacao, quantity: siteControler.carrinho.pModel.listaItens[i].quantidade, value: siteControler.carrinho.pModel.listaItens[i].preco}; products.push(product); } if(products.length == 0){ products = "empty"; } console.log(products); self.sendEvent("shopping_cart",null,null,null,null,null,products,null,null,null,null,null); } function productView(){ var name = produtoController.pModel.variacaoSelecionada.produto.descricao; var sku = produtoController.pModel.variacaoSelecionada.produto.id; self.sendEvent("product_open",null,null,null,null,null,null,name,sku,null,null,null,null); } function checkout(){ var name = sessao.pModel.cliente.nome; var email = sessao.pModel.cliente.email; var phone = sessao.pModel.cliente.fone; var cep = sessao.pModel.enderecoSelecionado.cep; self.sendEvent("checkout",name,email,phone,cep,null,null,null,null,null,null,null,null); } var trying = setInterval(myTimer, 1000); function myTimer() { if(typeof siteControler.carrinho.pModel != "undefined" && typeof siteControler.carrinho.pModel.carrinho != "undefined"){ clearInterval(trying); run(); } } function run(){ if (verifyRotes() == "home" || verifyRotes() == "home2") { watchCart(); self.sendEvent(null,null,null,null,null,null,null,null,null,null,null,null,null); } else if(verifyRotes() == "carrinho"){ watchCart(); } else if(typeof produtoController !== "undefined"){ productView(); watchCart(); } else if(verifyRotes() == "finalizar"){ checkout(); setTimeout(function(){ if(document.querySelector(".hoopcompany_cta")) document.querySelector(".hoopcompany_cta").style.display = "none"; if(document.querySelector("#buttonWidget")) document.querySelector("#buttonWidget").style.display = "none"; if(document.querySelector("#hoopWidgetCoupon")) document.querySelector("#hoopWidgetCoupon").style.display = "none"; }, 1500); } else if(location.pathname.split("/")[1] == "finalizado"){ var pedidoId = location.pathname.split("/")[2]; self.sendEvent("purchase",null,null,null,null,null,null,null,null,null,pedidoId,null,null); } else{ watchCart(); } } });