1function getCookie(n) { 2 return document.cookie 3 .split('; ') 4 .find((row) => row.startsWith(n)) 5 ?.split('=')[1]; 6} 7 8function createCookie(name, value, days) { 9 let expires = ''; 10 if (days) { 11 const date = new Date(); 12 date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); 13 expires = '; expires=' + date.toUTCString(); 14 } 15 document.cookie = name + '=' + (value || '') + expires + '; path=/'; 16} 17 18function getUrlParam(urlParam) { 19 return new URLSearchParams(window.location.search).get(urlParam); 20} 21 22function getRandomUUID() { 23 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { 24 const r = Math.random() * 16 | 0; 25 const v = c === 'x' ? r : (r & 0x3 | 0x8); 26 return v.toString(16); 27 }); 28} 29 30(function () { 31 // Check if the browser data is already in a cookie 32 const cookie = getCookie('_tb_b'); 33 if (!cookie) { 34 // If it isn't, store it 35 const data = { 36 clientId: typeof crypto.randomUUID === "function" ? crypto.randomUUID() : getRandomUUID(), 37 context: { 38 document: { 39 location: { 40 href: document.location.href, 41 hash: document.location.hash, 42 host: document.location.host, 43 hostname: document.location.hostname, 44 origin: document.location.origin, 45 pathname: document.location.pathname, 46 port: document.location.port, 47 protocol: document.location.protocol, 48 search: document.location.search, 49 }, 50 title: document.title, 51 referrer: document.referrer, 52 characterSet: document.characterSet, 53 }, 54 navigator: { 55 language: navigator.language, 56 cookieEnabled: navigator.cookieEnabled, 57 languages: navigator.languages, 58 userAgent: navigator.userAgent, 59 }, 60 window: { 61 innerHeight: window.innerHeight, 62 innerWidth: window.innerWidth, 63 outerHeight: window.outerHeight, 64 outerWidth: window.outerWidth, 65 pageXOffset: window.pageXOffset, 66 pageYOffset: window.pageYOffset, 67 screenX: window.screenX, 68 screenY: window.screenY, 69 scrollX: window.scrollX, 70 scrollY: window.scrollY, 71 }, 72 }, 73 }; 74 const base64Data = btoa(encodeURIComponent(JSON.stringify(data))); 75 createCookie('_tb_b', base64Data, 400); 76 } else { 77 // If it is, update the data 78 const data = JSON.parse(decodeURIComponent(atob(cookie))); 79 80 // Update the document 81 data.context.document = { 82 title: document.title, 83 referrer: document.referrer, 84 characterSet: document.characterSet, 85 location: { 86 href: document.location.href, 87 hash: document.location.hash, 88 host: document.location.host, 89 hostname: document.location.hostname, 90 origin: document.location.origin, 91 pathname: document.location.pathname, 92 port: document.location.port, 93 protocol: document.location.protocol, 94 search: document.location.search, 95 } 96 }; 97 98 // Update the navigator 99 data.context.navigator = { 100 language: navigator.language, 101 cookieEnabled: navigator.cookieEnabled, 102 languages: navigator.languages, 103 userAgent: navigator.userAgent, 104 }; 105 106 // Update the window 107 data.context.window = { 108 innerHeight: window.innerHeight, 109 innerWidth: window.innerWidth, 110 outerHeight: window.outerHeight, 111 outerWidth: window.outerWidth, 112 pageXOffset: window.pageXOffset, 113 pageYOffset: window.pageYOffset, 114 screenX: window.screenX, 115 screenY: window.screenY, 116 scrollX: window.scrollX, 117 scrollY: window.scrollY, 118 }; 119 120 // Update the cookie 121 const base64Data = btoa(encodeURIComponent(JSON.stringify(data))); 122 createCookie('_tb_b', base64Data, 400); 123 } 124 125 // Get the marketing attributes from the url parameters 126 const params = [ 127 // Key is the name of the key in the order notes, cookie is the 128 // name of the cookie and value is the value retrieved from the URL.
129 {key: "epik", cookie: "_epik", value: getUrlParam("epik")}, 130 {key: "fbc", cookie: "_fbc", value: getUrlParam("fbclid")}, 131 {key: "ttclid", cookie: "_ttclid", value: getUrlParam("ttclid")}, 132 {key: "gclid", cookie: "_gclid", value: getUrlParam("gclid")}, 133 {key: "gbraid", cookie: "_gbraid", value: getUrlParam("gbraid")}, 134 {key: "wbraid", cookie: "_wbraid", value: getUrlParam("wbraid")}, 135 {key: "kx", cookie: "_kx", value: getUrlParam("_kx")}, 136 {key: "utmCampaign", cookie: "_utm_campaign", value: getUrlParam("utm_campaign") || getUrlParam("tw_campaign")}, 137 {key: "utmAdGroup", cookie: "_utm_ad_group", value: getUrlParam("utm_ad_group")}, 138 {key: "utmAd", cookie: "_utm_ad", value: getUrlParam("utm_ad") || getUrlParam("tw_adid")}, 139 {key: "utmSource", cookie: "_utm_source", value: getUrlParam("utm_source")}, 140 ]; 141 142 // Check if there are any values in the url parameters 143 const values = params.filter((v) => v.value != null); 144 145 // Create cookies for the marketing attributes 146 params.forEach((param) => { 147 // If there are new values, create cookie with old prefix 148 if (values.length > 0) { 149 const oldCookie = getCookie(param.cookie); 150 const oldCookieKey = "_old" + param.cookie; 151 if (oldCookie) createCookie(oldCookieKey, oldCookie, 400); 152 // Remove old cookie 153 document.cookie = param.cookie 154 + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; 155 } 156 157 // If new value, create new cookie 158 if (param.value) { 159 let cookieValue; 160 // Fbc value has a specific format 161 if (param.key === "fbc") { 162 cookieValue = param.value ? "fb.1." + Date.now() + "." + param.value : null; 163 } else { 164 cookieValue = param.value; 165 } 166 createCookie(param.cookie, cookieValue, 400); 167 } 168 }); 169 170 // If there's no fbp value yet, generate one and store it in a cookie 171 const fbp = getCookie('_fbp'); 172 if (!fbp) { 173 const randomNumber = Math.floor( 174 1000000000 + Math.random() * 9000000000 175 ); 176 const fbp = 'fb.1.' + Date.now() + '.' + randomNumber; 177 createCookie('_fbp', fbp, 400); 178 } 179 180 // If there's no ttp value yet, generate one and store it in a cookie 181 const ttp = getCookie('_ttp'); 182 if (!ttp) { 183 const ttp = typeof crypto.randomUUID === "function" 184 ? crypto.randomUUID() + crypto.randomUUID() 185 : getRandomUUID() + getRandomUUID(); 186 createCookie('_ttp', ttp, 400); 187 } 188 189 let savedUUID = localStorage.getItem("tbId"); 190 if (!savedUUID) { 191 if (typeof crypto.randomUUID !== "function") { 192 savedUUID = getRandomUUID(); 193 } else { 194 const uuid = crypto.randomUUID(); 195 localStorage.setItem("tbId", uuid); 196 savedUUID = uuid; 197 } 198 } 199 200 const tbId = getCookie("_tb_id"); 201 if (!tbId) { 202 createCookie("_tb_id", savedUUID, 400); 203 } 204 205 const landingSiteUrl = getCookie("_tb_l"); 206 if (!landingSiteUrl) { 207 createCookie("_tb_l", document.location.href, 400); 208 } 209 210 const referringSiteUrl = getCookie("_tb_r"); 211 if (!referringSiteUrl) { 212 createCookie("_tb_r", document.referrer, 400); 213 } 214 215 const currentPath = window.location.pathname; 216 let productSlug; 217 if (currentPath.includes('/product/')) { 218 // If the current page is a product page, get the product slug 219 productSlug = currentPath.replace(/\/+$/, '').split('/').pop(); 220 // Send the product slug to the server and trigger the page loaded action 221 } 222 jQuery.post({ 223 url: trackBee.ajaxurl, 224 data: { 225 action: 'trackbee_page_loaded', 226 productSlug: productSlug || null, 227 }, 228 }); 229})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.