(function(){"use strict";function a(a){const b=new RegExp("(^|;)\\s*"+a+"\\s*=\\s*([^;]*)\\s*(;|$)").exec(window.document.cookie);return b?decodeURIComponent(b[2]):null}function b({key:a,expires:b,domain:c,value:d}){const e=c&&""!==c?";domain="+encodeURIComponent(c):"",f=b&&"number"==typeof b?";expires="+new Date(new Date().getTime()+b).toUTCString():"";document.cookie=a+"="+encodeURIComponent(d)+f+";path=/"+e+";SameSite=None;Secure"}function c(a){return window.localStorage.getItem(a)}function d(a,b){window.localStorage.setItem(a,b)}function e(a){return window.sessionStorage.getItem(a)}function f(a,b){window.sessionStorage.setItem(a,b)}function g(a){window.localStorage.removeItem(a),window.sessionStorage.removeItem(a)}function h(b){const d=e(b);return d?d:a(b)||c(b)}function i({key:a,value:c,expires:e,domain:g}){a&&c&&(b({key:a,value:c,expires:e,domain:g}),d(a,c),f(a,c))}function j(a){try{return null===a?null:JSON.parse(a)}catch{return null}}function k(){const a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".length;let b="";for(let c=0;20>c;c++)b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(Math.random()*a));return b}function l(a){return"function"==typeof a?a:()=>{}}function m(a){return!a?.url||!a?.type}function n(a,b){return a.reduce((a,c)=>{const d=c.hash?c.hash:b;return d?(a[d]||(a[d]=[]),a[d].push(c),a):a},{})}function o(){const a=window[F].find(a=>a.eventType&&"init"===a.eventType);return a||null}function p(a=null){return a?.value?a.value:null}function q(a=null){return a?.dc&&["ams","us","phx","sin","ash","asia"].includes(a.dc)?a.dc:"ams"}function r(a){try{const b=JSON.parse(a),c=Array.isArray(b)?b:[];for(const a of c){const b=m(a);if(!b)if("img"===(a.type+"").toLowerCase()){const b=new Image;b.src=a.url,b.setAttribute("width","1"),b.setAttribute("height","1"),b.setAttribute("scrolling","no"),b.setAttribute("frameBorder","0"),b.setAttribute("style","display:none"),document.body.appendChild(b)}else if("iframe"===(a.type+"").toLowerCase()){const b=document.createElement("iframe");b.onload=()=>{setTimeout(()=>b.parentNode?.removeChild(b),3e4)},b.setAttribute("width","1"),b.setAttribute("height","1"),b.setAttribute("scrolling","no"),b.setAttribute("frameBorder","0"),b.setAttribute("style","display:none"),b.setAttribute("src",a.url),document.body.appendChild(b)}}}catch{}}function s(a){return!!a&&new Date(a){b.test(a?.eventType+"")&&i({key:G+a.eventType,value:JSON.stringify({...a,expiryDate:u()}),expires:J})})}function y(){const a=w();for(const b of a){if(b&&!b.expiryDate){i({key:G+b.eventType,value:JSON.stringify({...b,expiryDate:u()}),expires:J});continue}if(H.includes(b?.eventType)&&s(b?.expiryDate)){const a=G+b.eventType;g(a)}}const b=h("__rtbh.lid"),c=t(b);if(!b||c)i({key:"__rtbh.lid",value:JSON.stringify({eventType:"lid",id:k(),expiryDate:u()}),expires:J});else{const a=j(b);a?.expiryDate&&i({key:"__rtbh.lid",value:JSON.stringify({...a,expiryDate:u()}),expires:J})}}function z(){for(const a of I){const b=G+a,c=h(`__rtbhouse.${a}`),d=h(b),e=window[F].find(b=>b.eventType===a&&b.id);if(e&&i({key:b,value:JSON.stringify(e),expires:J}),!d&&c&&!c.includes("eventType")){i({key:G+a,value:JSON.stringify({eventType:a,id:c}),expires:J})}}}async function A(a,b,c,d){try{const e=l(c),f=await fetch(a,b),g=f.status;if(200<=g&&300>g)return e(d?await f.json():await f.text(),f)}catch{}}function B(a,b,c){try{const d=n(a,c),e=Object.keys(d),f=w();for(const a of e)b&&b(r,d[a],f,a)}catch{}}function C(a,b,c){if(null===a)return;return function(d,e,f,g=null){const h=e.filter(a=>!b.includes(a.eventType)&&"init"!==a.eventType);return A(`https://${c}.creativecdn.com/tags/v2?type=json`,{method:"POST",mode:"cors",credentials:"include",referrerPolicy:"no-referrer-when-downgrade",headers:{"Content-Type":"application/json"},redirect:"follow",body:JSON.stringify({...v(a,g),tags:[...h,...f]})},d)}}function D(){const a=o(),b=q(a),c=p(a),d=C(c,I,b);return{taggingHash:c,sendTags:d}}function E(a,b){const c=new RegExp(`^(${I.join("|")})$`);return function(...d){try{if(x(d,c),null===a){const{taggingHash:c,sendTags:d}=D();a=c,b=d}return Array.prototype.push.apply(this,d),B(d,b,a),!0}catch{return!1}}}const F="rtbhEvents",G="__rtbh.",H=["uid","sid","aid","eid"],I=[...H,"lid"],J=31536000000,K="v0.2.1";(function(){if(Array.isArray(window[F])||(window[F]=[]),window[F].length&&!window[F].push.prototype)try{const{taggingHash:a,sendTags:b}=D();z(),y(),B(window[F],b,a),window[F].push=E(a,b)}catch{}})()})();