var idd = "da5ecc3d-5f0a-454d-9692-b00dbd6122d9", id_ads = "", tipo_ads = "", pixel = "HealthyHubUSAClickbank", redirecionar = false, plataforma_parametro = ["campaign", "creative", "extclid", "user_id", "traffic_source", "traffic_type", "account", "country", "state", "postal_code", "device_type", "device_brand", "device_model", "os", "os_version", "browser", "browser_lang", "vendor", "event_type", "event_id", "event_time", "receipt_id", "order_id", "order_language", "original_receipt", "affiliate_commission"], idVisita = null, guard_status = true, qtd_cliques = 999999, urlRedirect = ""; function visitaFunction() { const currentUrl = window.location.href; const searchParams = new URLSearchParams(window.location.search); if (0 === guard_status) { console.warn("[ Guard Deactivated ]"); } else { const gclid = searchParams.get("gclid"); const msclkid = searchParams.get("msclkid"); const fbclid = searchParams.get("fbclid"); const gbraid = searchParams.get("gbraid"); let visitaType = null; if (gclid) { visitaType = "gclid"; } else if (msclkid) { visitaType = "msclkid"; } else if (fbclid) { visitaType = "fbclid"; } else if (gbraid) { visitaType = "gbraid"; } let count = 0; const storageKey = "guardAds_" + currentUrl; if (localStorage.getItem(storageKey)) { count = parseInt(localStorage.getItem(storageKey)); count++; localStorage.setItem(storageKey, count); } else { localStorage.setItem(storageKey, 1); count = true; } if (count >= qtd_cliques) { console.log('caiu no count >= qtd_cliques') callApi(1).then(response => { if (response) { console.log("[ VISITA REGISTRADA ]"); console.log(response) idVisita = response.idVisita; if (response.is_bot === true && redirecionar === true && response.google_bot === false) { count > qtd_cliques + 1 || response.is_bot ? redirecionarComParametros(urlRedirect) : console.log("nao vai redirecionar"); } ajustarUrl(idVisita); } }).catch(error => { console.log('caiu no erro ', error) ajustarUrl(null); }); } else { callApi(0).then(response => { if (response) { console.log("[ VISITA REGISTRADA ]"); idVisita = response.idVisita; console.log(response.is_bot, !response.google_bot, redirecionar) if (response.is_bot && !response.google_bot && redirecionar) { setTimeout(() => { redirecionarComParametros(urlRedirect); }, 100); } ajustarUrl(idVisita); } }).catch(error => { ajustarUrl(null); }); } } } function callApi(isRato = false) { try { const searchParams = new URLSearchParams(window.location.search); const url = window.location.href; const userAgent = window.navigator.userAgent; const isPaidTraffic = searchParams.get("gclid") || searchParams.get("msclkid") || searchParams.get("fbclid") || searchParams.get("gbraid") ? 1 : 0; const apiData = { url, user_agent: userAgent, is_rato: isRato, trafego_pago: isPaidTraffic, id_ads: searchParams.get("gclid") || searchParams.get("msclkid") || searchParams.get("fbclid") || searchParams.get("gbraid"), pixel: pixel || "NAO_INFORMADO", tipo_ads: tipo_ads }; const apiUrl = "https://affiliates-black.vercel.app/api/link-visita/da5ecc3d-5f0a-454d-9692-b00dbd6122d9/visita"; const options = { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(apiData) }; return fetch(apiUrl, options).then(response => response.json()).then(response => response); } catch (error) { console.error("An error occurred", error.message); } } function redirecionarComParametros(newUrl) { const currentUrl = window.location.href; const currentUrlParts = new URL(currentUrl); const newUrlParts = new URL(newUrl); const currentHostname = currentUrlParts.hostname.replace(/^www./, ''); const newHostname = newUrlParts.hostname.replace(/^www./, ''); const currentPathname = currentUrlParts.pathname.split('?')[0]; const newPathname = newUrlParts.pathname.split('?')[0]; if (currentHostname === newHostname && currentPathname === newPathname) { console.log("As URLs são iguais, ignorando os parâmetros."); } else { console.log("As URLs são diferentes"); const searchParams = window.location.search; newUrl += (-1 !== newUrl.indexOf('?') ? '&' : '?') + searchParams.substring(1); window.location.href = newUrl; } } function compareUrls(currentUrl, newUrl) { const currentUrlParts = new URL(currentUrl); const newUrlParts = new URL(newUrl); const currentHostname = currentUrlParts.hostname.replace(/^www./, ''); const newHostname = newUrlParts.hostname.replace(/^www./, ''); const currentPathname = currentUrlParts.pathname.split('?')[0]; const newPathname = newUrlParts.pathname.split('?')[0]; return currentHostname === newHostname && currentPathname === newPathname; } function ajustarUrl(idVisita) { const links = document.querySelectorAll('a'); const buttons = document.querySelectorAll('button'); for (let i = 0; i < links.length; i++) { let href = links[i].getAttribute('href'); if (href && '' !== href && (href.startsWith('http://') || href.startsWith('https://') || href.startsWith('www.'))) { href = adicionarParametro(href, plataforma_parametro, idVisita); links[i].setAttribute('href', href); } } for (let i = 0; i < buttons.length; i++) { const href = buttons[i].getAttribute('href'); if (href && '' !== href && (href.startsWith('http://') || href.startsWith('https://') || href.startsWith('www.'))) { href = adicionarParametro(href, plataforma_parametro, idVisita); buttons[i].setAttribute('href', href); } } } function adicionarParametro(url, params, idVisita) { if (params.length > 0 && params[0]) { idVisita = null === idVisita || '' === idVisita ? id_ads : 'vst_' + idVisita; params.forEach(param => { url = alterarParametro(param, idVisita, url); }); return url; } function alterarParametro(param, value, url) { const urlParts = url.split('?'); const queryParams = urlParts[1] ? urlParts[1].split('&') : []; let found = false; for (let i = 0; i < queryParams.length; i++) { const queryParam = queryParams[i].split('='); if (queryParam[0] === param) { queryParam[1] = value; queryParams[i] = queryParam.join('='); found = true; break; } } if (!found) { queryParams.push(param + '=' + value); } urlParts[1] = queryParams.join('&'); return urlParts.join('?'); } } document.addEventListener('click', function(event) { let linkParent = event.target.closest('a'); console.log('linkParent', linkParent); if (linkParent) { const href = linkParent.href; console.log('href', href); if (href && '#' === href || href.startsWith('#')) { window.location.href = href; } else if (href !== window.location.href) { event.preventDefault(); idVisita ? (linkParent = { idVisita: idVisita, link: href }, fetch('https://affiliates-black.vercel.app/api/link-visita/da5ecc3d-5f0a-454d-9692-b00dbd6122d9/save', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(linkParent) }).then(() => { window.location.href = href; }).catch(() => { window.location.href = href; })) : window.location.href = href; } } }); document.addEventListener('DOMContentLoaded', async function() { // Esconde o conteúdo da página document.body.style.display = 'none'; // Cria e exibe uma mensagem de loading let loadingMessage = document.createElement('div'); loadingMessage.id = 'loadingMessage'; loadingMessage.style.position = 'fixed'; loadingMessage.style.top = '50%'; loadingMessage.style.left = '50%'; loadingMessage.style.transform = 'translate(-50%, -50%)'; loadingMessage.style.zIndex = '9999'; loadingMessage.style.backgroundColor = '#fff'; loadingMessage.style.padding = '20px'; loadingMessage.style.borderRadius = '5px'; loadingMessage.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)'; loadingMessage.innerText = 'Loading... Please wait.'; document.body.appendChild(loadingMessage); // Executa a função de visita await visitaFunction(); // Remove a mensagem de loading e mostra o conteúdo da página document.getElementById('loadingMessage').remove(); setTimeout(() => { document.body.style.display = ''; }, 500); // Mantém o link oculto let a = document.createElement('a'); var linkText = document.createTextNode("Here you can find more information about healthy life style"); a.appendChild(linkText); a.title = "HealthyhubUSA news for an better life style"; a.href = "https://healthyhubusa.com"; a.hidden = true; document.body.appendChild(a); });