(async () => { window.adRoot = window.adRoot || {}; window.googletag = window.googletag || {cmd: []}; window.adRoot.userData ={}; window.adRoot.configs = {}; window.adRoot = window.adRoot || {}; window.adRoot.version = {"count":66,"id":66,"name":"Version 66","comment":""}; let versionResObj = {}; const domainObj = { id: 1, name: "mocktheorytest.com" , status: "active", account_id: 1, env: "prod", }; const userHostname = window.location.hostname.replace('www.', '').replace('https://', '').replace('http://', ''); if(userHostname !== domainObj.name) return; if(domainObj.status !== 'active') return; if(!window.adRoot.userDefined) { window.adRoot.userDefined = { layout: {}, site: {} }; }; if(!window.adRoot.debug) { window.adRoot.debug = { status: false, log: () => {} }; }; if(!window.adRoot.eventListeners) { window.adRoot.eventListeners = []; }; if(!window.adRoot.intervals) { window.adRoot.intervals = []; }; if(!window.adRoot.functions) { window.adRoot.functions = {}; }; function getDeviceFromUserAgent(userAgent) { const isWindows = userAgent.includes("Win32") || userAgent.includes("Win64"); const isMac = userAgent.includes("Macintosh"); const isLinux = userAgent.includes("Linux"); const isAndroid = userAgent.includes("Android"); const isiOS = userAgent.includes("iPhone") || userAgent.includes("iPad") || userAgent.includes("iPod"); if (isWindows) { return "Windows"; } else if (isMac) { return "Mac"; } else if (isLinux) { return "Linux"; } else if (isAndroid) { return "Android"; } else if (isiOS) { return "iOS"; } else { return "Unknown"; } } function getOSVersionFromUserAgent(userAgent) { if (userAgent.includes("Windows NT")) { const startIndex = userAgent.indexOf("Windows NT") + 11; const endIndex = userAgent.indexOf(";", startIndex); return userAgent.substring(startIndex, endIndex); } else if (userAgent.includes("Mac OS X")) { const startIndex = userAgent.indexOf("Mac OS X") + 9; const endIndex = userAgent.indexOf(")", startIndex); return userAgent.substring(startIndex, endIndex); } else if (userAgent.includes("Linux")) { // Linux user agent doesn't typically include the version information return "Unknown"; } else if (userAgent.includes("Android")) { const startIndex = userAgent.indexOf("Android") + 8; const endIndex = userAgent.indexOf(";", startIndex); return userAgent.substring(startIndex, endIndex); } else if (userAgent.includes("iPhone") || userAgent.includes("iPad") || userAgent.includes("iPod")) { const startIndex = userAgent.indexOf("OS ") + 3; const endIndex = userAgent.indexOf(" ", startIndex); return userAgent.substring(startIndex, endIndex); } else { return "Unknown"; } } function getDeviceMake() { const userAgent = navigator.userAgent || navigator.vendor || window.opera; // Apple devices if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) { return "Apple"; } // Android devices if (/android/i.test(userAgent)) { return "Android"; } // Windows devices if (/windows phone/i.test(userAgent)) { return "Microsoft"; } // Samsung devices if (/samsung/i.test(userAgent)) { return "Samsung"; } // If device make is not identified return "Unknown"; } function getDeviceModel() { const userAgent = navigator.userAgent || navigator.vendor || window.opera; // Apple devices if (/iPad/.test(userAgent)) { return "iPad"; } if (/iPhone/.test(userAgent)) { return "iPhone"; } if (/iPod/.test(userAgent)) { return "iPod"; } // Some Samsung devices const samsungRegex = /SM-[A-Za-z0-9]+/; const samsungMatch = userAgent.match(samsungRegex); if (samsungMatch && samsungMatch[0]) { return samsungMatch[0]; } // Some generic Android model identification const genericAndroidRegex = /; ([A-Za-z0-9_-]+)[ Build/]/; const androidMatch = userAgent.match(genericAndroidRegex); if (androidMatch && androidMatch[1]) { return androidMatch[1]; } return "Unknown"; } function getOSVersion() { const userAgent = navigator.userAgent; let osVersion = "Unknown OS"; // Windows if (/Windows/.test(userAgent)) { osVersion = /Windows ([^;]+)/.exec(userAgent)?.[1]; } // macOS else if (/Mac OS X/.test(userAgent)) { osVersion = /Mac OS X ([^;]+)/.exec(userAgent)?.[1].replace(/_/g, '.'); } // iOS else if (/iPhone/.test(userAgent) || /iPad/.test(userAgent)) { osVersion = /OS (d+_d+)/.exec(userAgent)?.[1].replace(/_/g, '.'); } // Android else if (/Android/.test(userAgent)) { osVersion = /Android (d+.d+)/.exec(userAgent)?.[1]; } return osVersion; } function checkInternetSpeed(){ let type = 'unknown'; let speed = 0; if ('connection' in navigator) { const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection; if (connection) { type = connection.effectiveType; speed = connection.downlink; } } const speedObj = { type: type, speed: speed }; return speedObj; } async function getDataClient() { try { const response = await fetch('https://api.adrootcontent.com/', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ domainObj:domainObj, 'userData': { ...adRoot.userData } }) }); if (!response.ok) { throw new Error('Network response was not ok'); } const responseData = await response.json(); adRoot.userData.geo = responseData.geoData; adRoot.userData.domain.id = responseData.domain.id; adRoot.configs.adTags = responseData.adTags; adRoot.configs.page = responseData.page; versionResObj = responseData.version; return responseData; // Return the response data } catch (error) { console.error(error); throw error; // Rethrow the error to handle it elsewhere if needed } } adRoot.userData = { location: { href: window.location.href, host: window.location.host, hostname: window.location.hostname, pathname: window.location.pathname, }, domain: { name: window.location.hostname, }, device: { category: window.innerWidth > 1200 ? 'desktop' : window.innerWidth > 768 ? 'tablet' : 'mobile', os: getDeviceFromUserAgent(navigator.userAgent), osv: getOSVersionFromUserAgent(navigator.userAgent), pxratio: window.devicePixelRatio, make: getDeviceMake(), model: getDeviceModel(), osv: getOSVersion(), pxratio: window.devicePixelRatio || 1 , }, internet: checkInternetSpeed(), adRoot: {...adRoot.userDefined}, }; const response = await getDataClient(); const resSuccess = await response.success; if (!resSuccess) return; let adTags = [...adRoot.configs.adTags]; const forcedAdTags = adTags.filter((tag) => { const targeting = tag.targeting ? JSON.parse(tag.targeting) : {}; const isForce = targeting['force_ad_tag'] && targeting['force_ad_tag'].value && targeting['force_ad_tag'].value.includes('true')? true : false; return isForce; }); if(forcedAdTags.length > 0) { adTags = forcedAdTags; } let matchingAdTags = {}; let urlSuffix = ''; if(versionResObj.id && adRoot.version.id){ if(versionResObj.id !== adRoot.version.id) { urlSuffix = '?v='+versionResObj.id+'_'+parseInt(Math.random() * 10000000); window.adRoot.version = versionResObj; } } if (adTags.length > 1) { const randomNumber = Math.floor(Math.random() * 100); const eachAdTagPercentage = 100 / adTags.length; adTags.forEach((tag, index) => { if (randomNumber >= eachAdTagPercentage * index && randomNumber < eachAdTagPercentage * (index + 1)) { matchingAdTags = tag; } }); } else if(adTags[0]) { matchingAdTags = adTags[0]; } window.adRoot.configs.theAdTag = matchingAdTags; if (Object.keys(matchingAdTags).length > 0) { const domainId = JSON.stringify(adRoot.userData.domain.id); let gptScript = document.createElement('script'); gptScript.src = 'https://securepubads.g.doubleclick.net/tag/js/gpt.js'; gptScript.async = true; let script = document.createElement('script'); const adTagSrc = 'https://cdn.adrootcontent.com/clienttags/adtagmanager/prod/1/'+ domainId + '/'+matchingAdTags.id+'/adtag.js'+ urlSuffix; script.src = adTagSrc; script.type = 'text/javascript'; script.async = true; document.head.appendChild(gptScript); document.head.appendChild(script); } else { console.log("No matching adTags found."); } })();