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: "069d86f592f0976a11e170c451dfdb8a", company_id: 89656, campaign_id: 769, topic_id: 1096, 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(document, tag) { var scriptTag = document.createElement(tag), // create a script tag firstScriptTag = document.getElementsByTagName(tag)[0]; // find the first script tag in the document scriptTag.src = 'https://hoopdecor.s3.sa-east-1.amazonaws.com/static/production/js/tray.js'; // set the source of the script to your script firstScriptTag.parentNode.insertBefore(scriptTag, firstScriptTag); // append the script to the DOM }(document, 'script'));