let referrer_value = ""; let referrer = document.referrer; let currentUrl = window.location.href; let saveLocalStorage = ""; if (currentUrl.indexOf("source") === -1 && currentUrl.indexOf("utm_source ") === -1) { if (referrer.indexOf("google.com") !== -1) { if ( currentUrl.indexOf("/assine/") !== -1 || currentUrl.indexOf("/assinar/") !== -1 || currentUrl.indexOf(".com.br/ofertas") !== -1 || currentUrl.indexOf("assine.abril.com.br") !== -1 ) { saveLocalStorage = "google_assinar"; } if (currentUrl.indexOf("gclid") !== -1) { saveLocalStorage = "google_cpc"; } if ( currentUrl.indexOf("gclid") === -1 && currentUrl.indexOf("/assine/") === -1 && currentUrl.indexOf("/assinar/") === -1 && currentUrl.indexOf(".com.br/ofertas") === -1 && currentUrl.indexOf("assine.abril.com.br") === -1 ) { saveLocalStorage = "google_organico"; } } else { if (referrer === "") { saveLocalStorage = "direto"; } if (referrer !== "" && referrer.indexOf(".abril.com.br") === -1) { saveLocalStorage = "referrer_externo"; } } if (saveLocalStorage !== "") { referrer_value = saveLocalStorage; } } var AbrilCustomDimension = (function() { var min_leitura = 60000; var inicio_leitura = performance.now(); let sendMetricStatus = false; let limite_leitura = false; let crm_id = ''; console.log("limite_leitura: " + limite_leitura); console.log("sendMetricStatus: " + sendMetricStatus); setTimeout(setLimiteLeitura, min_leitura); window.addEventListener("beforeunload", sendNavigationDataBq); function setLimiteLeitura() { limite_leitura = true; console.log("limite_leitura " + limite_leitura); } function sendCustomDimension(dimension) { if (typeof dimension == 'undefined') { return; } if (typeof dimension.dimension29 !== 'undefined') { if (dimension.dimension29 != 'N/A') { gaUserProperties({"direitos_assinante": dimension.dimension29}); gaSendEvent({ "category":"Usuário autenticado", "action":"Direitos assinante", "label":dimension.dimension29, "dimensionsGA4": { "dimension29": dimension.dimension29 } }); } } if (typeof dimension.dimension30 !== 'undefined') { if (dimension.dimension30 != 'N/A') { gaUserProperties({ "tipo_cadastro": AbrilCustomDimension.tipoAssinante(), "tipo_assinatura": AbrilCustomDimension.tipoAssinatura() }); gaSendEvent({ "category": "Usuário autenticado", "action": "Tipo de assinatura", "label": dimension.dimension30 }); } } } function tipoAssinante(){ let tipo = "nao logado"; if( AbrilCustomDimension.verifyCookie(AbrilCustomDimension.sessionPrefix()) !== '' ){ tipo = "cadastrado"; const prodUser = localStorage.getItem('AbrilProductsUser'); if(prodUser !== null && prodUser.length > 0){ tipo = "assinante"; } } return tipo; } function tipoAssinatura(){ let tipo = "sem assinatura"; let prodUser = localStorage.getItem('AbrilProductsUser'); let combo = logged_paywall_combo[0].split(","); let digital = logged_paywall[0].split(","); if( prodUser !== null ){ if(prodUser.length > 0){ direito = prodUser.split(","); for(let i = 0; i < digital.length; i++){ if (direito.indexOf(digital[i].toString()) != -1 && digital[i] != "") { tipo = "digital"; } } for(let i = 0; i < combo.length; i++){ if (direito.indexOf(combo[i].toString()) != -1 && combo[i] != "") { tipo = "combo"; } } } } return tipo; } function tipoLogin(){ let tipo = 'abril'; const userAssets = JSON.parse(localStorage.getItem('abrilAssetsUser')); if( userAssets !== null ){ if(userAssets.tipo_login !== ""){ tipo = userAssets.tipo_login; } } return tipo; } function userID(){ let crm = null; const userAssets = JSON.parse(localStorage.getItem('abrilAssetsUser')); if( userAssets !== null ){ if(userAssets.crm > 0){ crm = userAssets.crm; } } return crm; } function verifyCookie(c_name, cpar) { var name = c_name + "="; var ca = document.cookie.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 && cpar == undefined) { return c.substring(name.length, c.length); } if (c.indexOf(name) == 0 && cpar) { var arr = []; str = c.substring(name.length, c.length); str = str.split(":"); for (var j = 0; j < str.length; j++) { a = str[j].split("="); arr[a[0]] = a[1]; } if (arr[cpar]) { return arr[cpar]; } } } return ""; } function sendNavigationData() { console.log("sendMetricStatus: " + sendMetricStatus); console.log("limite_leitura: " + limite_leitura); if (!sendMetricStatus && limite_leitura) { console.log("caiu no limite!!!!!!!!"); return sendNavigationDataBq(); } console.log("Espera min_leitura"); return setTimeout(sendNavigationData, 5000); } function getCookieIdGlobal(c_name) { if (document.cookie.length > 0) { c_start = document.cookie.indexOf(c_name + "="); if (c_start != -1) { c_start = c_start + c_name.length + 1; c_end = document.cookie.indexOf(";", c_start); if (c_end == -1) { c_end = document.cookie.length; } return unescape(document.cookie.substring(c_start, c_end)); } } return ""; } function getLocalStorage(c_name){ return localStorage.getItem(c_name); } function setCookieGlobalId(c_name,value){ var y = new Date(); y.setTime(y.getTime() + (365*24*60*60*1000)); expires = "expires="+ y.toUTCString(); document.cookie = c_name+"="+value+";" + expires + ";domain=.abril.com.br;path=/"; console.log("Gerou Cokie: " + value); } function setLocalStorage(c_name,value){ localStorage.setItem(c_name, value); console.log("Gerou LocalStorage: " + value); } function persistIdGlobal() { if ( verifyCrossDomainIdGlobal('abrilUserId') == true ){ return; } if( typeof gaGlobal != 'undefined'){ clientId = gaGlobal.vid; console.log("Gerou ID pelo gaGlobal: "+clientId); var hoje = new Date().toDateString(); var value = `${clientId}|${hoje}`; setCookieGlobalId('abrilUserId',value); setLocalStorage('abrilUserId',value); return; } if (typeof gtag !== 'undefined'){ gtag('get', 'G-0HTYQ9ZBSJ', 'client_id', (clientId)=> { console.log("Gerou ID pelo GA4: "+clientId); var hoje = new Date().toDateString(); var value = `${clientId}|${hoje}`; setCookieGlobalId('abrilUserId',value); setLocalStorage('abrilUserId',value); //localStorage.setItem('abrilUserId', `${clientId}|${hoje}`); }) return; } setTimeout(function(e) { AbrilCustomDimension.persistIdGlobal(); }, 1000); } function parseIdGLobalValue(value){ if(idData = value.split("|")){ return idData; } return null; } function verifyCrossDomainIdGlobal(c_name) { var idDataCokie = getCookieIdGlobal(c_name); var idDataStorage = getLocalStorage(c_name); if( idDataCokie && idDataStorage ){ if( idDataCokie !== idDataStorage ){ console.log("IdGlobal: checar ID mais antigo"); let dataCokie = parseIdGLobalValue(idDataCokie); let dataStorage = parseIdGLobalValue(idDataStorage); console.log( `${idDataCokie} ${idDataStorage}` ); console.log( new Date(dataCokie[1]) < new Date(dataStorage[1]) ); if( new Date(dataCokie[1]) < new Date(dataStorage[1]) ){ setLocalStorage(c_name,idDataCokie); console.log('gravou valor do cokie no storage' + idDataCokie); return true; }else{ setCookieGlobalId(c_name,idDataStorage); console.log('gravou valos do storage no cokie ' + idDataStorage); return true; } } console.log("IdGlobal: IDs iguais"); return true; } if( idDataCokie && !idDataStorage ){ console.log("IdGlobal: Apenas id cokie"); setLocalStorage(c_name,idDataCokie); return true; } if( !idDataCokie && idDataStorage ){ console.log("IdGlobal: Apenas id storage"); setCookieGlobalId(c_name,idDataStorage); return true; } return false; //new Date(new Date().setDate(new Date().getDate() - 5)).toDateString(); } function getUnicIdGlobal() { //let idCokie = getCookieIdGlobal('abrilUserId'); //verifyCrossDomainIdGlobal('abrilUserId'); let id = null; if ( verifyCrossDomainIdGlobal('abrilUserId') == true ){ let idStorage = localStorage.getItem('abrilUserId'); let dataId = null; if ( idStorage ) { if(idData = idStorage.split("|")){ id = idData[0]; dataId = idData[1] } console.log("getUnicIdGlobal: " + id); return id; } } // possivel forçar gerar id; console.log("getUnicIdGlobal: " + id); return false; } function checkUnicIdGlobal() { if (getUnicIdGlobal()) { console.log("checkUnicIdGlobal: " + getUnicIdGlobal()); return true; } console.log("checkUnicIdGlobal: " + getUnicIdGlobal()); return false; } async function sendNavigationDataBq(assinou = false, postAssineId = false, userId = '', bloqueado = false) { if (sendMetricStatus) { return; } var fim_leitura = performance.now(); var tempo_leitura = (fim_leitura - inicio_leitura) / 1000; sendMetricStatus = true; let post_id = '5822828'; let marca = 'veja'; let timestamp = new Date().getTime(); let autenticado = false; let codTipoIdentificador = "gaId"; assinou = false; if (verifyCookie("AbrilProductsUser") != '') { autenticado = true; } if(!autenticado){return;} if (AbrilCustomDimension.checkUnicIdGlobal()) { userId = AbrilCustomDimension.getUnicIdGlobal(); } else { AbrilCustomDimension.persistIdGlobal(); userId = AbrilCustomDimension.getUnicIdGlobal(); } if (typeof AbrilPaywall != 'undefined') { bloqueado = AbrilPaywall.ShowPaywall; } console.log("Tempo de leitura: " + tempo_leitura); console.log("user id: " + userId); console.log("post id: " + post_id); console.log("marca: " + marca); if (userId == null || userId == '' || typeof userId == 'undefined' || post_id == null || post_id == '' || typeof post_id == 'undefined' || marca == null || marca == '' || typeof marca == 'undefined') { console.log("Dados CW incompletos"); return; } let userStorage = JSON.parse(localStorage.getItem('abrilAssetsUser')); if(typeof userStorage === "object" && userStorage !== null){ if(typeof userStorage.crm === "number" ){ AbrilCustomDimension.crm_id = userStorage.crm; } } let slug = '/'; var pathSlug = location.pathname; var pathComponentsSlug = pathSlug.match(/([^\/]+)/g); if( pathComponentsSlug ){ if( pathComponentsSlug[pathComponentsSlug.length - 1] === 'mobile' ){ pathComponentsSlug.pop(); } slug = pathComponentsSlug.pop().split(";")[0]; } let data = { 'marca': marca, 'post_id': post_id, 'user_id': userId, 'bloqueado': bloqueado, 'assinou': assinou, 'autenticado': autenticado, 'plataforma': 'WEB', 'tempo_leitura': tempo_leitura, 'utm_source': '', 'utm_medium': '', 'utm_campaign': '', 'crm_id': AbrilCustomDimension.crm_id, 'utm_crm_id': '', 'tipo' : customData['tipo-pagina'], 'slug' : slug, 'referrer' : referrer_value, 'source' : '' }; console.log("DATA NOVOS PARANS"); console.log(data); fetch('https://us-central1-abril-id-testes-1528223718961.cloudfunctions.net/navigationData/dados-editoriais', { method: "POST", body: JSON.stringify(data), headers: { "Content-type": "application/json; charset=UTF-8" } }) .then(response => response.json()) .then(json => console.log(json)) .catch(err => console.log(err)); } function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i