@bidkernel/analytics 0.11.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analytics.global.js +1 -1
- package/dist/index.d.mts +73 -2
- package/dist/index.d.ts +73 -2
- package/dist/index.js +234 -78
- package/dist/index.mjs +233 -78
- package/package.json +1 -1
package/dist/analytics.global.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var bidkernelPrebidAnalyticsBundle=(()=>{var x=(i,e)=>()=>(i&&(e=i(i=0)),e);var tt=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports);function rt(){if(typeof window<"u"){let i=window;return i.__bidkernelLogListeners||(i.__bidkernelLogListeners=new Set),i.__bidkernelLogListeners}return nt}function ot(i){if((i<0||!Number.isFinite(i))&&(i=0),i<1e3)return`${i.toFixed(2)}ms`;let e=i/1e3;if(e<60)return`${e.toFixed(2)}s`;let t=Math.floor(e/60);return t<60?`${t}m ${(e%60).toFixed(2)}s`:`${Math.floor(t/60)}h ${t%60}m ${(e%60).toFixed(2)}s`}function W(i){if(typeof i=="string"){let e=i.toUpperCase();if(e==="DEBUG"||e==="INFO"||e==="WARN"||e==="ERROR")return e}return A.INFO}function ie(i){return new te(i)}var A,ve,O,it,nt,te,Te=x(()=>{"use strict";A={DEBUG:"DEBUG",INFO:"INFO",WARN:"WARN",ERROR:"ERROR"},ve={[A.DEBUG]:10,[A.INFO]:20,[A.WARN]:30,[A.ERROR]:40},O={badge:"color: #2dd4bf; font-weight: bold",badgeWarn:"background: #f59e0b; color: #fff; padding: 2px 4px; border-radius: 3px; font-weight: bold",badgeError:"background: #ef4444; color: #fff; padding: 2px 4px; border-radius: 3px; font-weight: bold",dim:"color: #6b7280",event:"color: #38bdf8; font-weight: bold",eventWarn:"color: #f59e0b; font-weight: bold",eventError:"color: #ef4444; font-weight: bold",reset:"color: inherit"},it=0,nt=new Set;te=class i{_prefix;_level;_loadedAt;_now;_console;_customFormatTime;_listeners=new Set;constructor(e={}){this._prefix=e.prefix??"[bidkernel]",this._level=W(e.logLevel??A.INFO),this._now=e.now,this._console=e.console,this._customFormatTime=e.formatTime,e.onLog&&this._listeners.add(e.onLog),this._loadedAt=e.loadedAt??(this._now?this._now():typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now())}get prefix(){return this._prefix}set prefix(e){this._prefix=e}get logLevel(){return this._level}set logLevel(e){this._level=W(e)}getLevel(){return this._level}setLevel(e){this._level=W(e)}getPrefix(){return this._prefix}setPrefix(e){this._prefix=e}resetTiming(e){this._loadedAt=e??(this._now?this._now():typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now())}getLoadedAt(){return this._loadedAt}addListener(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}removeListener(e){this._listeners.delete(e)}isEnabled(e){let t=W(e);return(ve[t]??20)>=(ve[this._level]??20)}formatTime(e){return this._customFormatTime?this._customFormatTime(e):ot(e)}_getConsole(){if(this._console)return this._console;if(typeof console<"u")return console}_getElapsed(){let e=this._now?this._now():typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now();return Math.max(0,e-this._loadedAt)}_dispatchRecord(e){for(let n of this._listeners)try{n(e)}catch{}let t=rt();for(let n of t)if(!this._listeners.has(n))try{n(e)}catch{}if(typeof window<"u"&&typeof window.dispatchEvent=="function")try{window.dispatchEvent(new CustomEvent("__bidkernel_log__",{detail:e}))}catch{}}log(e,t,...n){let r=W(e);if(!this.isEnabled(r))return;let o=this._getElapsed(),s=this.formatTime(o),d=Date.now(),l={id:`bk_log_${d}_${++it}`,timestamp:d,elapsedMs:o,level:r,prefix:this._prefix,message:t,args:n,data:n.length===1?n[0]:n.length>1?n:void 0};this._dispatchRecord(l);let u=this._getConsole();if(!u)return;let y=O.badge,f=O.event;r===A.WARN?(y=O.badgeWarn,f=O.eventWarn):r===A.ERROR&&(y=O.badgeError,f=O.eventError);let v=`%c${this._prefix}%c ${s} %c${t}%c`,T=[y,O.dim,f,O.reset],p=[v,...T];switch(n.length>0&&p.push(...n),r){case A.DEBUG:typeof u.log=="function"?u.log(...p):typeof u.debug=="function"&&u.debug(...p);break;case A.INFO:typeof u.info=="function"?u.info(...p):typeof u.log=="function"&&u.log(...p);break;case A.WARN:typeof u.warn=="function"?u.warn(...p):typeof u.log=="function"&&u.log(...p);break;case A.ERROR:typeof u.error=="function"?u.error(...p):typeof u.log=="function"&&u.log(...p);break;default:typeof u.log=="function"&&u.log(...p);break}}debug(e,...t){this.log(A.DEBUG,e,...t)}info(e,...t){this.log(A.INFO,e,...t)}warn(e,...t){this.log(A.WARN,e,...t)}error(e,...t){this.log(A.ERROR,e,...t)}logEvent(e){e&&(e.data!==void 0?this.log(e.level,e.eventName,e.data):this.log(e.level,e.eventName))}child(e,t={}){let n=this._prefix;if(e){let r=e.startsWith("[")&&e.endsWith("]")?e:`[${e}]`;n=`${this._prefix}${r}`}return new i({prefix:n,logLevel:t.logLevel??this._level,loadedAt:t.loadedAt??this._loadedAt,now:t.now??this._now,console:t.console??this._console,formatTime:t.formatTime??this._customFormatTime,...t})}withPrefix(e){return new i({prefix:e,logLevel:this._level,loadedAt:this._loadedAt,now:this._now,console:this._console,formatTime:this._customFormatTime})}}});function we(){let i=0,e=0;for(let n=0;n<28;n+=7){let r=this.buf[this.pos++];if(i|=(r&127)<<n,(r&128)==0)return this.assertBounds(),[i,e]}let t=this.buf[this.pos++];if(i|=(t&15)<<28,e=(t&112)>>4,(t&128)==0)return this.assertBounds(),[i,e];for(let n=3;n<=31;n+=7){let r=this.buf[this.pos++];if(e|=(r&127)<<n,(r&128)==0)return this.assertBounds(),[i,e]}throw new Error("invalid varint")}function G(i,e,t){for(let o=0;o<28;o=o+7){let s=i>>>o,d=!(!(s>>>7)&&e==0),a=(d?s|128:s)&255;if(t.push(a),!d)return}let n=i>>>28&15|(e&7)<<4,r=e>>3!=0;if(t.push((r?n|128:n)&255),!!r){for(let o=3;o<31;o=o+7){let s=e>>>o,d=!!(s>>>7),a=(d?s|128:s)&255;if(t.push(a),!d)return}t.push(e>>>31&1)}}function ne(i){let e=i[0]==="-";e&&(i=i.slice(1));let t=1e6,n=0,r=0;function o(s,d){let a=Number(i.slice(s,d));r*=t,n=n*t+a,n>=H&&(r=r+(n/H|0),n=n%H)}return o(-24,-18),o(-18,-12),o(-12,-6),o(-6),e?Re(n,r):oe(n,r)}function Ae(i,e){let t=oe(i,e),n=t.hi&2147483648;n&&(t=Re(t.lo,t.hi));let r=re(t.lo,t.hi);return n?"-"+r:r}function re(i,e){if({lo:i,hi:e}=st(i,e),e<=2097151)return String(H*e+i);let t=i&16777215,n=(i>>>24|e<<8)&16777215,r=e>>16&65535,o=t+n*6777216+r*6710656,s=n+r*8147497,d=r*2,a=1e7;return o>=a&&(s+=Math.floor(o/a),o%=a),s>=a&&(d+=Math.floor(s/a),s%=a),d.toString()+Ee(s)+Ee(o)}function st(i,e){return{lo:i>>>0,hi:e>>>0}}function oe(i,e){return{lo:i|0,hi:e|0}}function Re(i,e){return e=~e,i?i=~i+1:e+=1,oe(i,e)}function se(i,e){if(i>=0){for(;i>127;)e.push(i&127|128),i=i>>>7;e.push(i)}else{for(let t=0;t<9;t++)e.push(i&127|128),i=i>>7;e.push(1)}}function _e(){let i=this.buf[this.pos++],e=i&127;if((i&128)==0)return this.assertBounds(),e;if(i=this.buf[this.pos++],e|=(i&127)<<7,(i&128)==0)return this.assertBounds(),e;if(i=this.buf[this.pos++],e|=(i&127)<<14,(i&128)==0)return this.assertBounds(),e;if(i=this.buf[this.pos++],e|=(i&127)<<21,(i&128)==0)return this.assertBounds(),e;i=this.buf[this.pos++],e|=(i&15)<<28;for(let t=5;(i&128)!==0&&t<10;t++)i=this.buf[this.pos++];if((i&128)!=0)throw new Error("invalid varint");return this.assertBounds(),e>>>0}var H,Ee,de=x(()=>{"use strict";H=4294967296;Ee=i=>{let e=String(i);return"0000000".slice(e.length)+e}});function dt(){let i=new DataView(new ArrayBuffer(8));if(typeof BigInt=="function"&&typeof i.getBigInt64=="function"&&typeof i.getBigUint64=="function"&&typeof i.setBigInt64=="function"&&typeof i.setBigUint64=="function"&&(!!globalThis.Deno||typeof process!="object"||typeof process.env!="object"||process.env.BUF_BIGINT_DISABLE!=="1")){let t=BigInt("-9223372036854775808"),n=BigInt("9223372036854775807"),r=BigInt("0"),o=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(s){let d=typeof s=="bigint"?s:BigInt(s);if(d>n||d<t)throw new Error(`invalid int64: ${s}`);return d},uParse(s){let d=typeof s=="bigint"?s:BigInt(s);if(d>o||d<r)throw new Error(`invalid uint64: ${s}`);return d},enc(s){return i.setBigInt64(0,this.parse(s),!0),{lo:i.getInt32(0,!0),hi:i.getInt32(4,!0)}},uEnc(s){return i.setBigInt64(0,this.uParse(s),!0),{lo:i.getInt32(0,!0),hi:i.getInt32(4,!0)}},dec(s,d){return i.setInt32(0,s,!0),i.setInt32(4,d,!0),i.getBigInt64(0,!0)},uDec(s,d){return i.setInt32(0,s,!0),i.setInt32(4,d,!0),i.getBigUint64(0,!0)}}}return{zero:"0",supported:!1,parse(t){return typeof t!="string"&&(t=t.toString()),Be(t),t},uParse(t){return typeof t!="string"&&(t=t.toString()),xe(t),t},enc(t){return typeof t!="string"&&(t=t.toString()),Be(t),ne(t)},uEnc(t){return typeof t!="string"&&(t=t.toString()),xe(t),ne(t)},dec(t,n){return Ae(t,n)},uDec(t,n){return re(t,n)}}}function Be(i){if(!/^-?[0-9]+$/.test(i))throw new Error("invalid int64: "+i)}function xe(i){if(!/^[0-9]+$/.test(i))throw new Error("invalid uint64: "+i)}var C,Ce=x(()=>{"use strict";de();C=dt()});function ce(){if(globalThis[ae]==null){let i=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[ae]={encodeUtf8(t){return i.encode(t)},decodeUtf8(t){return e.decode(t)},checkUtf8(t){try{return encodeURIComponent(t),!0}catch{return!1}}}}return globalThis[ae]}var ae,le=x(()=>{"use strict";ae=Symbol.for("@bufbuild/protobuf/text-encoding")});function ue(i){if(typeof i=="string")i=Number(i);else if(typeof i!="number")throw new Error("invalid int32: "+typeof i);if(!Number.isInteger(i)||i>ut||i<ft)throw new Error("invalid int32: "+i)}function Se(i){if(typeof i=="string")i=Number(i);else if(typeof i!="number")throw new Error("invalid uint32: "+typeof i);if(!Number.isInteger(i)||i>lt||i<0)throw new Error("invalid uint32: "+i)}function ht(i){if(typeof i=="string"){let e=i;if(i=Number(i),Number.isNaN(i)&&e!=="NaN")throw new Error("invalid float32: "+e)}else if(typeof i!="number")throw new Error("invalid float32: "+typeof i);if(Number.isFinite(i)&&(i>at||i<ct))throw new Error("invalid float32: "+i)}var L,at,ct,lt,ut,ft,M,B,De=x(()=>{"use strict";de();Ce();le();(function(i){i[i.Varint=0]="Varint",i[i.Bit64=1]="Bit64",i[i.LengthDelimited=2]="LengthDelimited",i[i.StartGroup=3]="StartGroup",i[i.EndGroup=4]="EndGroup",i[i.Bit32=5]="Bit32"})(L||(L={}));at=34028234663852886e22,ct=-34028234663852886e22,lt=4294967295,ut=2147483647,ft=-2147483648,M=class{constructor(e=ce().encodeUtf8){this.encodeUtf8=e,this.stack=[],this.chunks=[],this.buf=[]}finish(){this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]);let e=0;for(let r=0;r<this.chunks.length;r++)e+=this.chunks[r].length;let t=new Uint8Array(e),n=0;for(let r=0;r<this.chunks.length;r++)t.set(this.chunks[r],n),n+=this.chunks[r].length;return this.chunks=[],t}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let e=this.finish(),t=this.stack.pop();if(!t)throw new Error("invalid state, fork stack empty");return this.chunks=t.chunks,this.buf=t.buf,this.uint32(e.byteLength),this.raw(e)}tag(e,t){return this.uint32((e<<3|t)>>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for(Se(e);e>127;)this.buf.push(e&127|128),e=e>>>7;return this.buf.push(e),this}int32(e){return ue(e),se(e,this.buf),this}bool(e){return this.buf.push(e?1:0),this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){let t=this.encodeUtf8(e);return this.uint32(t.byteLength),this.raw(t)}float(e){ht(e);let t=new Uint8Array(4);return new DataView(t.buffer).setFloat32(0,e,!0),this.raw(t)}double(e){let t=new Uint8Array(8);return new DataView(t.buffer).setFloat64(0,e,!0),this.raw(t)}fixed32(e){Se(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){ue(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return ue(e),e=(e<<1^e>>31)>>>0,se(e,this.buf),this}sfixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=C.enc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}fixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=C.uEnc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=C.enc(e);return G(t.lo,t.hi,this.buf),this}sint64(e){let t=C.enc(e),n=t.hi>>31,r=t.lo<<1^n,o=(t.hi<<1|t.lo>>>31)^n;return G(r,o,this.buf),this}uint64(e){let t=C.uEnc(e);return G(t.lo,t.hi,this.buf),this}},B=class{constructor(e,t=ce().decodeUtf8){this.decodeUtf8=t,this.varint64=we,this.uint32=_e,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength)}tag(){let e=this.uint32(),t=e>>>3,n=e&7;if(t<=0||n<0||n>5)throw new Error("illegal tag: field no "+t+" wire type "+n);return[t,n]}skip(e,t){let n=this.pos;switch(e){case L.Varint:for(;this.buf[this.pos++]&128;);break;case L.Bit64:this.pos+=4;case L.Bit32:this.pos+=4;break;case L.LengthDelimited:let r=this.uint32();this.pos+=r;break;case L.StartGroup:for(;;){let[o,s]=this.tag();if(s===L.EndGroup){if(t!==void 0&&o!==t)throw new Error("invalid end group tag");break}this.skip(s,o)}break;default:throw new Error("cant skip wire type "+e)}return this.assertBounds(),this.buf.subarray(n,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)}int64(){return C.dec(...this.varint64())}uint64(){return C.uDec(...this.varint64())}sint64(){let[e,t]=this.varint64(),n=-(e&1);return e=(e>>>1|(t&1)<<31)^n,t=t>>>1^n,C.dec(e,t)}bool(){let[e,t]=this.varint64();return e!==0||t!==0}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return C.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return C.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),t=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(t,t+e)}string(){return this.decodeUtf8(this.bytes())}}});var Oe=x(()=>{"use strict"});var Le=x(()=>{"use strict"});var Me=x(()=>{"use strict"});var ke=x(()=>{"use strict";De();Oe();le();Le();Me()});function Ue(){return{propertyId:"",pageviewId:"",sessionId:"",pageUrl:"",country:"",region:"",deviceType:"",userId:"",domain:"",events:[],browser:"",deviceManufacturer:"",deviceModel:"",city:"",postalCode:""}}function Pe(){return{timestampMs:0,type:0,eventName:"",auctionId:"",transactionId:"",adUnitCode:"",bid:void 0,namespace:"",eventId:"",metadata:{},viewableDurationMs:void 0,bidderOutcomes:[]}}function Ne(){return{key:"",value:""}}function Ve(){return{bidder:"",adUnitCode:"",mediaType:"",outcome:0,latencyMs:0}}function Fe(){return{bidder:"",cpm:0,currency:"",width:0,height:0,dealId:"",mediaType:"",latencyMs:0,advertiserDomain:"",creativeId:""}}var b,S,Y,j,fe,z,X,$e=x(()=>{"use strict";ke();b={TRACE_EVENT_TYPE_UNSPECIFIED:0,AUCTION_START:1,AUCTION_END:2,BID_RESPONSE:3,BID_WIN:4,IMPRESSION:5,VIEWABLE:6,TIME_IN_VIEW:7,REFRESH:8,ERROR:9,SLOT_DEFINED:10,SLOT_DESTROYED:11,CLICK:12,AD_RENDER_FAILED:13,UNRECOGNIZED:-1},S={BIDDER_OUTCOME_UNSPECIFIED:0,BIDDER_OUTCOME_BID:1,BIDDER_OUTCOME_NO_BID:2,BIDDER_OUTCOME_TIMEOUT:3,BIDDER_OUTCOME_ERROR:4,BIDDER_OUTCOME_NO_RESPONSE:5,UNRECOGNIZED:-1};Y={encode(i,e=new M){if(i.propertyId!==void 0&&i.propertyId!==""&&e.uint32(10).string(i.propertyId),i.pageviewId!==void 0&&i.pageviewId!==""&&e.uint32(18).string(i.pageviewId),i.sessionId!==void 0&&i.sessionId!==""&&e.uint32(26).string(i.sessionId),i.pageUrl!==void 0&&i.pageUrl!==""&&e.uint32(34).string(i.pageUrl),i.country!==void 0&&i.country!==""&&e.uint32(42).string(i.country),i.region!==void 0&&i.region!==""&&e.uint32(50).string(i.region),i.deviceType!==void 0&&i.deviceType!==""&&e.uint32(58).string(i.deviceType),i.userId!==void 0&&i.userId!==""&&e.uint32(66).string(i.userId),i.domain!==void 0&&i.domain!==""&&e.uint32(74).string(i.domain),i.events!==void 0&&i.events.length!==0)for(let t of i.events)j.encode(t,e.uint32(82).fork()).join();return i.browser!==void 0&&i.browser!==""&&e.uint32(90).string(i.browser),i.deviceManufacturer!==void 0&&i.deviceManufacturer!==""&&e.uint32(98).string(i.deviceManufacturer),i.deviceModel!==void 0&&i.deviceModel!==""&&e.uint32(106).string(i.deviceModel),i.city!==void 0&&i.city!==""&&e.uint32(114).string(i.city),i.postalCode!==void 0&&i.postalCode!==""&&e.uint32(122).string(i.postalCode),e},decode(i,e){let t=i instanceof B?i:new B(i),n=e===void 0?t.len:t.pos+e,r=Ue();for(;t.pos<n;){let o=t.uint32();switch(o>>>3){case 1:{if(o!==10)break;r.propertyId=t.string();continue}case 2:{if(o!==18)break;r.pageviewId=t.string();continue}case 3:{if(o!==26)break;r.sessionId=t.string();continue}case 4:{if(o!==34)break;r.pageUrl=t.string();continue}case 5:{if(o!==42)break;r.country=t.string();continue}case 6:{if(o!==50)break;r.region=t.string();continue}case 7:{if(o!==58)break;r.deviceType=t.string();continue}case 8:{if(o!==66)break;r.userId=t.string();continue}case 9:{if(o!==74)break;r.domain=t.string();continue}case 10:{if(o!==82)break;let s=j.decode(t,t.uint32());s!==void 0&&r.events.push(s);continue}case 11:{if(o!==90)break;r.browser=t.string();continue}case 12:{if(o!==98)break;r.deviceManufacturer=t.string();continue}case 13:{if(o!==106)break;r.deviceModel=t.string();continue}case 14:{if(o!==114)break;r.city=t.string();continue}case 15:{if(o!==122)break;r.postalCode=t.string();continue}}if((o&7)===4||o===0)break;t.skip(o&7)}return r},create(i){return Y.fromPartial(i??{})},fromPartial(i){let e=Ue();return e.propertyId=i.propertyId??"",e.pageviewId=i.pageviewId??"",e.sessionId=i.sessionId??"",e.pageUrl=i.pageUrl??"",e.country=i.country??"",e.region=i.region??"",e.deviceType=i.deviceType??"",e.userId=i.userId??"",e.domain=i.domain??"",e.events=i.events?.map(t=>j.fromPartial(t))||[],e.browser=i.browser??"",e.deviceManufacturer=i.deviceManufacturer??"",e.deviceModel=i.deviceModel??"",e.city=i.city??"",e.postalCode=i.postalCode??"",e}};j={encode(i,e=new M){if(i.timestampMs!==void 0&&i.timestampMs!==0&&e.uint32(9).double(i.timestampMs),i.type!==void 0&&i.type!==0&&e.uint32(16).int32(i.type),i.eventName!==void 0&&i.eventName!==""&&e.uint32(26).string(i.eventName),i.auctionId!==void 0&&i.auctionId!==""&&e.uint32(34).string(i.auctionId),i.transactionId!==void 0&&i.transactionId!==""&&e.uint32(42).string(i.transactionId),i.adUnitCode!==void 0&&i.adUnitCode!==""&&e.uint32(50).string(i.adUnitCode),i.bid!==void 0&&X.encode(i.bid,e.uint32(58).fork()).join(),i.namespace!==void 0&&i.namespace!==""&&e.uint32(66).string(i.namespace),i.eventId!==void 0&&i.eventId!==""&&e.uint32(74).string(i.eventId),globalThis.Object.entries(i.metadata||{}).forEach(([t,n])=>{fe.encode({key:t,value:n},e.uint32(82).fork()).join()}),i.viewableDurationMs!==void 0&&e.uint32(89).double(i.viewableDurationMs),i.bidderOutcomes!==void 0&&i.bidderOutcomes.length!==0)for(let t of i.bidderOutcomes)z.encode(t,e.uint32(98).fork()).join();return e},decode(i,e){let t=i instanceof B?i:new B(i),n=e===void 0?t.len:t.pos+e,r=Pe();for(;t.pos<n;){let o=t.uint32();switch(o>>>3){case 1:{if(o!==9)break;r.timestampMs=t.double();continue}case 2:{if(o!==16)break;r.type=t.int32();continue}case 3:{if(o!==26)break;r.eventName=t.string();continue}case 4:{if(o!==34)break;r.auctionId=t.string();continue}case 5:{if(o!==42)break;r.transactionId=t.string();continue}case 6:{if(o!==50)break;r.adUnitCode=t.string();continue}case 7:{if(o!==58)break;r.bid=X.decode(t,t.uint32());continue}case 8:{if(o!==66)break;r.namespace=t.string();continue}case 9:{if(o!==74)break;r.eventId=t.string();continue}case 10:{if(o!==82)break;let s=fe.decode(t,t.uint32());s.value!==void 0&&(r.metadata[s.key]=s.value);continue}case 11:{if(o!==89)break;r.viewableDurationMs=t.double();continue}case 12:{if(o!==98)break;let s=z.decode(t,t.uint32());s!==void 0&&r.bidderOutcomes.push(s);continue}}if((o&7)===4||o===0)break;t.skip(o&7)}return r},create(i){return j.fromPartial(i??{})},fromPartial(i){let e=Pe();return e.timestampMs=i.timestampMs??0,e.type=i.type??0,e.eventName=i.eventName??"",e.auctionId=i.auctionId??"",e.transactionId=i.transactionId??"",e.adUnitCode=i.adUnitCode??"",e.bid=i.bid!==void 0&&i.bid!==null?X.fromPartial(i.bid):void 0,e.namespace=i.namespace??"",e.eventId=i.eventId??"",e.metadata=globalThis.Object.entries(i.metadata??{}).reduce((t,[n,r])=>(r!==void 0&&(t[n]=globalThis.String(r)),t),{}),e.viewableDurationMs=i.viewableDurationMs??void 0,e.bidderOutcomes=i.bidderOutcomes?.map(t=>z.fromPartial(t))||[],e}};fe={encode(i,e=new M){return i.key!==""&&e.uint32(10).string(i.key),i.value!==""&&e.uint32(18).string(i.value),e},decode(i,e){let t=i instanceof B?i:new B(i),n=e===void 0?t.len:t.pos+e,r=Ne();for(;t.pos<n;){let o=t.uint32();switch(o>>>3){case 1:{if(o!==10)break;r.key=t.string();continue}case 2:{if(o!==18)break;r.value=t.string();continue}}if((o&7)===4||o===0)break;t.skip(o&7)}return r},create(i){return fe.fromPartial(i??{})},fromPartial(i){let e=Ne();return e.key=i.key??"",e.value=i.value??"",e}};z={encode(i,e=new M){return i.bidder!==void 0&&i.bidder!==""&&e.uint32(10).string(i.bidder),i.adUnitCode!==void 0&&i.adUnitCode!==""&&e.uint32(18).string(i.adUnitCode),i.mediaType!==void 0&&i.mediaType!==""&&e.uint32(26).string(i.mediaType),i.outcome!==void 0&&i.outcome!==0&&e.uint32(32).int32(i.outcome),i.latencyMs!==void 0&&i.latencyMs!==0&&e.uint32(41).double(i.latencyMs),e},decode(i,e){let t=i instanceof B?i:new B(i),n=e===void 0?t.len:t.pos+e,r=Ve();for(;t.pos<n;){let o=t.uint32();switch(o>>>3){case 1:{if(o!==10)break;r.bidder=t.string();continue}case 2:{if(o!==18)break;r.adUnitCode=t.string();continue}case 3:{if(o!==26)break;r.mediaType=t.string();continue}case 4:{if(o!==32)break;r.outcome=t.int32();continue}case 5:{if(o!==41)break;r.latencyMs=t.double();continue}}if((o&7)===4||o===0)break;t.skip(o&7)}return r},create(i){return z.fromPartial(i??{})},fromPartial(i){let e=Ve();return e.bidder=i.bidder??"",e.adUnitCode=i.adUnitCode??"",e.mediaType=i.mediaType??"",e.outcome=i.outcome??0,e.latencyMs=i.latencyMs??0,e}};X={encode(i,e=new M){return i.bidder!==void 0&&i.bidder!==""&&e.uint32(10).string(i.bidder),i.cpm!==void 0&&i.cpm!==0&&e.uint32(17).double(i.cpm),i.currency!==void 0&&i.currency!==""&&e.uint32(26).string(i.currency),i.width!==void 0&&i.width!==0&&e.uint32(32).int32(i.width),i.height!==void 0&&i.height!==0&&e.uint32(40).int32(i.height),i.dealId!==void 0&&i.dealId!==""&&e.uint32(50).string(i.dealId),i.mediaType!==void 0&&i.mediaType!==""&&e.uint32(58).string(i.mediaType),i.latencyMs!==void 0&&i.latencyMs!==0&&e.uint32(65).double(i.latencyMs),i.advertiserDomain!==void 0&&i.advertiserDomain!==""&&e.uint32(74).string(i.advertiserDomain),i.creativeId!==void 0&&i.creativeId!==""&&e.uint32(82).string(i.creativeId),e},decode(i,e){let t=i instanceof B?i:new B(i),n=e===void 0?t.len:t.pos+e,r=Fe();for(;t.pos<n;){let o=t.uint32();switch(o>>>3){case 1:{if(o!==10)break;r.bidder=t.string();continue}case 2:{if(o!==17)break;r.cpm=t.double();continue}case 3:{if(o!==26)break;r.currency=t.string();continue}case 4:{if(o!==32)break;r.width=t.int32();continue}case 5:{if(o!==40)break;r.height=t.int32();continue}case 6:{if(o!==50)break;r.dealId=t.string();continue}case 7:{if(o!==58)break;r.mediaType=t.string();continue}case 8:{if(o!==65)break;r.latencyMs=t.double();continue}case 9:{if(o!==74)break;r.advertiserDomain=t.string();continue}case 10:{if(o!==82)break;r.creativeId=t.string();continue}}if((o&7)===4||o===0)break;t.skip(o&7)}return r},create(i){return X.fromPartial(i??{})},fromPartial(i){let e=Fe();return e.bidder=i.bidder??"",e.cpm=i.cpm??0,e.currency=i.currency??"",e.width=i.width??0,e.height=i.height??0,e.dealId=i.dealId??"",e.mediaType=i.mediaType??"",e.latencyMs=i.latencyMs??0,e.advertiserDomain=i.advertiserDomain??"",e.creativeId=i.creativeId??"",e}}});function F(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,i=>{let e=Math.random()*16|0;return(i==="x"?e:e&3|8).toString(16)})}function xt(i){let e="";for(let n=0;n<i.length;n+=8192)e+=String.fromCharCode(...i.subarray(n,n+8192));return btoa(e)}function Ct(i){let e=atob(i),t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return t}function St(i){if(!i)return!1;let e;try{e=new URL(i)}catch{return!1}return e.username||e.password?!1:e.protocol==="https:"?!0:e.protocol==="http:"?e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname==="[::1]":!1}function Dt(i){let e={},t=0;for(let n of Object.keys(i)){if(t>=It)break;let r=i[n];if(r==null)continue;let o=String(r);e[n]=o.length>qe?`${o.slice(0,qe)}...[truncated]`:o,t++}return e}function Ot(i){let e=i.slice(J.length).split("_");return e.length===2&&/^\d+$/.test(e[0])}function Lt(i,e){if(!i||!e)return!1;try{return new URL(i).origin===new URL(e).origin}catch{return!1}}function je(){let i=Date.now();q=i;try{typeof localStorage<"u"&&localStorage.setItem(ee,i.toString())}catch{}}function Mt(){let i=Date.now();try{if(typeof localStorage<"u"){let e=localStorage.getItem(He),t=localStorage.getItem(ee),n=t&&parseInt(t,10)||0;if(e&&n&&i-n<=Ge)return localStorage.setItem(ee,i.toString()),e;let r=F();return localStorage.setItem(He,r),localStorage.setItem(ee,i.toString()),r}}catch{}return Z&&q&&i-q<=Ge?(q=i,Z):(Z=F(),q=i,Z)}function h(i){return String(i??"").replace(/%/g,"%25").replace(/:/g,"%3A")}function kt(i,e){switch(i){case"auctionInit":return`auctionInit:${h(e?.auctionId)}`;case"auctionEnd":return`auctionEnd:${h(e?.auctionId)}`;case"bidRequested":{let t=Array.isArray(e?.bids)?e.bids.map(n=>h(n?.bidId||n?.transactionId||n?.adUnitCode)).join(","):"";return`bidRequested:${h(e?.auctionId)}:${h(e?.bidderCode||e?.bidder)}:${t}`}case"bidResponse":{let t=e||{},n=t.creativeId||t.adId||t.requestId||t.bidId||"",r=t.originalCpm??t.cpm??"";return`bidResponse:${h(t.auctionId)}:${h(t.adUnitCode)}:${h(t.bidderCode||t.bidder)}:${h(n)}:${h(r)}`}case"bidTimeout":return"bidTimeout:"+(Array.isArray(e)?e:e?[e]:[]).map(n=>`${h(n?.auctionId)}:${h(n?.bidderCode||n?.bidder)}:${h(n?.bidId||n?.transactionId||n?.adUnitCode)}`).join(",");case"bidWon":{let t=e||{},n=t.creativeId||t.adId||t.requestId||t.bidId||"",r=t.originalCpm??t.cpm??"";return`bidWon:${h(t.auctionId)}:${h(t.adUnitCode)}:${h(t.bidderCode||t.bidder)}:${h(n)}:${h(r)}`}case"noBid":return`noBid:${h(e?.auctionId)}:${h(e?.adUnitCode)}:${h(e?.bidderCode||e?.bidder)}:${h(e?.bidId||e?.transactionId)}`;case"adRenderFailed":{let t=e?.bid||{};return`adRenderFailed:${h(t.auctionId||e?.auctionId)}:${h(t.adUnitCode||e?.adUnitCode)}:${h(t.bidderCode||t.bidder||e?.bidderCode||e?.bidder)}:${h(e?.reason)}:${h(e?.message)}`}case"adRenderSucceeded":{let t=e?.bid||e||{},n=t.creativeId||t.adId||e?.adId||"",r=t.originalCpm??t.cpm??"";return`adRenderSucceeded:${h(t.auctionId||e?.auctionId)}:${h(t.adUnitCode||e?.adUnitCode)}:${h(t.bidderCode||t.bidder)}:${h(n)}:${h(r)}`}case"setTargeting":return`setTargeting:${Object.keys(e||{}).sort().map(h).join(",")}`;case"auctionDebug":return`auctionDebug:${h(e?.type)}:${h(String(e?.arguments?.[0]??"").slice(0,50))}`;default:return""}}function k(i){if(Number.isFinite(i?.width)&&Number.isFinite(i?.height))return{width:i.width,height:i.height};if(typeof i?.size=="string"){let e=i.size.match(/^(\d+)x(\d+)$/);if(e)return{width:Number(e[1]),height:Number(e[2])}}return{width:Number.isFinite(i?.width)?i.width:0,height:Number.isFinite(i?.height)?i.height:0}}function ze(i){if(i)try{let e=i.prototype;if(e&&typeof e.getAdsManager=="function"&&!e.getAdsManager.__bidkernelHooked){let t=e.getAdsManager,n=function(...r){let o=t.apply(this,r);if(o)for(let s of V.getActiveInstances())try{s.attachImaAdsManager(o)}catch{}return o};n.__bidkernelHooked=!0,e.getAdsManager=n}}catch{}}function Xe(i){if(i)try{let e=i.prototype||i;if(e&&typeof e.init=="function"&&!e.init.__bidkernelHooked){let t=e.init,n=function(...r){for(let o of V.getActiveInstances())try{o.attachImaAdsManager(this)}catch{}return t.apply(this,r)};n.__bidkernelHooked=!0,e.init=n}if(e&&typeof e.start=="function"&&!e.start.__bidkernelHooked){let t=e.start,n=function(...r){for(let o of V.getActiveInstances())try{o.attachImaAdsManager(this)}catch{}return t.apply(this,r)};n.__bidkernelHooked=!0,e.start=n}}catch{}}function Ye(i){if(i)try{let e=i.prototype;if(!e)return;if(typeof e.addEventListener=="function"&&!e.addEventListener.__bidkernelHooked){let t=e.addEventListener,n=function(r,o,...s){if((r==="adsManagerLoaded"||r===(this?.AdsManagerLoadedEvent?.Type?.ADS_MANAGER_LOADED||"adsManagerLoaded"))&&typeof o=="function"){let d=pe.get(o);return d||(d=function(a){if(a&&typeof a.getAdsManager=="function"&&!a.getAdsManager.__bidkernelHooked){let l=a.getAdsManager;a.getAdsManager=function(...u){let y=l.apply(this,u);if(y)for(let f of V.getActiveInstances())try{f.attachImaAdsManager(y)}catch{}return y},a.getAdsManager.__bidkernelHooked=!0}return o.apply(this,arguments)},pe.set(o,d)),t.call(this,r,d,...s)}return t.call(this,r,o,...s)};n.__bidkernelHooked=!0,e.addEventListener=n}if(typeof e.removeEventListener=="function"&&!e.removeEventListener.__bidkernelHooked){let t=e.removeEventListener,n=function(r,o,...s){let d=typeof o=="function"?pe.get(o):void 0;return t.call(this,r,d||o,...s)};n.__bidkernelHooked=!0,e.removeEventListener=n}}catch{}}function K(i){if(!(!i||typeof i!="object"))try{i.AdsManagerLoadedEvent&&ze(i.AdsManagerLoadedEvent);let e=Object.getOwnPropertyDescriptor(i,"AdsManagerLoadedEvent");if(!e||e.configurable){let r=i.AdsManagerLoadedEvent;try{Object.defineProperty(i,"AdsManagerLoadedEvent",{configurable:!0,enumerable:!0,get(){return r},set(o){r=o,ze(o)}})}catch{}}i.AdsLoader&&Ye(i.AdsLoader);let t=Object.getOwnPropertyDescriptor(i,"AdsLoader");if(!t||t.configurable){let r=i.AdsLoader;try{Object.defineProperty(i,"AdsLoader",{configurable:!0,enumerable:!0,get(){return r},set(o){r=o,Ye(o)}})}catch{}}i.AdsManager&&Xe(i.AdsManager);let n=Object.getOwnPropertyDescriptor(i,"AdsManager");if(!n||n.configurable){let r=i.AdsManager;try{Object.defineProperty(i,"AdsManager",{configurable:!0,enumerable:!0,get(){return r},set(o){r=o,Xe(o)}})}catch{}}}catch{}}function me(){if(typeof window>"u")return;let i=window;if(i.google?.ima&&K(i.google.ima),i.google&&typeof i.google=="object"){let t=Object.getOwnPropertyDescriptor(i.google,"ima");if(!t||t.configurable){let n=i.google.ima;try{Object.defineProperty(i.google,"ima",{configurable:!0,enumerable:!0,get(){return n},set(r){n=r,K(r)}})}catch{}}}let e=Object.getOwnPropertyDescriptor(i,"google");if(!e||e.configurable){let t=i.google;try{Object.defineProperty(i,"google",{configurable:!0,enumerable:!0,get(){return t},set(n){if(t=n,t&&typeof t=="object"){t.ima&&K(t.ima);let r=Object.getOwnPropertyDescriptor(t,"ima");if(!r||r.configurable){let o=t.ima;try{Object.defineProperty(t,"ima",{configurable:!0,enumerable:!0,get(){return o},set(s){o=s,K(s)}})}catch{}}}}})}catch{}}}function $(i,e=!0){if(!i)return null;if(Array.isArray(i)){let t=i.find(n=>n?.provider==="bidkernel")??(e?i.find(n=>n&&typeof n=="object"&&n.provider===void 0):void 0);return t?$(t,e):null}if(typeof i=="object"){if(i.options&&typeof i.options=="object")return i.options;if(i.config&&typeof i.config=="object")return i.config;if(i.propertyId||i.endpoint)return i}return null}function Ut(i){if(!i)return null;if(i._bidkernelAnalyticsConfig){let e=$(i._bidkernelAnalyticsConfig);if(e)return e}if(i.bidkernelPrebidAnalytics){let e=i.bidkernelPrebidAnalytics;if(e.options){let t=$(e.options);if(t)return t}if(e.config){let t=$(e.config);if(t)return t}if(e.propertyId)return $(e)}return null}function be(i="pbjs",e){let t=typeof window<"u"?window:{};t[i]=t[i]||{};let n=t[i],r=s=>{let d=t._bidkernelPrebidAnalytics,a=d?.getEndpoint?.()||"",l={pbjsGlobalName:i,...e,...s};if(a&&!Lt(l.endpoint||"",a)&&(ye.warn(`Ignoring analytics endpoint change to ${l.endpoint||"(empty)"}: this page is pinned to ${a}. Reload to change the ingest endpoint.`),l.endpoint=a),d)try{d.disable()}catch(y){ye.warn("Failed to disable previous analytics instance:",y)}let u=new V(l);return u.enable(),t._bidkernelPrebidAnalytics=u,u},o=()=>{try{n.adapterManager&&typeof n.adapterManager.registerAnalyticsAdapter=="function"&&n.adapterManager.registerAnalyticsAdapter({adapter:{enableAnalytics:d=>{let a=$(d,!Array.isArray(d));a&&r(a)},disableAnalytics:()=>{t._bidkernelPrebidAnalytics&&t._bidkernelPrebidAnalytics.disable()}},code:"bidkernel"});let s=Ut(t);s&&(s.propertyId||e?.propertyId)&&r(s)}catch(s){ye.warn("Failed to register standard Prebid analytics adapter:",s)}};n.adapterManager&&typeof n.adapterManager.registerAnalyticsAdapter=="function"?o():(n.que=n.que||[],n.que.push(o))}var yt,We,gt,Q,mt,bt,he,qe,It,Ke,J,vt,Tt,Et,wt,At,N,Rt,_t,Bt,He,ee,Ge,Z,q,ge,pe,V,ye,Qe=x(()=>{"use strict";Te();$e();yt=20,We=1e4,gt=50,Q=200,mt=300*1e3,bt=10,he=32*1024,qe=1024,It=16,Ke="text/plain",J="_bidkernel_pending_",vt=20,Tt=7200*1e3,Et=1e4,wt={auctionStart:b.AUCTION_START,auctionEnd:b.AUCTION_END,bidResponse:b.BID_RESPONSE,bidWin:b.BID_WIN,adRenderFailed:b.AD_RENDER_FAILED,click:b.CLICK,impression:b.IMPRESSION,refresh:b.REFRESH,timeInView:b.TIME_IN_VIEW,viewable:b.VIEWABLE},At=new Set([b.IMPRESSION,b.BID_WIN,b.CLICK]),N=1800*1e3,Rt=200,_t=1e3,Bt=50,He="_bidkernel_session",ee="_bidkernel_session_ts",Ge=1800*1e3,Z=null,q=0;ge=class{seenObjects=new WeakMap;seenKeys=new Set;isDuplicate(e,t){if(!t)return!1;if(typeof t=="object"){let r=this.seenObjects.get(t);if(r){if(r.has(e))return!0;r.add(e)}else this.seenObjects.set(t,new Set([e]))}let n=kt(e,t);if(n){if(this.seenKeys.has(n))return!0;if(this.seenKeys.size>=1e3){let r=this.seenKeys.values().next().value;r!==void 0&&this.seenKeys.delete(r)}this.seenKeys.add(n)}return!1}};pe=new WeakMap;typeof window<"u"&&me();V=class i{static activeInstances=new Set;static getActiveInstances(){return i.activeInstances}static initImaInterception(){me()}config;queue=[];errorCount=0;flushTimer=null;boundFlushBeacon;boundVisibilityChange;isEnabled=!1;boundPbjsHandlers=[];pageUrl="";deduper=new ge;consecutiveSendFailures=0;nextSendAllowedAt=0;replayedEventCount=0;immediateFlushScheduled=!1;persistedBatchKeys=[];persistedCleanupTimer=null;intersectionObserver=null;slotViewabilityRecords=new Map;elementToSlotId=new Map;slotRefreshIndices=new Map;slotLastAuctionIds=new Map;pendingThresholdListeners=new Map;slotEmittedImpressionKeys=new Set;cachedWinningBids=new Map;videoDetachCleanups=new Set;auctionBidderOutcomes=new Map;logger;constructor(e){let t=e.endpoint||"",n=!t||St(t)?t:"";this.config={endpoint:n,propertyId:e.propertyId||"",pageviewId:e.pageviewId||F(),sessionId:e.sessionId||Mt(),userId:e.userId||"",deviceType:e.deviceType||"desktop",country:e.country||"",region:e.region||"",auctionEnabled:e.auctionEnabled??!0,warningsEnabled:e.warningsEnabled??!0,errorsEnabled:e.errorsEnabled??!0,viewabilityEnabled:e.viewabilityEnabled??!0,logLevel:e.logLevel||"INFO",pbjsGlobalName:e.pbjsGlobalName||"pbjs",attachPbjsListeners:e.attachPbjsListeners??!0},this.logger=ie({prefix:"[bidkernel][prebid-analytics]",logLevel:this.config.logLevel}),t&&!n&&this.log("ERROR",`Rejected untrusted analytics endpoint ${t}: must be an absolute https:// URL without embedded credentials. Events will not be transmitted.`),this.boundFlushBeacon=()=>{this.flushAllSlotsTimeInView(),this.flushBeacon()},this.boundVisibilityChange=()=>this.handleVisibilityChange()}enable(){if(!this.isEnabled){if(this.isEnabled=!0,i.activeInstances.add(this),this.logger.setLevel(this.config.logLevel),this.config.endpoint||this.log("WARN","Endpoint is empty. Analytics events will not be transmitted."),this.config.viewabilityEnabled&&typeof IntersectionObserver<"u"){this.intersectionObserver=new IntersectionObserver(this.handleIntersection.bind(this),{threshold:[.5]});for(let e of this.slotViewabilityRecords.values())e.element&&this.intersectionObserver.observe(e.element)}if(this.config.attachPbjsListeners){let t=(typeof window<"u"?window:{})[this.config.pbjsGlobalName]||{};if(typeof t.onEvent=="function"){this.log("DEBUG","Attaching event listeners to pbjs");let n=[["auctionInit",this.handleAuctionInit.bind(this)],["auctionEnd",this.handleAuctionEnd.bind(this)],["bidRequested",this.handleBidRequested.bind(this)],["bidResponse",this.handleBidResponse.bind(this)],["bidTimeout",this.handleBidTimeout.bind(this)],["bidWon",this.handleBidWon.bind(this)],["noBid",this.handleNoBid.bind(this)],["adRenderFailed",this.handleAdRenderFailed.bind(this)],["adRenderSucceeded",this.handleAdRenderSucceeded.bind(this)]];for(let[r,o]of n)t.onEvent(r,o),this.boundPbjsHandlers.push({event:r,handler:o})}else this.log("WARN","pbjs.onEvent is not defined. Prebid analytics will not function.");if(typeof t.getEvents=="function")try{let n=t.getEvents();if(Array.isArray(n)){let r=n.slice(this.replayedEventCount);if(this.replayedEventCount=n.length,r.length>0){this.log("DEBUG",`Replaying ${r.length} historical events from pbjs.getEvents()`);let o={auctionInit:this.handleAuctionInit.bind(this),auctionEnd:this.handleAuctionEnd.bind(this),bidRequested:this.handleBidRequested.bind(this),bidResponse:this.handleBidResponse.bind(this),bidTimeout:this.handleBidTimeout.bind(this),bidWon:this.handleBidWon.bind(this),noBid:this.handleNoBid.bind(this),adRenderFailed:this.handleAdRenderFailed.bind(this),adRenderSucceeded:this.handleAdRenderSucceeded.bind(this)};for(let s of r){if(!s)continue;let d=s.eventType||s.event||s.name,a=s.args!==void 0?s.args:s.data!==void 0?s.data:s,l=o[d];l&&l(a)}}}}catch(n){this.log("WARN","Failed to replay historical events from pbjs.getEvents()",n)}}if(typeof window<"u"){if(!this.pageUrl)try{let e=new URL(window.location.href);this.pageUrl=e.origin+e.pathname}catch{this.pageUrl=window.location.href}window.addEventListener("pagehide",this.boundFlushBeacon),typeof document<"u"&&document.addEventListener("visibilitychange",this.boundVisibilityChange),this.flushTimer=setInterval(()=>this.flush(),We),this.resendPersistedBatches(),me(),window.google?.ima&&K(window.google.ima)}}}disable(){if(this.isEnabled){this.flushAllSlotsTimeInView(),this.isEnabled=!1,i.activeInstances.delete(this);for(let e of this.slotViewabilityRecords.values()){e.dwellTimer&&(clearTimeout(e.dwellTimer),e.dwellTimer=null,e.dwellStartedAt=null);for(let t of e.thresholdListeners)t.timer&&(clearTimeout(t.timer),t.timer=null)}this.intersectionObserver&&(this.intersectionObserver.disconnect(),this.intersectionObserver=null),this.slotViewabilityRecords.clear(),this.elementToSlotId.clear();for(let e of this.videoDetachCleanups)try{e()}catch{}if(this.videoDetachCleanups.clear(),this.cachedWinningBids.clear(),this.slotEmittedImpressionKeys.clear(),this.slotLastAuctionIds.clear(),this.auctionBidderOutcomes.clear(),this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.persistedCleanupTimer&&(clearTimeout(this.persistedCleanupTimer),this.persistedCleanupTimer=null),typeof window<"u"&&(window.removeEventListener("pagehide",this.boundFlushBeacon),typeof document<"u"&&document.removeEventListener("visibilitychange",this.boundVisibilityChange)),this.boundPbjsHandlers.length>0){let t=(typeof window<"u"?window:{})[this.config.pbjsGlobalName]||{};if(typeof t.offEvent=="function")for(let{event:n,handler:r}of this.boundPbjsHandlers)t.offEvent(n,r);this.boundPbjsHandlers=[]}this.flush()}}handleVisibilityChange(){if(!(typeof document>"u")){if(document.visibilityState==="hidden"){let e=typeof performance<"u"&&performance.now?performance.now():Date.now();for(let t of this.slotViewabilityRecords.values()){t.inView&&t.lastEnteredViewAt!==null&&(t.accumulatedTimeInViewMs+=Math.max(0,e-t.lastEnteredViewAt),t.lastEnteredViewAt=null,this.checkThresholdListeners(t)),t.dwellTimer&&(clearTimeout(t.dwellTimer),t.dwellTimer=null,t.dwellStartedAt=null);for(let r of t.thresholdListeners)r.timer&&(clearTimeout(r.timer),r.timer=null);let n=Math.round(t.accumulatedTimeInViewMs);n>0&&this.enqueue(b.TIME_IN_VIEW,"timeInView",{auctionId:t.auctionId,transactionId:t.transactionId,adUnitCode:t.adUnitCode,viewableDurationMs:n,bid:t.bidPayload,metadata:{...t.metadata,refresh_index:String(t.refreshIndex)}})}this.flushBeacon()}else if(document.visibilityState==="visible"){let e=typeof performance<"u"&&performance.now?performance.now():Date.now();for(let t of this.slotViewabilityRecords.values())if(t.inView){if(t.lastEnteredViewAt=e,!t.viewableFired&&t.dwellTimer===null){let n=t.mediaType==="video"?2e3:1e3;t.dwellStartedAt=e,t.dwellTimer=setTimeout(()=>{this.handleDwellComplete(t)},n)}this.scheduleThresholdTimers(t)}}}}handleIntersection(e){for(let t of e){let n=this.elementToSlotId.get(t.target);if(!n){for(let a of i.activeInstances)if(a!==this&&a.elementToSlotId.has(t.target)){a.handleIntersection([t]);break}continue}let r=this.slotViewabilityRecords.get(n);if(!r)continue;let o=t.isIntersecting&&(t.intersectionRatio===void 0||t.intersectionRatio>=.5),s=typeof document>"u"||document.visibilityState==="visible",d=typeof performance<"u"&&performance.now?performance.now():Date.now();if(o){if(!r.inView&&(r.inView=!0,s)){if(r.lastEnteredViewAt=d,!r.viewableFired&&r.dwellTimer===null){let a=r.mediaType==="video"?2e3:1e3;r.dwellStartedAt=d,r.dwellTimer=setTimeout(()=>{this.handleDwellComplete(r)},a)}this.scheduleThresholdTimers(r)}}else{r.inView&&(r.lastEnteredViewAt!==null&&(r.accumulatedTimeInViewMs+=Math.max(0,d-r.lastEnteredViewAt),r.lastEnteredViewAt=null),r.inView=!1,this.checkThresholdListeners(r)),r.dwellTimer!==null&&(clearTimeout(r.dwellTimer),r.dwellTimer=null,r.dwellStartedAt=null);for(let a of r.thresholdListeners)a.timer&&(clearTimeout(a.timer),a.timer=null)}}}handleDwellComplete(e){e.dwellTimer=null,e.dwellStartedAt=null,e.inView&&(typeof document<"u"&&document.visibilityState==="hidden"||e.viewableFired||(e.viewableFired=!0,this.enqueue(b.VIEWABLE,"viewable",{auctionId:e.auctionId,transactionId:e.transactionId,adUnitCode:e.adUnitCode,bid:e.bidPayload,metadata:{...e.metadata,refresh_index:String(e.refreshIndex)}})))}scheduleThresholdTimers(e){if(!e.inView||typeof document<"u"&&document.visibilityState==="hidden")return;let t=this.getCurrentTimeInView(e);for(let n of e.thresholdListeners)if(!n.fired)if(t>=n.thresholdMs){n.fired=!0,n.timer&&(clearTimeout(n.timer),n.timer=null);try{n.callback(e.slotId,t)}catch(r){this.log("ERROR","Error in threshold listener callback",r)}}else{n.timer&&clearTimeout(n.timer);let r=n.thresholdMs-t;n.timer=setTimeout(()=>{if(n.timer=null,!n.fired&&e.inView&&(typeof document>"u"||document.visibilityState==="visible")){let o=this.getCurrentTimeInView(e);if(o>=n.thresholdMs){n.fired=!0;try{n.callback(e.slotId,o)}catch(s){this.log("ERROR","Error in threshold listener callback",s)}}}},r)}}checkThresholdListeners(e){let t=this.getCurrentTimeInView(e);for(let n of e.thresholdListeners)if(!n.fired&&t>=n.thresholdMs){n.fired=!0,n.timer&&(clearTimeout(n.timer),n.timer=null);try{n.callback(e.slotId,t)}catch(r){this.log("ERROR","Error in threshold listener callback",r)}}}getCurrentTimeInView(e){let t=e.accumulatedTimeInViewMs;if(e.inView&&e.lastEnteredViewAt!==null){let n=typeof performance<"u"&&performance.now?performance.now():Date.now();t+=Math.max(0,n-e.lastEnteredViewAt)}return t}flushSlotTimeInView(e){let t=this.slotViewabilityRecords.get(e);if(!t)return;if(t.inView&&t.lastEnteredViewAt!==null){let r=typeof performance<"u"&&performance.now?performance.now():Date.now();t.accumulatedTimeInViewMs+=Math.max(0,r-t.lastEnteredViewAt),t.lastEnteredViewAt=null}let n=Math.round(t.accumulatedTimeInViewMs);n>0&&this.enqueue(b.TIME_IN_VIEW,"timeInView",{auctionId:t.auctionId,transactionId:t.transactionId,adUnitCode:t.adUnitCode,viewableDurationMs:n,bid:t.bidPayload,metadata:{...t.metadata,refresh_index:String(t.refreshIndex)}}),t.accumulatedTimeInViewMs=0}flushAllSlotsTimeInView(){for(let e of Array.from(this.slotViewabilityRecords.keys()))this.flushSlotTimeInView(e)}observeSlot(e,t,n){if(!this.config.viewabilityEnabled)return;let r=null;if(typeof e=="string"){if(typeof document<"u"){try{r=document.querySelector(e)||document.getElementById(e)}catch{r=document.getElementById(e)}r||(r=document.getElementById(e))}}else r=e;let o=t||n?.adUnitCode||(r?r.id:"")||F(),s=this.slotViewabilityRecords.get(o);if(s){if(n?.refreshIndex===void 0||n.refreshIndex>s.refreshIndex){this.flushSlotTimeInView(o);let a=n?.refreshIndex!==void 0?n.refreshIndex:(this.slotRefreshIndices.get(o)??s.refreshIndex)+1;this.slotRefreshIndices.set(o,a),n?.emitRefreshEvent!==!1&&this.enqueue(b.REFRESH,"refresh",{auctionId:n?.auctionId||s.auctionId,transactionId:n?.transactionId||s.transactionId,adUnitCode:o,bid:n?.bid??s.bidPayload,metadata:{...n?.metadata,refresh_index:String(a)}}),s.dwellTimer&&(clearTimeout(s.dwellTimer),s.dwellTimer=null,s.dwellStartedAt=null);for(let u of s.thresholdListeners)u.fired=!1,u.timer&&(clearTimeout(u.timer),u.timer=null);s.viewableFired=!1,s.accumulatedTimeInViewMs=0;let l=typeof performance<"u"&&performance.now?performance.now():Date.now();if(s.lastEnteredViewAt=s.inView?l:null,s.refreshIndex=a,s.auctionId=n?.auctionId||s.auctionId,s.transactionId=n?.transactionId||s.transactionId,s.mediaType=n?.mediaType||s.mediaType||"banner",s.bidPayload=n?.bid!==void 0?n.bid:s.bidPayload,s.metadata=n?.metadata??s.metadata,s.inView&&(typeof document>"u"||document.visibilityState==="visible")){let u=s.mediaType==="video"?2e3:1e3;s.dwellStartedAt=l,s.dwellTimer=setTimeout(()=>{this.handleDwellComplete(s)},u),this.scheduleThresholdTimers(s)}}else s.auctionId=n?.auctionId||s.auctionId,s.transactionId=n?.transactionId||s.transactionId,s.mediaType=n?.mediaType||s.mediaType,n?.bid!==void 0&&(s.bidPayload=n.bid),n?.metadata!==void 0&&(s.metadata=n.metadata);n?.auctionId&&this.slotLastAuctionIds.set(o,n.auctionId),r&&(s.element&&s.element!==r&&this.intersectionObserver&&(this.intersectionObserver.unobserve(s.element),this.elementToSlotId.delete(s.element)),s.element=r,this.elementToSlotId.set(r,o),this.intersectionObserver?.observe(r))}else{let d=n?.refreshIndex??this.slotRefreshIndices.get(o)??0;this.slotRefreshIndices.set(o,d),n?.auctionId&&this.slotLastAuctionIds.set(o,n.auctionId);let a=this.pendingThresholdListeners.get(o)||new Set;this.pendingThresholdListeners.delete(o);let l={slotId:o,element:r,adUnitCode:n?.adUnitCode||o,auctionId:n?.auctionId||"",transactionId:n?.transactionId||"",mediaType:n?.mediaType||"banner",bidPayload:n?.bid,metadata:n?.metadata,refreshIndex:d,inView:!1,lastEnteredViewAt:null,accumulatedTimeInViewMs:0,viewableFired:!1,dwellTimer:null,dwellStartedAt:null,thresholdListeners:a};this.slotViewabilityRecords.set(o,l),r&&(this.elementToSlotId.set(r,o),this.intersectionObserver?.observe(r))}}unobserveSlot(e){let t=this.slotViewabilityRecords.get(e);if(t){this.flushSlotTimeInView(e),t.dwellTimer&&(clearTimeout(t.dwellTimer),t.dwellTimer=null,t.dwellStartedAt=null);for(let n of t.thresholdListeners)n.timer&&(clearTimeout(n.timer),n.timer=null);t.thresholdListeners=new Set,t.element&&this.intersectionObserver&&(this.intersectionObserver.unobserve(t.element),this.elementToSlotId.delete(t.element),t.element=null),t.inView=!1,t.lastEnteredViewAt=null}}destroySlot(e){this.unobserveSlot(e),this.slotViewabilityRecords.delete(e),this.slotRefreshIndices.delete(e),this.slotLastAuctionIds.delete(e),this.pendingThresholdListeners.delete(e);let t=`${h(e)}:`;for(let r of Array.from(this.slotEmittedImpressionKeys))(r===e||r.startsWith(t))&&this.slotEmittedImpressionKeys.delete(r);let n=this.cachedWinningBids.get(e);n&&this.deleteCachedBidEntry(n)}getCachedBid(e){let t=this.cachedWinningBids.get(e);if(t){if(Date.now()-t.timestamp>N){this.deleteCachedBidEntry(t);return}return t}}deleteCachedBidEntry(e){for(let[t,n]of Array.from(this.cachedWinningBids))n===e&&this.cachedWinningBids.delete(t)}pruneCachedWinningBids(){let e=Date.now();for(let[t,n]of Array.from(this.cachedWinningBids))e-n.timestamp>N&&this.cachedWinningBids.delete(t);for(;this.cachedWinningBids.size>Rt;){let t=this.cachedWinningBids.keys().next();if(t.done)break;this.cachedWinningBids.delete(t.value)}}findCachedWinningBid(e){let t=Date.now(),n=s=>this.hasImpressionEmitted(s.adUnitCode,void 0,s.auctionId,s.bidTrace.creativeId);if(e?.creativeId||e?.adId){for(let s of Array.from(this.cachedWinningBids.values()))if(!(t-s.timestamp>N)&&(e.creativeId&&(s.bidTrace.creativeId===e.creativeId||s.rawBid?.creativeId===e.creativeId)||e.adId&&(s.rawBid?.adId===e.adId||s.adUnitCode===e.adId)))return s}let r;if(e?.mediaType){for(let d of Array.from(this.cachedWinningBids.values())){if(t-d.timestamp>N)continue;(d.bidTrace.mediaType===e.mediaType||d.rawBid?.mediaType===e.mediaType||e.mediaType==="video"&&d.rawBid?.mediaTypes?.video!==void 0)&&(n(d)||(!r||d.timestamp<r.timestamp)&&(r=d))}if(r)return r;let s;for(let d of Array.from(this.cachedWinningBids.values())){if(t-d.timestamp>N)continue;(d.bidTrace.mediaType===e.mediaType||d.rawBid?.mediaType===e.mediaType||e.mediaType==="video"&&d.rawBid?.mediaTypes?.video!==void 0)&&(!s||d.timestamp>s.timestamp)&&(s=d)}if(s)return s}for(let s of Array.from(this.cachedWinningBids.values()))t-s.timestamp>N||n(s)||(!r||s.timestamp>r.timestamp)&&(r=s);if(r)return r;let o;for(let s of Array.from(this.cachedWinningBids.values()))t-s.timestamp>N||(!o||s.timestamp>o.timestamp)&&(o=s);return o}addImpressionKey(e){if(!this.slotEmittedImpressionKeys.has(e)){for(;this.slotEmittedImpressionKeys.size>=_t;){let t=this.slotEmittedImpressionKeys.values().next();if(t.done)break;this.slotEmittedImpressionKeys.delete(t.value)}this.slotEmittedImpressionKeys.add(e)}}getOrCreateAuctionOutcomes(e){let t=this.auctionBidderOutcomes.get(e);for(t||(t=new Map,this.auctionBidderOutcomes.set(e,t));this.auctionBidderOutcomes.size>Bt;){let n=this.auctionBidderOutcomes.keys().next();if(n.done||n.value===e)break;this.auctionBidderOutcomes.delete(n.value)}return t}hasImpressionEmitted(e,t,n,r){let o=t??this.slotRefreshIndices.get(e)??0,s=`${h(e)}:${o}`;return r?n?this.slotEmittedImpressionKeys.has(`${s}:auc:${h(n)}:${h(r)}`)||this.slotEmittedImpressionKeys.has(`${s}:${h(r)}`):this.slotEmittedImpressionKeys.has(`${s}:${h(r)}`):n?this.slotEmittedImpressionKeys.has(`${s}:auc:${h(n)}`):this.slotEmittedImpressionKeys.has(s)}markImpressionEmitted(e,t,n,r){let o=`${h(e)}:${t}`;this.addImpressionKey(o),r&&this.addImpressionKey(`${o}:${h(r)}`),n&&(this.addImpressionKey(`${o}:auc:${h(n)}`),r&&this.addImpressionKey(`${o}:auc:${h(n)}:${h(r)}`))}recordImpression(e,t){if(!this.isEnabled)return!1;let n=e||t?.adUnitCode||"",r=t?.adUnitCode||n,o=(t?.auctionId&&n?this.getCachedBid(`${t.auctionId}:${n}`):void 0)||(t?.auctionId&&r?this.getCachedBid(`${t.auctionId}:${r}`):void 0)||(n?this.getCachedBid(n):void 0)||(r?this.getCachedBid(r):void 0),s=t?.bid||o?.rawBid||{},d=t?.auctionId||s.auctionId||o?.auctionId||"",a=t?.transactionId||s.transactionId||o?.transactionId||"",l=s.creativeId||o?.bidTrace?.creativeId||t?.bid?.creativeId||"",u=t?.mediaType||s.mediaType||o?.bidTrace?.mediaType||"banner",y=n||r,f=(n?this.slotViewabilityRecords.get(n):void 0)||(r?this.slotViewabilityRecords.get(r):void 0),v=y?this.slotLastAuctionIds.get(y)||(f?f.auctionId:void 0):void 0,T=!!(y&&d&&v&&v!==d&&t?.refreshIndex===void 0),p={bidder:s.bidderCode||s.bidder||o?.bidTrace?.bidder||"",cpm:Number.isFinite(s.originalCpm)?s.originalCpm:Number.isFinite(s.cpm)?s.cpm:o?.bidTrace?.cpm??0,currency:s.originalCurrency??s.currency??o?.bidTrace?.currency??"USD",...k(s).width?k(s):o?.bidTrace?{width:o.bidTrace.width,height:o.bidTrace.height}:k(s),dealId:s.dealId||o?.bidTrace?.dealId||"",mediaType:u,latencyMs:Number.isFinite(s.timeToRespond)?s.timeToRespond:o?.bidTrace?.latencyMs??0,advertiserDomain:s.meta?.advertiserDomains?.[0]||o?.bidTrace?.advertiserDomain||"",creativeId:s.creativeId||o?.bidTrace?.creativeId||""};if(T&&y){this.flushSlotTimeInView(y);let w=(this.slotRefreshIndices.get(y)??(f?f.refreshIndex:0))+1;this.slotRefreshIndices.set(y,w),this.slotLastAuctionIds.set(y,d),f&&(f.refreshIndex=w,f.auctionId=d,f.transactionId=a,f.bidPayload=p,f.viewableFired=!1,f.accumulatedTimeInViewMs=0),this.enqueue(b.REFRESH,"refresh",{auctionId:d,transactionId:a,adUnitCode:y,bid:p,metadata:{...t?.metadata,refresh_index:String(w)}})}else y&&(d&&this.slotLastAuctionIds.set(y,d),this.slotRefreshIndices.has(y)||this.slotRefreshIndices.set(y,0));let _=t?.refreshIndex??(n?this.slotRefreshIndices.get(n)??(r?this.slotRefreshIndices.get(r):void 0)??(f?f.refreshIndex:0):0);return n&&this.hasImpressionEmitted(n,_,d,l)||r&&r!==n&&this.hasImpressionEmitted(r,_,d,l)?(this.log("DEBUG",`Impression already emitted for slot ${n||r} in cycle ${_}`),!1):(n&&this.markImpressionEmitted(n,_,d,l),r&&r!==n&&this.markImpressionEmitted(r,_,d,l),this.enqueue(b.IMPRESSION,"impression",{auctionId:d,transactionId:a,adUnitCode:r,bid:p,metadata:{...t?.metadata,refresh_index:String(_)}}),f&&(!f.bidPayload&&p&&(f.bidPayload=p),!f.auctionId&&d&&(f.auctionId=d),!f.transactionId&&a&&(f.transactionId=a)),!0)}attachImaAdsManager(e,t){if(!e||typeof e.addEventListener!="function")return this.log("WARN","Invalid AdsManager passed to attachImaAdsManager"),()=>{};if(!e.__bidkernelAttachedInstances)try{Object.defineProperty(e,"__bidkernelAttachedInstances",{value:new Set,configurable:!0,writable:!0})}catch{e.__bidkernelAttachedInstances=new Set}if(e.__bidkernelAttachedInstances.has(this))return()=>{};e.__bidkernelAttachedInstances.add(this);let n=t?.slotId||t?.adUnitCode||"video",r=t?.adUnitCode||n,o=t?.auctionId||"",s=t?.transactionId||"",d=g=>{let c=(o?this.getCachedBid(`${o}:${r}`):void 0)||(o&&n!==r?this.getCachedBid(`${o}:${n}`):void 0)||(r!=="video"?this.getCachedBid(r):void 0)||(n!==r&&n!=="video"?this.getCachedBid(n):void 0);return c||(c=this.findCachedWinningBid({creativeId:g?.creativeId,adId:g?.adId,mediaType:"video"})),c},a=!1,l=g=>{a=!0,this.log("DEBUG","IMA AdEvent.STARTED / IMPRESSION received",g);let c=typeof g?.getAd=="function"?g.getAd():g?.ad,m={};c&&(m.creativeId=(typeof c.getCreativeId=="function"?c.getCreativeId():c.creativeId)||"",m.adId=(typeof c.getAdId=="function"?c.getAdId():c.id)||"",m.title=(typeof c.getTitle=="function"?c.getTitle():c.title)||"",m.duration=typeof c.getDuration=="function"?c.getDuration():c.duration,m.advertiserName=typeof c.getAdvertiserName=="function"?c.getAdvertiserName():"");let I=d(m),R=t?.slotId&&t.slotId!=="video"?t.slotId:t?.adUnitCode&&t.adUnitCode!=="video"?t.adUnitCode:I?.adUnitCode||t?.slotId||t?.adUnitCode||"video",D=t?.adUnitCode&&t.adUnitCode!=="video"?t.adUnitCode:I?.adUnitCode||R,P=o||I?.auctionId||"",Je=s||I?.transactionId||"",Ie={...I?.rawBid||t?.bid,mediaType:"video",creativeId:m.creativeId||I?.bidTrace?.creativeId||t?.bid?.creativeId||""};if(this.recordImpression(R,{adUnitCode:D,auctionId:P,transactionId:Je,mediaType:"video",bid:Ie,metadata:{...t?.metadata,media_type:"video",...m.title?{ad_title:m.title}:{},...Number.isFinite(m.duration)?{ad_duration_s:String(m.duration)}:{}}})&&t?.onImpression)try{t.onImpression(R,{ad:c,bid:Ie})}catch(et){this.log("ERROR","Error in onImpression callback",et)}},u=g=>{if(this.log("DEBUG",`IMA AdEvent milestone: ${g}`),t?.onMilestone)try{t.onMilestone(g,n)}catch(c){this.log("ERROR","Error in onMilestone callback",c)}},y=g=>{this.log("DEBUG","IMA AdEvent.CLICK received",g);let c=d(),m=t?.adUnitCode&&t.adUnitCode!=="video"?t.adUnitCode:c?.adUnitCode||n;this.enqueue(b.CLICK,"click",{auctionId:o||c?.auctionId,transactionId:s||c?.transactionId,adUnitCode:m,bid:c?.bidTrace||t?.bid,metadata:{...t?.metadata,media_type:"video"}})},f=g=>{this.log("WARN","IMA AdErrorEvent received",g);let c=typeof g?.getError=="function"?g.getError():g?.error||g,m=(c&&typeof c.getMessage=="function"?c.getMessage():c?.message)||String(c||"IMA ad error"),I=(c&&typeof c.getErrorCode=="function"?c.getErrorCode():c?.code)||"",R=d(),D=t?.adUnitCode&&t.adUnitCode!=="video"?t.adUnitCode:R?.adUnitCode||n;if(this.enqueue(b.AD_RENDER_FAILED,"adRenderFailed",{auctionId:o||R?.auctionId,transactionId:s||R?.transactionId,adUnitCode:D,bid:R?.bidTrace||t?.bid,metadata:{...t?.metadata,reason:a?"ima_playback_error":"ima_ad_error",playback_phase:a?"post_start":"pre_start",message:m,...I?{ima_error_code:String(I)}:{}},error:typeof c=="object"?c:new Error(m)}),t?.onError)try{t.onError(c)}catch(P){this.log("ERROR","Error in onError callback",P)}},v=typeof window<"u"?window.google?.ima:void 0,T=v?.AdEvent?.Type||{},p=v?.AdErrorEvent?.Type||{},_=[{type:T.STARTED||"started",handler:l},{type:T.IMPRESSION||"impression",handler:l},{type:T.FIRST_QUARTILE||"firstQuartile",handler:()=>u("firstQuartile")},{type:T.MIDPOINT||"midpoint",handler:()=>u("midpoint")},{type:T.THIRD_QUARTILE||"thirdQuartile",handler:()=>u("thirdQuartile")},{type:T.COMPLETE||"complete",handler:()=>u("complete")},{type:T.CLICK||"click",handler:y},{type:p.AD_ERROR||"adError",handler:f}],U=new Set,w=[];for(let g of _)U.has(g.type)||(U.add(g.type),w.push(g));for(let{type:g,handler:c}of w)try{e.addEventListener(g,c)}catch{}let E=()=>{e.__bidkernelAttachedInstances?.delete(this);for(let{type:g,handler:c}of w)try{e.removeEventListener(g,c)}catch{}this.videoDetachCleanups.delete(E)};return this.videoDetachCleanups.add(E),E}attachVideoPlayer(e,t){if(!e)return this.log("WARN","attachVideoPlayer called with null/undefined target"),()=>{};let n=null;if(typeof e=="string"){if(typeof document<"u")try{n=document.querySelector(e)||document.getElementById(e)}catch{n=document.getElementById(e)}}else if(typeof HTMLElement<"u"&&e instanceof HTMLElement)n=e;else if(e&&typeof e=="object"&&e.nodeType===1)n=e;else{if(typeof e.addEventListener=="function"&&(typeof e.init=="function"||typeof e.start=="function"||typeof e.getCuePoints=="function"||typeof e.getVolume=="function"||e.__imaAdsManager))return this.attachImaAdsManager(e,t);e&&typeof e.addEventListener=="function"&&(n=e)}let r=t?.slotId||t?.adUnitCode||(n?n.id:"")||"video",o=t?.adUnitCode||r,s=t?.auctionId||"",d=t?.transactionId||"",a=()=>(s?this.getCachedBid(`${s}:${o}`):void 0)||(s&&r!==o?this.getCachedBid(`${s}:${r}`):void 0)||this.getCachedBid(o)||(r!==o?this.getCachedBid(r):void 0),l=null;n&&(n.tagName&&n.tagName.toLowerCase()==="video"?l=n:l=n.querySelector("video"));let u={q1:!1,q2:!1,q3:!1,q4:!1},y=c=>{let m=c||l||(n?.querySelector?n.querySelector("video"):null),I=a(),R={...I?.rawBid||t?.bid,mediaType:"video"};if(this.recordImpression(r,{adUnitCode:o,auctionId:s||I?.auctionId,transactionId:d||I?.transactionId,mediaType:"video",bid:R,metadata:{...t?.metadata,media_type:"video",...m&&Number.isFinite(m.duration)?{video_duration_s:String(Math.round(m.duration))}:{}}})&&t?.onImpression)try{t.onImpression(r,{element:m||n,bid:R})}catch(P){this.log("ERROR","Error in onImpression callback",P)}},f=c=>{this.log("DEBUG","HTML5 video playing event received");let m=c?.target instanceof HTMLVideoElement?c.target:l;y(m)},v=c=>{let m=c?.target instanceof HTMLVideoElement?c.target:l;if(m&&m.currentTime>0&&(y(m),Number.isFinite(m.duration)&&m.duration>0)){let I=m.currentTime/m.duration;I>=.25&&!u.q1&&(u.q1=!0,t?.onMilestone?.("firstQuartile",r)),I>=.5&&!u.q2&&(u.q2=!0,t?.onMilestone?.("midpoint",r)),I>=.75&&!u.q3&&(u.q3=!0,t?.onMilestone?.("thirdQuartile",r))}},T=()=>{u.q4||(u.q4=!0,t?.onMilestone?.("complete",r))},p=c=>{let I=(c?.target instanceof HTMLVideoElement?c.target:l)?.error||l?.error,R=a(),D=I?`HTML5 video error code ${I.code}: ${I.message}`:"Video playback error";if(this.log("WARN",D),this.enqueue(b.AD_RENDER_FAILED,"adRenderFailed",{auctionId:s||R?.auctionId,transactionId:d||R?.transactionId,adUnitCode:o,bid:R?.bidTrace||t?.bid,metadata:{...t?.metadata,reason:"html5_video_error",message:D,...I?.code?{video_error_code:String(I.code)}:{}},error:I?new Error(D):void 0}),t?.onError)try{t.onError(I)}catch(P){this.log("ERROR","Error in onError callback",P)}},_=c=>{c.addEventListener("playing",f),c.addEventListener("play",f),c.addEventListener("timeupdate",v),c.addEventListener("ended",T),c.addEventListener("error",p)},U=c=>{c.removeEventListener("playing",f),c.removeEventListener("play",f),c.removeEventListener("timeupdate",v),c.removeEventListener("ended",T),c.removeEventListener("error",p)},w=null;n&&n!==l&&(n.addEventListener("playing",f,!0),n.addEventListener("play",f,!0),n.addEventListener("timeupdate",v,!0),n.addEventListener("ended",T,!0),n.addEventListener("error",p,!0)),l&&_(l),n&&n.tagName?.toLowerCase()!=="video"&&typeof MutationObserver<"u"&&(w=new MutationObserver(()=>{let c=n.querySelector("video");c&&c!==l&&(l&&U(l),l=c,l&&_(l))}),w.observe(n,{childList:!0,subtree:!0}));let E=a();t?.trackViewability!==!1&&n&&this.observeSlot(n,r,{adUnitCode:o,auctionId:s||E?.auctionId,transactionId:d||E?.transactionId,mediaType:"video",bid:E?.bidTrace||t?.bid,metadata:t?.metadata,emitRefreshEvent:!1});let g=()=>{w&&(w.disconnect(),w=null),n&&n!==l&&(n.removeEventListener("playing",f,!0),n.removeEventListener("play",f,!0),n.removeEventListener("timeupdate",v,!0),n.removeEventListener("ended",T,!0),n.removeEventListener("error",p,!0)),l&&U(l),this.videoDetachCleanups.delete(g)};return this.videoDetachCleanups.add(g),g}onTimeInViewThreshold(e,t,n){let r={thresholdMs:t,callback:n,timer:null,fired:!1},o=this.slotViewabilityRecords.get(e);if(o){o.thresholdListeners.add(r);let s=this.getCurrentTimeInView(o);if(s>=t){r.fired=!0;try{n(e,s)}catch(d){this.log("ERROR","Error in threshold callback",d)}}else if(o.inView&&(typeof document>"u"||document.visibilityState==="visible")){let d=t-s;r.timer=setTimeout(()=>{if(r.timer=null,!r.fired&&o.inView&&(typeof document>"u"||document.visibilityState==="visible")){let a=this.getCurrentTimeInView(o);if(a>=t){r.fired=!0;try{n(e,a)}catch(l){this.log("ERROR","Error in threshold callback",l)}}}},d)}}else this.pendingThresholdListeners.has(e)||this.pendingThresholdListeners.set(e,new Set),this.pendingThresholdListeners.get(e).add(r);return()=>{r.timer&&(clearTimeout(r.timer),r.timer=null),o&&o.thresholdListeners.delete(r);let s=this.pendingThresholdListeners.get(e);s&&s.delete(r)}}getViewabilityState(e){let t=this.slotViewabilityRecords.get(e);if(!t)return;let n=Math.round(this.getCurrentTimeInView(t));return{inView:t.inView,viewable:t.viewableFired,timeInViewMs:n,refreshIndex:t.refreshIndex}}getEndpoint(){return this.config.endpoint}getRefreshIndex(e){return this.slotRefreshIndices.get(e)??0}triggerSlotRefresh(e,t){let n=this.slotViewabilityRecords.get(e);n&&n.element&&this.observeSlot(n.element,e,t)}trackRawEvent(e,t,n){let r=wt[t]??(e==="ERROR"?b.ERROR:b.TRACE_EVENT_TYPE_UNSPECIFIED);this.enqueue(r,t,n,e)}setUserId(e){this.config.userId=e}setSessionId(e){this.config.sessionId=e}navigate(e,t){if(this.disable(),this.slotRefreshIndices.clear(),this.pendingThresholdListeners.clear(),this.config.pageviewId=e||F(),t)try{let n=new URL(t);this.pageUrl=n.origin+n.pathname}catch{this.pageUrl=t}else this.pageUrl="";this.logger.resetTiming(),je(),this.enable()}handleAuctionInit(e){if(this.isDuplicate("auctionInit",e))return;this.log("DEBUG","auctionInit",e);let t=e.auctionId||"";t&&(this.auctionBidderOutcomes.delete(t),this.getOrCreateAuctionOutcomes(t)),this.enqueue(b.AUCTION_START,"auctionStart",{auctionId:t,transactionId:e.transactionId||""})}handleAuctionEnd(e){if(this.isDuplicate("auctionEnd",e))return;this.log("DEBUG","auctionEnd",e);let t=e.auctionId||"",n=t?this.auctionBidderOutcomes.get(t):void 0,r=n?Array.from(n.values()):[];t&&this.auctionBidderOutcomes.delete(t),this.enqueue(b.AUCTION_END,"auctionEnd",{auctionId:t,transactionId:e.transactionId||"",bidderOutcomes:r})}handleBidRequested(e){if(this.isDuplicate("bidRequested",e))return;this.log("DEBUG","bidRequested",e);let t=e.auctionId||"",n=e.bidderCode||e.bidder||"";if(!t||!n)return;let r=this.getOrCreateAuctionOutcomes(t);Array.isArray(e.bids)&&e.bids.forEach(o=>{let s=o.adUnitCode||"",d=Object.keys(o.mediaTypes||{}),a=d.length>0?d[0]:o.mediaType||"banner",l=`${n}:${s}`;r.has(l)||r.set(l,{bidder:n,adUnitCode:s,mediaType:a,outcome:S.BIDDER_OUTCOME_NO_RESPONSE,latencyMs:0})})}handleBidResponse(e){if(this.isDuplicate("bidResponse",e))return;this.log("DEBUG","bidResponse",e);let t=e.auctionId||"",n=e.bidderCode||e.bidder||"",r=e.adUnitCode||"",o=Number.isFinite(e.originalCpm)?e.originalCpm:Number.isFinite(e.cpm)?e.cpm:0,s=Number.isFinite(e.timeToRespond)?e.timeToRespond:0,d=Object.keys(e.mediaTypes||{}),a=e.mediaType||(e.mediaTypes?.video?"video":d.length>0?d[0]:"banner");if(t&&n){let l=this.getOrCreateAuctionOutcomes(t),u=`${n}:${r}`,y=l.get(u),f=o>0?S.BIDDER_OUTCOME_BID:S.BIDDER_OUTCOME_NO_BID;y?(y.outcome=f,y.latencyMs=s,a&&(y.mediaType=a)):l.set(u,{bidder:n,adUnitCode:r,mediaType:a,outcome:f,latencyMs:s})}o>0&&this.enqueue(b.BID_RESPONSE,"bidResponse",{auctionId:t,transactionId:e.transactionId||"",adUnitCode:r,bid:{bidder:n,cpm:o,currency:e.originalCurrency??e.currency??"USD",...k(e),dealId:e.dealId||"",mediaType:a,latencyMs:s,advertiserDomain:e.meta?.advertiserDomains?.[0]||"",creativeId:e.creativeId||""}})}handleBidTimeout(e){if(this.isDuplicate("bidTimeout",e))return;this.log("DEBUG","bidTimeout",e);let t=Array.isArray(e)?e:e?[e]:[];for(let n of t){let r=n.auctionId||"",o=n.bidderCode||n.bidder||"",s=n.adUnitCode||"",d=Number.isFinite(n.timeout)?n.timeout:0;if(r&&o){let a=this.getOrCreateAuctionOutcomes(r),l=`${o}:${s}`,u=a.get(l);u?(u.outcome=S.BIDDER_OUTCOME_TIMEOUT,d>0&&(u.latencyMs=d)):a.set(l,{bidder:o,adUnitCode:s,mediaType:"banner",outcome:S.BIDDER_OUTCOME_TIMEOUT,latencyMs:d})}}}handleBidWon(e){if(this.isDuplicate("bidWon",e))return;this.log("DEBUG","bidWon",e);let t=e.auctionId||"",n=e.transactionId||"",r=e.adUnitCode||e.adId||"",o=Object.keys(e.mediaTypes||{}),s=e.mediaType||(e.mediaTypes?.video?"video":o.length>0?o[0]:"banner"),d={bidder:e.bidderCode||e.bidder||"",cpm:Number.isFinite(e.originalCpm)?e.originalCpm:Number.isFinite(e.cpm)?e.cpm:0,currency:e.originalCurrency??e.currency??"USD",...k(e),dealId:e.dealId||"",mediaType:s,latencyMs:Number.isFinite(e.timeToRespond)?e.timeToRespond:0,advertiserDomain:e.meta?.advertiserDomains?.[0]||"",creativeId:e.creativeId||""};if(r){let a={bidTrace:d,auctionId:t,transactionId:n,adUnitCode:r,rawBid:e,timestamp:Date.now()};this.cachedWinningBids.set(r,a),e.adId&&e.adId!==r&&this.cachedWinningBids.set(e.adId,a),t&&(this.cachedWinningBids.set(`${t}:${r}`,a),e.adId&&e.adId!==r&&this.cachedWinningBids.set(`${t}:${e.adId}`,a)),this.pruneCachedWinningBids()}this.enqueue(b.BID_WIN,"bidWon",{auctionId:t,transactionId:n,adUnitCode:r,bid:d})}handleNoBid(e){if(this.isDuplicate("noBid",e))return;this.log("DEBUG","noBid",e);let t=e.auctionId||"",n=e.bidderCode||e.bidder||"",r=e.adUnitCode||"";if(t&&n){let o=this.getOrCreateAuctionOutcomes(t),s=`${n}:${r}`,d=o.get(s);d?d.outcome===S.BIDDER_OUTCOME_NO_RESPONSE&&(d.outcome=S.BIDDER_OUTCOME_NO_BID):o.set(s,{bidder:n,adUnitCode:r,mediaType:"banner",outcome:S.BIDDER_OUTCOME_NO_BID,latencyMs:0})}}handleAdRenderFailed(e){if(this.isDuplicate("adRenderFailed",e))return;this.log("DEBUG","adRenderFailed",e);let t=e.bid||{};this.enqueue(b.AD_RENDER_FAILED,"adRenderFailed",{auctionId:t.auctionId||e.auctionId||"",transactionId:t.transactionId||e.transactionId||"",adUnitCode:t.adUnitCode||e.adUnitCode||"",bid:{bidder:t.bidderCode||t.bidder||e.bidderCode||e.bidder||""},metadata:{reason:String(e.reason||""),message:String(e.message||e.error?.message||"")},error:e.error||(e.message?new Error(String(e.message)):void 0)})}handleAdRenderSucceeded(e){if(this.isDuplicate("adRenderSucceeded",e))return;this.log("DEBUG","adRenderSucceeded",e);let t=e.bid||e||{},n=e.adUnitCode||t.adUnitCode||e.adId||t.adId||"",r=t.auctionId||e.auctionId||"",o=t.transactionId||e.transactionId||"",s=t.mediaType||"banner",d=e.adUnitCode||t.adUnitCode||"",a=e.adId||t.adId||"",l=(r&&d?this.getCachedBid(`${r}:${d}`):void 0)||(r&&a?this.getCachedBid(`${r}:${a}`):void 0)||(d?this.getCachedBid(d):void 0)||(a?this.getCachedBid(a):void 0),u=s==="video"||t.mediaType==="video"||t.mediaTypes?.video!==void 0||l?.bidTrace?.mediaType==="video"||l?.rawBid?.mediaType==="video"||n&&this.slotViewabilityRecords.get(n)?.mediaType==="video",y=u?"video":s||l?.bidTrace?.mediaType||"banner",f={bidder:t.bidderCode||t.bidder||l?.bidTrace?.bidder||"",cpm:Number.isFinite(t.originalCpm)?t.originalCpm:Number.isFinite(t.cpm)?t.cpm:l?.bidTrace?.cpm??0,currency:t.originalCurrency??t.currency??l?.bidTrace?.currency??"USD",...k(t).width?k(t):l?.bidTrace?{width:l.bidTrace.width,height:l.bidTrace.height}:k(t),dealId:t.dealId||l?.bidTrace?.dealId||"",mediaType:y,latencyMs:Number.isFinite(t.timeToRespond)?t.timeToRespond:l?.bidTrace?.latencyMs??0,advertiserDomain:t.meta?.advertiserDomains?.[0]||l?.bidTrace?.advertiserDomain||"",creativeId:t.creativeId||l?.bidTrace?.creativeId||""},v=r||l?.auctionId||"",T=o||l?.transactionId||"",p=n?this.slotViewabilityRecords.get(n):void 0,_=p&&v&&p.auctionId&&p.auctionId!==v;if(!!(n&&p&&_)){this.flushSlotTimeInView(n);let E=(this.slotRefreshIndices.get(n)??(p?p.refreshIndex:0))+1;this.slotRefreshIndices.set(n,E),this.slotLastAuctionIds.set(n,v),p&&(p.refreshIndex=E,p.auctionId=v,p.transactionId=T,p.bidPayload=f,p.viewableFired=!1,p.accumulatedTimeInViewMs=0),this.enqueue(b.REFRESH,"refresh",{auctionId:v,transactionId:T,adUnitCode:n,bid:f,metadata:{refresh_index:String(E)}})}else n&&(v&&this.slotLastAuctionIds.set(n,v),this.slotRefreshIndices.has(n)||this.slotRefreshIndices.set(n,0));let w=n?this.slotRefreshIndices.get(n)??(p?p.refreshIndex:0):0;if(u?this.log("DEBUG",`adRenderSucceeded received for video ad unit ${n||"unknown"}: suppressing IMPRESSION until verified video lifecycle event`):n&&this.hasImpressionEmitted(n,w,v,f.creativeId)||(n&&this.markImpressionEmitted(n,w,v,f.creativeId),this.enqueue(b.IMPRESSION,"impression",{auctionId:v,transactionId:T,adUnitCode:n,bid:f,metadata:{refresh_index:String(w)}})),this.config.viewabilityEnabled&&typeof document<"u"){let E=null,g=n||e.adId||t.adId;if(g&&(E=document.getElementById(g)),!E&&typeof window<"u"&&window.googletag?.pubads)try{let c=window.googletag.pubads().getSlots();for(let m of c)if((m.getAdUnitPath?.()===n||m.getSlotElementId?.()===n)&&(E=document.getElementById(m.getSlotElementId()),E))break}catch{}if(!E&&g)try{for(let c of Array.from(document.querySelectorAll("[data-ad-slot]")))if(c.getAttribute("data-ad-slot")===g){E=c;break}}catch{}E&&this.observeSlot(E,n||g,{adUnitCode:n,auctionId:v,transactionId:T,mediaType:y,bid:f,refreshIndex:w,emitRefreshEvent:!1})}}isDuplicate(e,t){return this.deduper.isDuplicate(e,t)}enqueue(e,t,n,r){if(!this.isEnabled||!this.shouldSample(e,r))return;je();let o={eventId:F(),timestampMs:Date.now(),type:e,eventName:t,auctionId:n.auctionId||"",transactionId:n.transactionId||"",adUnitCode:n.adUnitCode||n.elementId||"",namespace:n.ns||n.namespace||""};n.bid&&(o.bid={bidder:n.bid.bidder||"",cpm:Number.isFinite(n.bid.cpm)?n.bid.cpm:0,currency:n.bid.currency||"",width:Number.isFinite(n.bid.width)?n.bid.width:0,height:Number.isFinite(n.bid.height)?n.bid.height:0,dealId:n.bid.dealId||"",mediaType:n.bid.mediaType||"",latencyMs:Number.isFinite(n.bid.latencyMs)?n.bid.latencyMs:0,advertiserDomain:n.bid.advertiserDomain||"",creativeId:n.bid.creativeId||""}),n.viewableDurationMs!==void 0&&(o.viewableDurationMs=Number.isFinite(n.viewableDurationMs)?n.viewableDurationMs:0),n.bidderOutcomes&&Array.isArray(n.bidderOutcomes)&&(o.bidderOutcomes=n.bidderOutcomes);let s={...n.metadata};n.error!==void 0&&n.error!==null&&(s.error=typeof n.error=="object"&&n.error.message?String(n.error.message):String(n.error)),n.gpid&&(s.gpid=String(n.gpid)),n.refreshIndex!==void 0&&s.refresh_index===void 0&&(s.refresh_index=String(n.refreshIndex));let d=Dt(s);Object.keys(d).length>0&&(o.metadata=d),this.queue.push(o),this.queue.length>Q&&this.queue.splice(0,this.queue.length-Q),this.queue.length>=yt?this.flush():At.has(e)&&!this.immediateFlushScheduled&&(this.immediateFlushScheduled=!0,setTimeout(()=>{this.immediateFlushScheduled=!1,this.flush()},0))}shouldSample(e,t){return e===b.ERROR?(this.errorCount++,this.errorCount>gt?!1:this.config.errorsEnabled):t==="WARN"?this.config.warningsEnabled:this.config.auctionEnabled}requeue(e){e.length&&(this.queue=e.concat(this.queue),this.queue.length>Q&&this.queue.splice(0,this.queue.length-Q))}drainBatch(){if(this.queue.length===0||!this.config.endpoint)return null;let e=typeof window<"u"?window.location.hostname:"",t=n=>({propertyId:this.config.propertyId,pageviewId:this.config.pageviewId,sessionId:this.config.sessionId,pageUrl:this.pageUrl,country:this.config.country,region:this.config.region,deviceType:this.config.deviceType,userId:this.config.userId,domain:e,events:n});for(;;){if(this.queue.length===0)return null;let n=this.queue,r=Y.encode(t(n)).finish();for(;n.length>1&&r.byteLength>he;)n=n.slice(0,Math.floor(n.length/2)),r=Y.encode(t(n)).finish();if(r.byteLength>he){let[o]=this.queue.splice(0,1);this.log("WARN",`Dropping oversized event ${o?.eventName||o?.eventId} (${r.byteLength} bytes exceeds the ${he}-byte cap on its own)`);continue}return this.queue=this.queue.slice(n.length),{url:`${this.config.endpoint}/${this.config.propertyId}`,encoded:r,events:n}}}sendFetch(e,t=!1,n,r=!1){let o={method:"POST",headers:{"Content-Type":Ke},body:e.encoded};t&&(o.keepalive=!0),fetch(e.url,o).then(d=>{if(d.ok)r||(this.consecutiveSendFailures=0,this.nextSendAllowedAt=0),n&&n();else{if(this.log("WARN",`Failed to send batch: HTTP ${d.status}`),d.status>=400&&d.status<500&&d.status!==429&&d.status!==408){this.log("WARN",`Dropping batch due to non-retryable client error HTTP ${d.status}`);return}r||this.handleSendFailure(e.events)}}).catch(d=>{this.log("ERROR","Failed to send batch",d),r||this.handleSendFailure(e.events)});let s=typeof globalThis<"u"?globalThis.process:void 0;if(s&&typeof s._tickCallback=="function")try{s._tickCallback()}catch{}}handleSendFailure(e){this.consecutiveSendFailures++;let t=Math.min(We*2**(this.consecutiveSendFailures-1),mt);this.nextSendAllowedAt=Date.now()+t,this.consecutiveSendFailures<=bt?this.requeue(e):this.log("WARN",`Dropping ${e.length} events after ${this.consecutiveSendFailures} consecutive send failures`)}flush(){if(Date.now()<this.nextSendAllowedAt)return;let e=this.drainBatch();for(;e&&(this.sendFetch(e,!1),!(Date.now()<this.nextSendAllowedAt));)e=this.drainBatch()}flushBeacon(){let e=this.drainBatch();for(;e;){let t=!1;if(typeof navigator<"u"&&typeof navigator.sendBeacon=="function")try{let n=new Blob([e.encoded],{type:Ke});t=navigator.sendBeacon(e.url,n)}catch{t=!1}if(!t){let n=this.persistBatch(e.encoded);this.sendFetch(e,!0,()=>this.removePersistedBatch(n))}e=this.drainBatch()}this.schedulePersistedCleanup()}pendingKeyPrefix(){return`${J}${encodeURIComponent(this.config.propertyId)}_`}persistBatch(e){try{if(typeof localStorage>"u"||!this.config.propertyId)return null;let t=0;for(let r=0;r<localStorage.length;r++){let o=localStorage.key(r);o&&o.startsWith(J)&&t++}if(t>=vt)return null;let n=`${this.pendingKeyPrefix()}${Date.now()}_${Math.floor(Math.random()*1e6)}`;return localStorage.setItem(n,xt(e)),this.persistedBatchKeys.push(n),n}catch{return null}}removePersistedBatch(e){if(!e)return;try{typeof localStorage<"u"&&localStorage.removeItem(e)}catch{}let t=this.persistedBatchKeys.indexOf(e);t!==-1&&this.persistedBatchKeys.splice(t,1)}schedulePersistedCleanup(){this.persistedBatchKeys.length!==0&&(this.persistedCleanupTimer&&clearTimeout(this.persistedCleanupTimer),this.persistedCleanupTimer=setTimeout(()=>{this.persistedCleanupTimer=null;for(let e of Array.from(this.persistedBatchKeys))this.removePersistedBatch(e)},Et))}resendPersistedBatches(){try{if(typeof localStorage>"u"||!this.config.endpoint||!this.config.propertyId)return;let e=this.pendingKeyPrefix(),t=[],n=[];for(let r=0;r<localStorage.length;r++){let o=localStorage.key(r);!o||!o.startsWith(J)||(o.startsWith(e)?t.push(o):Ot(o)&&n.push(o))}for(let r of n)try{localStorage.removeItem(r)}catch{}for(let r of t){let o=null;try{o=localStorage.getItem(r),localStorage.removeItem(r)}catch{continue}if(!o)continue;let s=parseInt(r.slice(e.length),10);if(!Number.isFinite(s)||Date.now()-s>Tt)continue;let d;try{d=Ct(o)}catch{continue}d.byteLength!==0&&(this.log("DEBUG",`Resending persisted exit batch (${d.byteLength} bytes)`),this.sendFetch({url:`${this.config.endpoint}/${this.config.propertyId}`,encoded:d,events:[]},!1,void 0,!0))}}catch{}}log(e,t,...n){this.logger.log(e,t,...n)}},ye=ie({prefix:"[bidkernel]",logLevel:"INFO"})});var Nt=tt(()=>{Qe();var Ze="https://by.bidkernel.io/t",Pt=window._bidkernelPbjsGlobal||"pbjs";be(Pt,{endpoint:Ze});window.bidkernelPrebidAnalytics={...window.bidkernelPrebidAnalytics,register:(i,e)=>be(i,{endpoint:Ze,...e}),attachVideoPlayer:(i,e)=>{let t=window._bidkernelPrebidAnalytics;return t?.attachVideoPlayer?t.attachVideoPlayer(i,e):()=>{}},attachImaAdsManager:(i,e)=>{let t=window._bidkernelPrebidAnalytics;return t?.attachImaAdsManager?t.attachImaAdsManager(i,e):()=>{}},recordImpression:(i,e)=>{let t=window._bidkernelPrebidAnalytics;return t?.recordImpression?t.recordImpression(i,e):!1}}});return Nt();})();
|
|
1
|
+
"use strict";var bidkernelPrebidAnalyticsBundle=(()=>{var L=(i,e)=>()=>(i&&(e=i(i=0)),e);var rt=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports);function dt(){if(typeof window<"u"){let i=window;return i.__bidkernelLogListeners||(i.__bidkernelLogListeners=new Set),i.__bidkernelLogListeners}return ot}function at(i){if((i<0||!Number.isFinite(i))&&(i=0),i<1e3)return`${i.toFixed(2)}ms`;let e=i/1e3;if(e<60)return`${e.toFixed(2)}s`;let t=Math.floor(e/60);return t<60?`${t}m ${(e%60).toFixed(2)}s`:`${Math.floor(t/60)}h ${t%60}m ${(e%60).toFixed(2)}s`}function H(i){if(typeof i=="string"){let e=i.toUpperCase();if(e==="DEBUG"||e==="INFO"||e==="WARN"||e==="ERROR")return e}return A.INFO}function se(i){return new re(i)}var A,Ae,k,st,ot,re,Re=L(()=>{"use strict";A={DEBUG:"DEBUG",INFO:"INFO",WARN:"WARN",ERROR:"ERROR"},Ae={[A.DEBUG]:10,[A.INFO]:20,[A.WARN]:30,[A.ERROR]:40},k={badge:"color: #2dd4bf; font-weight: bold",badgeWarn:"background: #f59e0b; color: #fff; padding: 2px 4px; border-radius: 3px; font-weight: bold",badgeError:"background: #ef4444; color: #fff; padding: 2px 4px; border-radius: 3px; font-weight: bold",dim:"color: #6b7280",event:"color: #38bdf8; font-weight: bold",eventWarn:"color: #f59e0b; font-weight: bold",eventError:"color: #ef4444; font-weight: bold",reset:"color: inherit"},st=0,ot=new Set;re=class i{_prefix;_level;_loadedAt;_now;_console;_customFormatTime;_listeners=new Set;constructor(e={}){this._prefix=e.prefix??"[bidkernel]",this._level=H(e.logLevel??A.INFO),this._now=e.now,this._console=e.console,this._customFormatTime=e.formatTime,e.onLog&&this._listeners.add(e.onLog),this._loadedAt=e.loadedAt??(this._now?this._now():typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now())}get prefix(){return this._prefix}set prefix(e){this._prefix=e}get logLevel(){return this._level}set logLevel(e){this._level=H(e)}getLevel(){return this._level}setLevel(e){this._level=H(e)}getPrefix(){return this._prefix}setPrefix(e){this._prefix=e}resetTiming(e){this._loadedAt=e??(this._now?this._now():typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now())}getLoadedAt(){return this._loadedAt}addListener(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}removeListener(e){this._listeners.delete(e)}isEnabled(e){let t=H(e);return(Ae[t]??20)>=(Ae[this._level]??20)}formatTime(e){return this._customFormatTime?this._customFormatTime(e):at(e)}_getConsole(){if(this._console)return this._console;if(typeof console<"u")return console}_getElapsed(){let e=this._now?this._now():typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now();return Math.max(0,e-this._loadedAt)}_dispatchRecord(e){for(let n of this._listeners)try{n(e)}catch{}let t=dt();for(let n of t)if(!this._listeners.has(n))try{n(e)}catch{}if(typeof window<"u"&&typeof window.dispatchEvent=="function")try{window.dispatchEvent(new CustomEvent("__bidkernel_log__",{detail:e}))}catch{}}log(e,t,...n){let r=H(e);if(!this.isEnabled(r))return;let s=this._getElapsed(),o=this.formatTime(s),d=Date.now(),c={id:`bk_log_${d}_${++st}`,timestamp:d,elapsedMs:s,level:r,prefix:this._prefix,message:t,args:n,data:n.length===1?n[0]:n.length>1?n:void 0};this._dispatchRecord(c);let u=this._getConsole();if(!u)return;let g=k.badge,f=k.event;r===A.WARN?(g=k.badgeWarn,f=k.eventWarn):r===A.ERROR&&(g=k.badgeError,f=k.eventError);let I=`%c${this._prefix}%c ${o} %c${t}%c`,R=[g,k.dim,f,k.reset],y=[I,...R];switch(n.length>0&&y.push(...n),r){case A.DEBUG:typeof u.log=="function"?u.log(...y):typeof u.debug=="function"&&u.debug(...y);break;case A.INFO:typeof u.info=="function"?u.info(...y):typeof u.log=="function"&&u.log(...y);break;case A.WARN:typeof u.warn=="function"?u.warn(...y):typeof u.log=="function"&&u.log(...y);break;case A.ERROR:typeof u.error=="function"?u.error(...y):typeof u.log=="function"&&u.log(...y);break;default:typeof u.log=="function"&&u.log(...y);break}}debug(e,...t){this.log(A.DEBUG,e,...t)}info(e,...t){this.log(A.INFO,e,...t)}warn(e,...t){this.log(A.WARN,e,...t)}error(e,...t){this.log(A.ERROR,e,...t)}logEvent(e){e&&(e.data!==void 0?this.log(e.level,e.eventName,e.data):this.log(e.level,e.eventName))}child(e,t={}){let n=this._prefix;if(e){let r=e.startsWith("[")&&e.endsWith("]")?e:`[${e}]`;n=`${this._prefix}${r}`}return new i({prefix:n,logLevel:t.logLevel??this._level,loadedAt:t.loadedAt??this._loadedAt,now:t.now??this._now,console:t.console??this._console,formatTime:t.formatTime??this._customFormatTime,...t})}withPrefix(e){return new i({prefix:e,logLevel:this._level,loadedAt:this._loadedAt,now:this._now,console:this._console,formatTime:this._customFormatTime})}}});function Be(){let i=0,e=0;for(let n=0;n<28;n+=7){let r=this.buf[this.pos++];if(i|=(r&127)<<n,(r&128)==0)return this.assertBounds(),[i,e]}let t=this.buf[this.pos++];if(i|=(t&15)<<28,e=(t&112)>>4,(t&128)==0)return this.assertBounds(),[i,e];for(let n=3;n<=31;n+=7){let r=this.buf[this.pos++];if(e|=(r&127)<<n,(r&128)==0)return this.assertBounds(),[i,e]}throw new Error("invalid varint")}function z(i,e,t){for(let s=0;s<28;s=s+7){let o=i>>>s,d=!(!(o>>>7)&&e==0),a=(d?o|128:o)&255;if(t.push(a),!d)return}let n=i>>>28&15|(e&7)<<4,r=e>>3!=0;if(t.push((r?n|128:n)&255),!!r){for(let s=3;s<31;s=s+7){let o=e>>>s,d=!!(o>>>7),a=(d?o|128:o)&255;if(t.push(a),!d)return}t.push(e>>>31&1)}}function oe(i){let e=i[0]==="-";e&&(i=i.slice(1));let t=1e6,n=0,r=0;function s(o,d){let a=Number(i.slice(o,d));r*=t,n=n*t+a,n>=j&&(r=r+(n/j|0),n=n%j)}return s(-24,-18),s(-18,-12),s(-12,-6),s(-6),e?Ce(n,r):ae(n,r)}function xe(i,e){let t=ae(i,e),n=t.hi&2147483648;n&&(t=Ce(t.lo,t.hi));let r=de(t.lo,t.hi);return n?"-"+r:r}function de(i,e){if({lo:i,hi:e}=ct(i,e),e<=2097151)return String(j*e+i);let t=i&16777215,n=(i>>>24|e<<8)&16777215,r=e>>16&65535,s=t+n*6777216+r*6710656,o=n+r*8147497,d=r*2,a=1e7;return s>=a&&(o+=Math.floor(s/a),s%=a),o>=a&&(d+=Math.floor(o/a),o%=a),d.toString()+_e(o)+_e(s)}function ct(i,e){return{lo:i>>>0,hi:e>>>0}}function ae(i,e){return{lo:i|0,hi:e|0}}function Ce(i,e){return e=~e,i?i=~i+1:e+=1,ae(i,e)}function ce(i,e){if(i>=0){for(;i>127;)e.push(i&127|128),i=i>>>7;e.push(i)}else{for(let t=0;t<9;t++)e.push(i&127|128),i=i>>7;e.push(1)}}function Le(){let i=this.buf[this.pos++],e=i&127;if((i&128)==0)return this.assertBounds(),e;if(i=this.buf[this.pos++],e|=(i&127)<<7,(i&128)==0)return this.assertBounds(),e;if(i=this.buf[this.pos++],e|=(i&127)<<14,(i&128)==0)return this.assertBounds(),e;if(i=this.buf[this.pos++],e|=(i&127)<<21,(i&128)==0)return this.assertBounds(),e;i=this.buf[this.pos++],e|=(i&15)<<28;for(let t=5;(i&128)!==0&&t<10;t++)i=this.buf[this.pos++];if((i&128)!=0)throw new Error("invalid varint");return this.assertBounds(),e>>>0}var j,_e,le=L(()=>{"use strict";j=4294967296;_e=i=>{let e=String(i);return"0000000".slice(e.length)+e}});function lt(){let i=new DataView(new ArrayBuffer(8));if(typeof BigInt=="function"&&typeof i.getBigInt64=="function"&&typeof i.getBigUint64=="function"&&typeof i.setBigInt64=="function"&&typeof i.setBigUint64=="function"&&(!!globalThis.Deno||typeof process!="object"||typeof process.env!="object"||process.env.BUF_BIGINT_DISABLE!=="1")){let t=BigInt("-9223372036854775808"),n=BigInt("9223372036854775807"),r=BigInt("0"),s=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(o){let d=typeof o=="bigint"?o:BigInt(o);if(d>n||d<t)throw new Error(`invalid int64: ${o}`);return d},uParse(o){let d=typeof o=="bigint"?o:BigInt(o);if(d>s||d<r)throw new Error(`invalid uint64: ${o}`);return d},enc(o){return i.setBigInt64(0,this.parse(o),!0),{lo:i.getInt32(0,!0),hi:i.getInt32(4,!0)}},uEnc(o){return i.setBigInt64(0,this.uParse(o),!0),{lo:i.getInt32(0,!0),hi:i.getInt32(4,!0)}},dec(o,d){return i.setInt32(0,o,!0),i.setInt32(4,d,!0),i.getBigInt64(0,!0)},uDec(o,d){return i.setInt32(0,o,!0),i.setInt32(4,d,!0),i.getBigUint64(0,!0)}}}return{zero:"0",supported:!1,parse(t){return typeof t!="string"&&(t=t.toString()),Se(t),t},uParse(t){return typeof t!="string"&&(t=t.toString()),De(t),t},enc(t){return typeof t!="string"&&(t=t.toString()),Se(t),oe(t)},uEnc(t){return typeof t!="string"&&(t=t.toString()),De(t),oe(t)},dec(t,n){return xe(t,n)},uDec(t,n){return de(t,n)}}}function Se(i){if(!/^-?[0-9]+$/.test(i))throw new Error("invalid int64: "+i)}function De(i){if(!/^[0-9]+$/.test(i))throw new Error("invalid uint64: "+i)}var S,Me=L(()=>{"use strict";le();S=lt()});function fe(){if(globalThis[ue]==null){let i=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[ue]={encodeUtf8(t){return i.encode(t)},decodeUtf8(t){return e.decode(t)},checkUtf8(t){try{return encodeURIComponent(t),!0}catch{return!1}}}}return globalThis[ue]}var ue,he=L(()=>{"use strict";ue=Symbol.for("@bufbuild/protobuf/text-encoding")});function pe(i){if(typeof i=="string")i=Number(i);else if(typeof i!="number")throw new Error("invalid int32: "+typeof i);if(!Number.isInteger(i)||i>pt||i<yt)throw new Error("invalid int32: "+i)}function ke(i){if(typeof i=="string")i=Number(i);else if(typeof i!="number")throw new Error("invalid uint32: "+typeof i);if(!Number.isInteger(i)||i>ht||i<0)throw new Error("invalid uint32: "+i)}function gt(i){if(typeof i=="string"){let e=i;if(i=Number(i),Number.isNaN(i)&&e!=="NaN")throw new Error("invalid float32: "+e)}else if(typeof i!="number")throw new Error("invalid float32: "+typeof i);if(Number.isFinite(i)&&(i>ut||i<ft))throw new Error("invalid float32: "+i)}var O,ut,ft,ht,pt,yt,U,x,Oe=L(()=>{"use strict";le();Me();he();(function(i){i[i.Varint=0]="Varint",i[i.Bit64=1]="Bit64",i[i.LengthDelimited=2]="LengthDelimited",i[i.StartGroup=3]="StartGroup",i[i.EndGroup=4]="EndGroup",i[i.Bit32=5]="Bit32"})(O||(O={}));ut=34028234663852886e22,ft=-34028234663852886e22,ht=4294967295,pt=2147483647,yt=-2147483648,U=class{constructor(e=fe().encodeUtf8){this.encodeUtf8=e,this.stack=[],this.chunks=[],this.buf=[]}finish(){this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]);let e=0;for(let r=0;r<this.chunks.length;r++)e+=this.chunks[r].length;let t=new Uint8Array(e),n=0;for(let r=0;r<this.chunks.length;r++)t.set(this.chunks[r],n),n+=this.chunks[r].length;return this.chunks=[],t}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let e=this.finish(),t=this.stack.pop();if(!t)throw new Error("invalid state, fork stack empty");return this.chunks=t.chunks,this.buf=t.buf,this.uint32(e.byteLength),this.raw(e)}tag(e,t){return this.uint32((e<<3|t)>>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for(ke(e);e>127;)this.buf.push(e&127|128),e=e>>>7;return this.buf.push(e),this}int32(e){return pe(e),ce(e,this.buf),this}bool(e){return this.buf.push(e?1:0),this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){let t=this.encodeUtf8(e);return this.uint32(t.byteLength),this.raw(t)}float(e){gt(e);let t=new Uint8Array(4);return new DataView(t.buffer).setFloat32(0,e,!0),this.raw(t)}double(e){let t=new Uint8Array(8);return new DataView(t.buffer).setFloat64(0,e,!0),this.raw(t)}fixed32(e){ke(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){pe(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return pe(e),e=(e<<1^e>>31)>>>0,ce(e,this.buf),this}sfixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=S.enc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}fixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=S.uEnc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=S.enc(e);return z(t.lo,t.hi,this.buf),this}sint64(e){let t=S.enc(e),n=t.hi>>31,r=t.lo<<1^n,s=(t.hi<<1|t.lo>>>31)^n;return z(r,s,this.buf),this}uint64(e){let t=S.uEnc(e);return z(t.lo,t.hi,this.buf),this}},x=class{constructor(e,t=fe().decodeUtf8){this.decodeUtf8=t,this.varint64=Be,this.uint32=Le,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength)}tag(){let e=this.uint32(),t=e>>>3,n=e&7;if(t<=0||n<0||n>5)throw new Error("illegal tag: field no "+t+" wire type "+n);return[t,n]}skip(e,t){let n=this.pos;switch(e){case O.Varint:for(;this.buf[this.pos++]&128;);break;case O.Bit64:this.pos+=4;case O.Bit32:this.pos+=4;break;case O.LengthDelimited:let r=this.uint32();this.pos+=r;break;case O.StartGroup:for(;;){let[s,o]=this.tag();if(o===O.EndGroup){if(t!==void 0&&s!==t)throw new Error("invalid end group tag");break}this.skip(o,s)}break;default:throw new Error("cant skip wire type "+e)}return this.assertBounds(),this.buf.subarray(n,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)}int64(){return S.dec(...this.varint64())}uint64(){return S.uDec(...this.varint64())}sint64(){let[e,t]=this.varint64(),n=-(e&1);return e=(e>>>1|(t&1)<<31)^n,t=t>>>1^n,S.dec(e,t)}bool(){let[e,t]=this.varint64();return e!==0||t!==0}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return S.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return S.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),t=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(t,t+e)}string(){return this.decodeUtf8(this.bytes())}}});var Ue=L(()=>{"use strict"});var Pe=L(()=>{"use strict"});var Ne=L(()=>{"use strict"});var Ve=L(()=>{"use strict";Oe();Ue();he();Pe();Ne()});function Fe(){return{propertyId:"",pageviewId:"",sessionId:"",pageUrl:"",country:"",region:"",deviceType:"",userId:"",domain:"",events:[],browser:"",deviceManufacturer:"",deviceModel:"",city:"",postalCode:""}}function $e(){return{timestampMs:0,type:0,eventName:"",auctionId:"",transactionId:"",adUnitCode:"",bid:void 0,namespace:"",eventId:"",metadata:{},viewableDurationMs:void 0,bidderOutcomes:[]}}function We(){return{key:"",value:""}}function qe(){return{bidder:"",adUnitCode:"",mediaType:"",outcome:0,latencyMs:0}}function He(){return{bidder:"",cpm:0,currency:"",width:0,height:0,dealId:"",mediaType:"",latencyMs:0,advertiserDomain:"",creativeId:""}}var b,D,Z,Y,ye,X,Q,Ke=L(()=>{"use strict";Ve();b={TRACE_EVENT_TYPE_UNSPECIFIED:0,AUCTION_START:1,AUCTION_END:2,BID_RESPONSE:3,BID_WIN:4,IMPRESSION:5,VIEWABLE:6,TIME_IN_VIEW:7,REFRESH:8,ERROR:9,SLOT_DEFINED:10,SLOT_DESTROYED:11,CLICK:12,AD_RENDER_FAILED:13,UNRECOGNIZED:-1},D={BIDDER_OUTCOME_UNSPECIFIED:0,BIDDER_OUTCOME_BID:1,BIDDER_OUTCOME_NO_BID:2,BIDDER_OUTCOME_TIMEOUT:3,BIDDER_OUTCOME_ERROR:4,BIDDER_OUTCOME_NO_RESPONSE:5,UNRECOGNIZED:-1};Z={encode(i,e=new U){if(i.propertyId!==void 0&&i.propertyId!==""&&e.uint32(10).string(i.propertyId),i.pageviewId!==void 0&&i.pageviewId!==""&&e.uint32(18).string(i.pageviewId),i.sessionId!==void 0&&i.sessionId!==""&&e.uint32(26).string(i.sessionId),i.pageUrl!==void 0&&i.pageUrl!==""&&e.uint32(34).string(i.pageUrl),i.country!==void 0&&i.country!==""&&e.uint32(42).string(i.country),i.region!==void 0&&i.region!==""&&e.uint32(50).string(i.region),i.deviceType!==void 0&&i.deviceType!==""&&e.uint32(58).string(i.deviceType),i.userId!==void 0&&i.userId!==""&&e.uint32(66).string(i.userId),i.domain!==void 0&&i.domain!==""&&e.uint32(74).string(i.domain),i.events!==void 0&&i.events.length!==0)for(let t of i.events)Y.encode(t,e.uint32(82).fork()).join();return i.browser!==void 0&&i.browser!==""&&e.uint32(90).string(i.browser),i.deviceManufacturer!==void 0&&i.deviceManufacturer!==""&&e.uint32(98).string(i.deviceManufacturer),i.deviceModel!==void 0&&i.deviceModel!==""&&e.uint32(106).string(i.deviceModel),i.city!==void 0&&i.city!==""&&e.uint32(114).string(i.city),i.postalCode!==void 0&&i.postalCode!==""&&e.uint32(122).string(i.postalCode),e},decode(i,e){let t=i instanceof x?i:new x(i),n=e===void 0?t.len:t.pos+e,r=Fe();for(;t.pos<n;){let s=t.uint32();switch(s>>>3){case 1:{if(s!==10)break;r.propertyId=t.string();continue}case 2:{if(s!==18)break;r.pageviewId=t.string();continue}case 3:{if(s!==26)break;r.sessionId=t.string();continue}case 4:{if(s!==34)break;r.pageUrl=t.string();continue}case 5:{if(s!==42)break;r.country=t.string();continue}case 6:{if(s!==50)break;r.region=t.string();continue}case 7:{if(s!==58)break;r.deviceType=t.string();continue}case 8:{if(s!==66)break;r.userId=t.string();continue}case 9:{if(s!==74)break;r.domain=t.string();continue}case 10:{if(s!==82)break;let o=Y.decode(t,t.uint32());o!==void 0&&r.events.push(o);continue}case 11:{if(s!==90)break;r.browser=t.string();continue}case 12:{if(s!==98)break;r.deviceManufacturer=t.string();continue}case 13:{if(s!==106)break;r.deviceModel=t.string();continue}case 14:{if(s!==114)break;r.city=t.string();continue}case 15:{if(s!==122)break;r.postalCode=t.string();continue}}if((s&7)===4||s===0)break;t.skip(s&7)}return r},create(i){return Z.fromPartial(i??{})},fromPartial(i){let e=Fe();return e.propertyId=i.propertyId??"",e.pageviewId=i.pageviewId??"",e.sessionId=i.sessionId??"",e.pageUrl=i.pageUrl??"",e.country=i.country??"",e.region=i.region??"",e.deviceType=i.deviceType??"",e.userId=i.userId??"",e.domain=i.domain??"",e.events=i.events?.map(t=>Y.fromPartial(t))||[],e.browser=i.browser??"",e.deviceManufacturer=i.deviceManufacturer??"",e.deviceModel=i.deviceModel??"",e.city=i.city??"",e.postalCode=i.postalCode??"",e}};Y={encode(i,e=new U){if(i.timestampMs!==void 0&&i.timestampMs!==0&&e.uint32(9).double(i.timestampMs),i.type!==void 0&&i.type!==0&&e.uint32(16).int32(i.type),i.eventName!==void 0&&i.eventName!==""&&e.uint32(26).string(i.eventName),i.auctionId!==void 0&&i.auctionId!==""&&e.uint32(34).string(i.auctionId),i.transactionId!==void 0&&i.transactionId!==""&&e.uint32(42).string(i.transactionId),i.adUnitCode!==void 0&&i.adUnitCode!==""&&e.uint32(50).string(i.adUnitCode),i.bid!==void 0&&Q.encode(i.bid,e.uint32(58).fork()).join(),i.namespace!==void 0&&i.namespace!==""&&e.uint32(66).string(i.namespace),i.eventId!==void 0&&i.eventId!==""&&e.uint32(74).string(i.eventId),globalThis.Object.entries(i.metadata||{}).forEach(([t,n])=>{ye.encode({key:t,value:n},e.uint32(82).fork()).join()}),i.viewableDurationMs!==void 0&&e.uint32(89).double(i.viewableDurationMs),i.bidderOutcomes!==void 0&&i.bidderOutcomes.length!==0)for(let t of i.bidderOutcomes)X.encode(t,e.uint32(98).fork()).join();return e},decode(i,e){let t=i instanceof x?i:new x(i),n=e===void 0?t.len:t.pos+e,r=$e();for(;t.pos<n;){let s=t.uint32();switch(s>>>3){case 1:{if(s!==9)break;r.timestampMs=t.double();continue}case 2:{if(s!==16)break;r.type=t.int32();continue}case 3:{if(s!==26)break;r.eventName=t.string();continue}case 4:{if(s!==34)break;r.auctionId=t.string();continue}case 5:{if(s!==42)break;r.transactionId=t.string();continue}case 6:{if(s!==50)break;r.adUnitCode=t.string();continue}case 7:{if(s!==58)break;r.bid=Q.decode(t,t.uint32());continue}case 8:{if(s!==66)break;r.namespace=t.string();continue}case 9:{if(s!==74)break;r.eventId=t.string();continue}case 10:{if(s!==82)break;let o=ye.decode(t,t.uint32());o.value!==void 0&&(r.metadata[o.key]=o.value);continue}case 11:{if(s!==89)break;r.viewableDurationMs=t.double();continue}case 12:{if(s!==98)break;let o=X.decode(t,t.uint32());o!==void 0&&r.bidderOutcomes.push(o);continue}}if((s&7)===4||s===0)break;t.skip(s&7)}return r},create(i){return Y.fromPartial(i??{})},fromPartial(i){let e=$e();return e.timestampMs=i.timestampMs??0,e.type=i.type??0,e.eventName=i.eventName??"",e.auctionId=i.auctionId??"",e.transactionId=i.transactionId??"",e.adUnitCode=i.adUnitCode??"",e.bid=i.bid!==void 0&&i.bid!==null?Q.fromPartial(i.bid):void 0,e.namespace=i.namespace??"",e.eventId=i.eventId??"",e.metadata=globalThis.Object.entries(i.metadata??{}).reduce((t,[n,r])=>(r!==void 0&&(t[n]=globalThis.String(r)),t),{}),e.viewableDurationMs=i.viewableDurationMs??void 0,e.bidderOutcomes=i.bidderOutcomes?.map(t=>X.fromPartial(t))||[],e}};ye={encode(i,e=new U){return i.key!==""&&e.uint32(10).string(i.key),i.value!==""&&e.uint32(18).string(i.value),e},decode(i,e){let t=i instanceof x?i:new x(i),n=e===void 0?t.len:t.pos+e,r=We();for(;t.pos<n;){let s=t.uint32();switch(s>>>3){case 1:{if(s!==10)break;r.key=t.string();continue}case 2:{if(s!==18)break;r.value=t.string();continue}}if((s&7)===4||s===0)break;t.skip(s&7)}return r},create(i){return ye.fromPartial(i??{})},fromPartial(i){let e=We();return e.key=i.key??"",e.value=i.value??"",e}};X={encode(i,e=new U){return i.bidder!==void 0&&i.bidder!==""&&e.uint32(10).string(i.bidder),i.adUnitCode!==void 0&&i.adUnitCode!==""&&e.uint32(18).string(i.adUnitCode),i.mediaType!==void 0&&i.mediaType!==""&&e.uint32(26).string(i.mediaType),i.outcome!==void 0&&i.outcome!==0&&e.uint32(32).int32(i.outcome),i.latencyMs!==void 0&&i.latencyMs!==0&&e.uint32(41).double(i.latencyMs),e},decode(i,e){let t=i instanceof x?i:new x(i),n=e===void 0?t.len:t.pos+e,r=qe();for(;t.pos<n;){let s=t.uint32();switch(s>>>3){case 1:{if(s!==10)break;r.bidder=t.string();continue}case 2:{if(s!==18)break;r.adUnitCode=t.string();continue}case 3:{if(s!==26)break;r.mediaType=t.string();continue}case 4:{if(s!==32)break;r.outcome=t.int32();continue}case 5:{if(s!==41)break;r.latencyMs=t.double();continue}}if((s&7)===4||s===0)break;t.skip(s&7)}return r},create(i){return X.fromPartial(i??{})},fromPartial(i){let e=qe();return e.bidder=i.bidder??"",e.adUnitCode=i.adUnitCode??"",e.mediaType=i.mediaType??"",e.outcome=i.outcome??0,e.latencyMs=i.latencyMs??0,e}};Q={encode(i,e=new U){return i.bidder!==void 0&&i.bidder!==""&&e.uint32(10).string(i.bidder),i.cpm!==void 0&&i.cpm!==0&&e.uint32(17).double(i.cpm),i.currency!==void 0&&i.currency!==""&&e.uint32(26).string(i.currency),i.width!==void 0&&i.width!==0&&e.uint32(32).int32(i.width),i.height!==void 0&&i.height!==0&&e.uint32(40).int32(i.height),i.dealId!==void 0&&i.dealId!==""&&e.uint32(50).string(i.dealId),i.mediaType!==void 0&&i.mediaType!==""&&e.uint32(58).string(i.mediaType),i.latencyMs!==void 0&&i.latencyMs!==0&&e.uint32(65).double(i.latencyMs),i.advertiserDomain!==void 0&&i.advertiserDomain!==""&&e.uint32(74).string(i.advertiserDomain),i.creativeId!==void 0&&i.creativeId!==""&&e.uint32(82).string(i.creativeId),e},decode(i,e){let t=i instanceof x?i:new x(i),n=e===void 0?t.len:t.pos+e,r=He();for(;t.pos<n;){let s=t.uint32();switch(s>>>3){case 1:{if(s!==10)break;r.bidder=t.string();continue}case 2:{if(s!==17)break;r.cpm=t.double();continue}case 3:{if(s!==26)break;r.currency=t.string();continue}case 4:{if(s!==32)break;r.width=t.int32();continue}case 5:{if(s!==40)break;r.height=t.int32();continue}case 6:{if(s!==50)break;r.dealId=t.string();continue}case 7:{if(s!==58)break;r.mediaType=t.string();continue}case 8:{if(s!==65)break;r.latencyMs=t.double();continue}case 9:{if(s!==74)break;r.advertiserDomain=t.string();continue}case 10:{if(s!==82)break;r.creativeId=t.string();continue}}if((s&7)===4||s===0)break;t.skip(s&7)}return r},create(i){return Q.fromPartial(i??{})},fromPartial(i){let e=He();return e.bidder=i.bidder??"",e.cpm=i.cpm??0,e.currency=i.currency??"",e.width=i.width??0,e.height=i.height??0,e.dealId=i.dealId??"",e.mediaType=i.mediaType??"",e.latencyMs=i.latencyMs??0,e.advertiserDomain=i.advertiserDomain??"",e.creativeId=i.creativeId??"",e}}});function W(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,i=>{let e=Math.random()*16|0;return(i==="x"?e:e&3|8).toString(16)})}function Mt(i){let e="";for(let n=0;n<i.length;n+=8192)e+=String.fromCharCode(...i.subarray(n,n+8192));return btoa(e)}function kt(i){let e=atob(i),t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return t}function Ot(i){if(!i)return!1;let e;try{e=new URL(i)}catch{return!1}return e.username||e.password?!1:e.protocol==="https:"?!0:e.protocol==="http:"?e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname==="[::1]":!1}function Ut(i){let e={},t=0;for(let n of Object.keys(i)){if(t>=Tt)break;let r=i[n];if(r==null)continue;let s=String(r);e[n]=s.length>je?`${s.slice(0,je)}...[truncated]`:s,t++}return e}function Pt(i){let e=i.slice(ee.length).split("_");return e.length===2&&/^\d+$/.test(e[0])}function Nt(i,e){if(!i||!e)return!1;try{return new URL(i).origin===new URL(e).origin}catch{return!1}}function Xe(){let i=Date.now();if(M=i,!!G)try{typeof localStorage<"u"&&localStorage.setItem(te,i.toString())}catch{}}function Vt(){let i=Date.now(),e=!!P&&!!M&&i-M<=me;try{if(G&&typeof localStorage<"u"){let t=localStorage.getItem(Ye),n=localStorage.getItem(te),r=n&&parseInt(n,10)||0;if(t&&r&&i-r<=me)return localStorage.setItem(te,i.toString()),P=t,M=i,t;let s=e?P:W();return localStorage.setItem(Ye,s),localStorage.setItem(te,i.toString()),P=s,M=i,s}}catch{}return P&&M&&i-M<=me?(M=i,P):(P=W(),M=i,P)}function h(i){return String(i??"").replace(/%/g,"%25").replace(/:/g,"%3A")}function Ft(i,e){switch(i){case"auctionInit":return`auctionInit:${h(e?.auctionId)}`;case"auctionEnd":return`auctionEnd:${h(e?.auctionId)}`;case"bidRequested":{let t=Array.isArray(e?.bids)?e.bids.map(n=>h(n?.bidId||n?.transactionId||n?.adUnitCode)).join(","):"";return`bidRequested:${h(e?.auctionId)}:${h(e?.bidderCode||e?.bidder)}:${t}`}case"bidResponse":{let t=e||{},n=t.creativeId||t.adId||t.requestId||t.bidId||"",r=t.originalCpm??t.cpm??"";return`bidResponse:${h(t.auctionId)}:${h(t.adUnitCode)}:${h(t.bidderCode||t.bidder)}:${h(n)}:${h(r)}`}case"bidTimeout":return"bidTimeout:"+(Array.isArray(e)?e:e?[e]:[]).map(n=>`${h(n?.auctionId)}:${h(n?.bidderCode||n?.bidder)}:${h(n?.bidId||n?.transactionId||n?.adUnitCode)}`).join(",");case"bidWon":{let t=e||{},n=t.creativeId||t.adId||t.requestId||t.bidId||"",r=t.originalCpm??t.cpm??"";return`bidWon:${h(t.auctionId)}:${h(t.adUnitCode)}:${h(t.bidderCode||t.bidder)}:${h(n)}:${h(r)}`}case"noBid":return`noBid:${h(e?.auctionId)}:${h(e?.adUnitCode)}:${h(e?.bidderCode||e?.bidder)}:${h(e?.bidId||e?.transactionId)}`;case"adRenderFailed":{let t=e?.bid||{};return`adRenderFailed:${h(t.auctionId||e?.auctionId)}:${h(t.adUnitCode||e?.adUnitCode)}:${h(t.bidderCode||t.bidder||e?.bidderCode||e?.bidder)}:${h(e?.reason)}:${h(e?.message)}`}case"adRenderSucceeded":{let t=e?.bid||e||{},n=t.creativeId||t.adId||e?.adId||"",r=t.originalCpm??t.cpm??"";return`adRenderSucceeded:${h(t.auctionId||e?.auctionId)}:${h(t.adUnitCode||e?.adUnitCode)}:${h(t.bidderCode||t.bidder)}:${h(n)}:${h(r)}`}case"setTargeting":return`setTargeting:${Object.keys(e||{}).sort().map(h).join(",")}`;case"auctionDebug":return`auctionDebug:${h(e?.type)}:${h(String(e?.arguments?.[0]??"").slice(0,50))}`;default:return""}}function N(i){if(Number.isFinite(i?.width)&&Number.isFinite(i?.height))return{width:i.width,height:i.height};if(typeof i?.size=="string"){let e=i.size.match(/^(\d+)x(\d+)$/);if(e)return{width:Number(e[1]),height:Number(e[2])}}return{width:Number.isFinite(i?.width)?i.width:0,height:Number.isFinite(i?.height)?i.height:0}}function Qe(i){if(i)try{let e=i.prototype;if(e&&typeof e.getAdsManager=="function"&&!e.getAdsManager.__bidkernelHooked){let t=e.getAdsManager,n=function(...r){let s=t.apply(this,r);if(s)for(let o of F.getActiveInstances())try{o.attachImaAdsManager(s)}catch{}return s};n.__bidkernelHooked=!0,e.getAdsManager=n}}catch{}}function Ze(i){if(i)try{let e=i.prototype||i;if(e&&typeof e.init=="function"&&!e.init.__bidkernelHooked){let t=e.init,n=function(...r){for(let s of F.getActiveInstances())try{s.attachImaAdsManager(this)}catch{}return t.apply(this,r)};n.__bidkernelHooked=!0,e.init=n}if(e&&typeof e.start=="function"&&!e.start.__bidkernelHooked){let t=e.start,n=function(...r){for(let s of F.getActiveInstances())try{s.attachImaAdsManager(this)}catch{}return t.apply(this,r)};n.__bidkernelHooked=!0,e.start=n}}catch{}}function Je(i){if(i)try{let e=i.prototype;if(!e)return;if(typeof e.addEventListener=="function"&&!e.addEventListener.__bidkernelHooked){let t=e.addEventListener,n=function(r,s,...o){if((r==="adsManagerLoaded"||r===(this?.AdsManagerLoadedEvent?.Type?.ADS_MANAGER_LOADED||"adsManagerLoaded"))&&typeof s=="function"){let d=be.get(s);return d||(d=function(a){if(a&&typeof a.getAdsManager=="function"&&!a.getAdsManager.__bidkernelHooked){let c=a.getAdsManager;a.getAdsManager=function(...u){let g=c.apply(this,u);if(g)for(let f of F.getActiveInstances())try{f.attachImaAdsManager(g)}catch{}return g},a.getAdsManager.__bidkernelHooked=!0}return s.apply(this,arguments)},be.set(s,d)),t.call(this,r,d,...o)}return t.call(this,r,s,...o)};n.__bidkernelHooked=!0,e.addEventListener=n}if(typeof e.removeEventListener=="function"&&!e.removeEventListener.__bidkernelHooked){let t=e.removeEventListener,n=function(r,s,...o){let d=typeof s=="function"?be.get(s):void 0;return t.call(this,r,d||s,...o)};n.__bidkernelHooked=!0,e.removeEventListener=n}}catch{}}function K(i){if(!(!i||typeof i!="object"))try{i.AdsManagerLoadedEvent&&Qe(i.AdsManagerLoadedEvent);let e=Object.getOwnPropertyDescriptor(i,"AdsManagerLoadedEvent");if(!e||e.configurable){let r=i.AdsManagerLoadedEvent;try{Object.defineProperty(i,"AdsManagerLoadedEvent",{configurable:!0,enumerable:!0,get(){return r},set(s){r=s,Qe(s)}})}catch{}}i.AdsLoader&&Je(i.AdsLoader);let t=Object.getOwnPropertyDescriptor(i,"AdsLoader");if(!t||t.configurable){let r=i.AdsLoader;try{Object.defineProperty(i,"AdsLoader",{configurable:!0,enumerable:!0,get(){return r},set(s){r=s,Je(s)}})}catch{}}i.AdsManager&&Ze(i.AdsManager);let n=Object.getOwnPropertyDescriptor(i,"AdsManager");if(!n||n.configurable){let r=i.AdsManager;try{Object.defineProperty(i,"AdsManager",{configurable:!0,enumerable:!0,get(){return r},set(s){r=s,Ze(s)}})}catch{}}}catch{}}function Ee(){if(typeof window>"u")return;let i=window;if(i.google?.ima&&K(i.google.ima),i.google&&typeof i.google=="object"){let t=Object.getOwnPropertyDescriptor(i.google,"ima");if(!t||t.configurable){let n=i.google.ima;try{Object.defineProperty(i.google,"ima",{configurable:!0,enumerable:!0,get(){return n},set(r){n=r,K(r)}})}catch{}}}let e=Object.getOwnPropertyDescriptor(i,"google");if(!e||e.configurable){let t=i.google;try{Object.defineProperty(i,"google",{configurable:!0,enumerable:!0,get(){return t},set(n){if(t=n,t&&typeof t=="object"){t.ima&&K(t.ima);let r=Object.getOwnPropertyDescriptor(t,"ima");if(!r||r.configurable){let s=t.ima;try{Object.defineProperty(t,"ima",{configurable:!0,enumerable:!0,get(){return s},set(o){s=o,K(o)}})}catch{}}}}})}catch{}}}function q(i,e=!0){if(!i)return null;if(Array.isArray(i)){let t=i.find(n=>n?.provider==="bidkernel")??(e?i.find(n=>n&&typeof n=="object"&&n.provider===void 0):void 0);return t?q(t,e):null}if(typeof i=="object"){if(i.options&&typeof i.options=="object")return i.options;if(i.config&&typeof i.config=="object")return i.config;if(i.propertyId||i.endpoint)return i}return null}function $t(i){if(!i)return null;if(i._bidkernelAnalyticsConfig){let e=q(i._bidkernelAnalyticsConfig);if(e)return e}if(i.bidkernelPrebidAnalytics){let e=i.bidkernelPrebidAnalytics;if(e.options){let t=q(e.options);if(t)return t}if(e.config){let t=q(e.config);if(t)return t}if(e.propertyId)return q(e)}return null}function Te(i="pbjs",e){let t=typeof window<"u"?window:{};t[i]=t[i]||{};let n=t[i],r=o=>{let d=t._bidkernelPrebidAnalytics,a=d?.getEndpoint?.()||"",c={pbjsGlobalName:i,...e,...o};if(a&&!Nt(c.endpoint||"",a)&&(Ie.warn(`Ignoring analytics endpoint change to ${c.endpoint||"(empty)"}: this page is pinned to ${a}. Reload to change the ingest endpoint.`),c.endpoint=a),d)try{d.disable()}catch(g){Ie.warn("Failed to disable previous analytics instance:",g)}let u=new F(c);return u.enable(),t._bidkernelPrebidAnalytics=u,u},s=()=>{try{n.adapterManager&&typeof n.adapterManager.registerAnalyticsAdapter=="function"&&n.adapterManager.registerAnalyticsAdapter({adapter:{enableAnalytics:d=>{let a=q(d,!Array.isArray(d));a&&r(a)},disableAnalytics:()=>{t._bidkernelPrebidAnalytics&&t._bidkernelPrebidAnalytics.disable()}},code:"bidkernel"});let o=$t(t);o&&(o.propertyId||e?.propertyId)&&r(o)}catch(o){Ie.warn("Failed to register standard Prebid analytics adapter:",o)}};n.adapterManager&&typeof n.adapterManager.registerAnalyticsAdapter=="function"?s():(n.que=n.que||[],n.que.push(s))}var bt,Ge,It,J,vt,Et,ge,je,Tt,ze,ee,wt,At,Rt,_t,Bt,xt,V,Ct,Lt,St,Dt,Ye,te,me,P,M,G,ve,be,F,Ie,et=L(()=>{"use strict";Re();Ke();bt=20,Ge=1e4,It=50,J=200,vt=300*1e3,Et=10,ge=32*1024,je=1024,Tt=16,ze="text/plain",ee="_bidkernel_pending_",wt=20,At=7200*1e3,Rt=1e4,_t={auctionStart:b.AUCTION_START,auctionEnd:b.AUCTION_END,bidResponse:b.BID_RESPONSE,bidWin:b.BID_WIN,adRenderFailed:b.AD_RENDER_FAILED,click:b.CLICK,impression:b.IMPRESSION,refresh:b.REFRESH,timeInView:b.TIME_IN_VIEW,viewable:b.VIEWABLE},Bt=3e3,xt=new Set([b.IMPRESSION,b.BID_WIN,b.CLICK]),V=1800*1e3,Ct=200,Lt=1e3,St=50,Dt=1e3,Ye="_bidkernel_session",te="_bidkernel_session_ts",me=1800*1e3,P=null,M=0,G=!0;ve=class{seenObjects=new WeakMap;seenKeys=new Set;isDuplicate(e,t){if(!t)return!1;if(typeof t=="object"){let r=this.seenObjects.get(t);if(r){if(r.has(e))return!0;r.add(e)}else this.seenObjects.set(t,new Set([e]))}let n=Ft(e,t);if(n){if(this.seenKeys.has(n))return!0;if(this.seenKeys.size>=1e3){let r=this.seenKeys.values().next().value;r!==void 0&&this.seenKeys.delete(r)}this.seenKeys.add(n)}return!1}};be=new WeakMap;typeof window<"u"&&Ee();F=class i{static activeInstances=new Set;static getActiveInstances(){return i.activeInstances}static initImaInterception(){Ee()}static setStorageAllowed(e){G=e}static isStorageAllowed(){return G}config;queue=[];errorCount=0;flushTimer=null;boundFlushBeacon;boundVisibilityChange;isEnabled=!1;boundPbjsHandlers=[];pageUrl="";deduper=new ve;consecutiveSendFailures=0;nextSendAllowedAt=0;replayedEventCount=0;revenueFlushTimer=null;persistedBatchKeys=[];persistedCleanupTimer=null;intersectionObserver=null;slotViewabilityRecords=new Map;elementToSlotId=new Map;slotRefreshIndices=new Map;slotLastAuctionIds=new Map;pendingThresholdListeners=new Map;pendingViewableListeners=new Map;slotElements=new Map;clickDetachCleanups=new Set;lastClickAt=new Map;slotEmittedImpressionKeys=new Set;cachedWinningBids=new Map;videoDetachCleanups=new Set;auctionBidderOutcomes=new Map;logger;constructor(e){e.storageAllowed!==void 0&&i.setStorageAllowed(e.storageAllowed);let t=e.endpoint||"",n=!t||Ot(t)?t:"";this.config={endpoint:n,propertyId:e.propertyId||"",pageviewId:e.pageviewId||W(),sessionId:e.sessionId||Vt(),userId:e.userId||"",deviceType:e.deviceType||"desktop",country:e.country||"",region:e.region||"",auctionEnabled:e.auctionEnabled??!0,warningsEnabled:e.warningsEnabled??!0,errorsEnabled:e.errorsEnabled??!0,viewabilityEnabled:e.viewabilityEnabled??!0,storageAllowed:e.storageAllowed??!0,logLevel:e.logLevel||"INFO",pbjsGlobalName:e.pbjsGlobalName||"pbjs",attachPbjsListeners:e.attachPbjsListeners??!0,revenueFlushDelayMs:Number.isFinite(e.revenueFlushDelayMs)&&e.revenueFlushDelayMs>=0?e.revenueFlushDelayMs:Bt},this.logger=se({prefix:"[bidkernel][prebid-analytics]",logLevel:this.config.logLevel}),t&&!n&&this.log("ERROR",`Rejected untrusted analytics endpoint ${t}: must be an absolute https:// URL without embedded credentials. Events will not be transmitted.`),this.boundFlushBeacon=()=>{this.flushAllSlotsTimeInView(),this.flushBeacon()},this.boundVisibilityChange=()=>this.handleVisibilityChange()}enable(){if(!this.isEnabled){if(this.isEnabled=!0,i.activeInstances.add(this),this.logger.setLevel(this.config.logLevel),this.config.endpoint||this.log("WARN","Endpoint is empty. Analytics events will not be transmitted."),this.config.viewabilityEnabled&&typeof IntersectionObserver<"u"){this.intersectionObserver=new IntersectionObserver(this.handleIntersection.bind(this),{threshold:[.5]});for(let e of this.slotViewabilityRecords.values())e.element&&this.intersectionObserver.observe(e.element)}if(this.config.attachPbjsListeners&&this.attachPbjs(),typeof window<"u"){if(!this.pageUrl)try{let e=new URL(window.location.href);this.pageUrl=e.origin+e.pathname}catch{this.pageUrl=window.location.href}window.addEventListener("pagehide",this.boundFlushBeacon),typeof document<"u"&&document.addEventListener("visibilitychange",this.boundVisibilityChange),this.flushTimer=setInterval(()=>this.flush(),Ge),this.resendPersistedBatches(),Ee(),window.google?.ima&&K(window.google.ima)}}}attachPbjs(){if(!this.isEnabled)return!1;if(this.boundPbjsHandlers.length>0)return!0;let t=(typeof window<"u"?window:{})[this.config.pbjsGlobalName]||{};if(typeof t.onEvent!="function")return this.log("WARN","pbjs.onEvent is not defined. Prebid analytics will not function."),!1;this.log("DEBUG","Attaching event listeners to pbjs");let n={auctionInit:this.handleAuctionInit.bind(this),auctionEnd:this.handleAuctionEnd.bind(this),bidRequested:this.handleBidRequested.bind(this),bidResponse:this.handleBidResponse.bind(this),bidTimeout:this.handleBidTimeout.bind(this),bidWon:this.handleBidWon.bind(this),noBid:this.handleNoBid.bind(this),adRenderFailed:this.handleAdRenderFailed.bind(this),adRenderSucceeded:this.handleAdRenderSucceeded.bind(this)};for(let[r,s]of Object.entries(n))t.onEvent(r,s),this.boundPbjsHandlers.push({event:r,handler:s});if(typeof t.getEvents=="function")try{let r=t.getEvents();if(Array.isArray(r)){let s=r.slice(this.replayedEventCount);if(this.replayedEventCount=r.length,s.length>0){this.log("DEBUG",`Replaying ${s.length} historical events from pbjs.getEvents()`);for(let o of s){if(!o)continue;let d=o.eventType||o.event||o.name,a=o.args!==void 0?o.args:o.data!==void 0?o.data:o,c=n[d];c&&c(a)}}}}catch(r){this.log("WARN","Failed to replay historical events from pbjs.getEvents()",r)}return!0}disable(){if(this.isEnabled){this.flushAllSlotsTimeInView(),this.isEnabled=!1,i.activeInstances.delete(this);for(let e of this.slotViewabilityRecords.values()){e.dwellTimer&&(clearTimeout(e.dwellTimer),e.dwellTimer=null,e.dwellStartedAt=null);for(let t of e.thresholdListeners)t.timer&&(clearTimeout(t.timer),t.timer=null)}this.intersectionObserver&&(this.intersectionObserver.disconnect(),this.intersectionObserver=null),this.slotViewabilityRecords.clear(),this.elementToSlotId.clear();for(let e of this.videoDetachCleanups)try{e()}catch{}this.videoDetachCleanups.clear();for(let e of Array.from(this.clickDetachCleanups))try{e()}catch{}if(this.clickDetachCleanups.clear(),this.slotElements.clear(),this.cachedWinningBids.clear(),this.slotEmittedImpressionKeys.clear(),this.slotLastAuctionIds.clear(),this.auctionBidderOutcomes.clear(),this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.revenueFlushTimer&&(clearTimeout(this.revenueFlushTimer),this.revenueFlushTimer=null),this.persistedCleanupTimer&&(clearTimeout(this.persistedCleanupTimer),this.persistedCleanupTimer=null),typeof window<"u"&&(window.removeEventListener("pagehide",this.boundFlushBeacon),typeof document<"u"&&document.removeEventListener("visibilitychange",this.boundVisibilityChange)),this.boundPbjsHandlers.length>0){let t=(typeof window<"u"?window:{})[this.config.pbjsGlobalName]||{};if(typeof t.offEvent=="function")for(let{event:n,handler:r}of this.boundPbjsHandlers)t.offEvent(n,r);this.boundPbjsHandlers=[]}this.flush()}}handleVisibilityChange(){if(!(typeof document>"u")){if(document.visibilityState==="hidden"){let e=typeof performance<"u"&&performance.now?performance.now():Date.now();for(let t of this.slotViewabilityRecords.values()){t.inView&&t.lastEnteredViewAt!==null&&(t.accumulatedTimeInViewMs+=Math.max(0,e-t.lastEnteredViewAt),t.lastEnteredViewAt=null,this.checkThresholdListeners(t)),t.dwellTimer&&(clearTimeout(t.dwellTimer),t.dwellTimer=null,t.dwellStartedAt=null);for(let r of t.thresholdListeners)r.timer&&(clearTimeout(r.timer),r.timer=null);let n=Math.round(t.accumulatedTimeInViewMs);n>0&&this.enqueue(b.TIME_IN_VIEW,"timeInView",{auctionId:t.auctionId,transactionId:t.transactionId,adUnitCode:t.adUnitCode,viewableDurationMs:n,bid:t.bidPayload,metadata:{...t.metadata,refresh_index:String(t.refreshIndex)}})}this.flushBeacon()}else if(document.visibilityState==="visible"){let e=typeof performance<"u"&&performance.now?performance.now():Date.now();for(let t of this.slotViewabilityRecords.values())if(t.inView){if(t.lastEnteredViewAt=e,!t.viewableFired&&t.dwellTimer===null){let n=t.mediaType==="video"?2e3:1e3;t.dwellStartedAt=e,t.dwellTimer=setTimeout(()=>{this.handleDwellComplete(t)},n)}this.scheduleThresholdTimers(t)}}}}handleIntersection(e){for(let t of e){let n=this.elementToSlotId.get(t.target);if(!n){for(let a of i.activeInstances)if(a!==this&&a.elementToSlotId.has(t.target)){a.handleIntersection([t]);break}continue}let r=this.slotViewabilityRecords.get(n);if(!r)continue;let s=t.isIntersecting&&(t.intersectionRatio===void 0||t.intersectionRatio>=.5),o=typeof document>"u"||document.visibilityState==="visible",d=typeof performance<"u"&&performance.now?performance.now():Date.now();if(s){if(!r.inView&&(r.inView=!0,o)){if(r.lastEnteredViewAt=d,!r.viewableFired&&r.dwellTimer===null){let a=r.mediaType==="video"?2e3:1e3;r.dwellStartedAt=d,r.dwellTimer=setTimeout(()=>{this.handleDwellComplete(r)},a)}this.scheduleThresholdTimers(r)}}else{r.inView&&(r.lastEnteredViewAt!==null&&(r.accumulatedTimeInViewMs+=Math.max(0,d-r.lastEnteredViewAt),r.lastEnteredViewAt=null),r.inView=!1,this.checkThresholdListeners(r)),r.dwellTimer!==null&&(clearTimeout(r.dwellTimer),r.dwellTimer=null,r.dwellStartedAt=null);for(let a of r.thresholdListeners)a.timer&&(clearTimeout(a.timer),a.timer=null)}}}handleDwellComplete(e){e.dwellTimer=null,e.dwellStartedAt=null,e.inView&&(typeof document<"u"&&document.visibilityState==="hidden"||(e.viewableFired||(e.viewableFired=!0,this.enqueue(b.VIEWABLE,"viewable",{auctionId:e.auctionId,transactionId:e.transactionId,adUnitCode:e.adUnitCode,bid:e.bidPayload,metadata:{...e.metadata,refresh_index:String(e.refreshIndex)}})),this.notifyViewable(e)))}notifyViewable(e){if(e.viewableFired){for(let t of e.viewableListeners)if(t.firedForIndex!==e.refreshIndex){t.firedForIndex=e.refreshIndex;try{t.callback(e.slotId)}catch(n){this.log("ERROR","Error in viewable listener callback",n)}}}}setSlotElement(e,t){this.slotElements.set(e,t);let n=this.slotViewabilityRecords.get(e);n&&n.element!==t&&this.observeSlot(t,e,{refreshIndex:n.refreshIndex,emitRefreshEvent:!1})}recordClick(e,t){if(!this.isEnabled||!e)return!1;let n=Date.now();if(n-(this.lastClickAt.get(e)||0)<Dt)return!1;this.lastClickAt.set(e,n);let r=this.getCachedBid(e);return this.enqueue(b.CLICK,"click",{auctionId:r?.auctionId||"",transactionId:r?.transactionId||"",adUnitCode:e,bid:r?.bidTrace,metadata:{...t?.metadata,refresh_index:String(this.getRefreshIndex(e))}}),!0}attachClickTracker(e,t){if(typeof window>"u")return()=>{};let n=()=>{setTimeout(()=>{let s=document.activeElement;s&&(s===e||e.contains(s))&&(this.recordClick(t,{metadata:{source:"blur"}}),window.focus())},0)};window.addEventListener("blur",n);let r=()=>{window.removeEventListener("blur",n),this.clickDetachCleanups.delete(r)};return this.clickDetachCleanups.add(r),r}onViewable(e,t){let n={callback:t,firedForIndex:-1},r=this.slotViewabilityRecords.get(e);return r?(r.viewableListeners.add(n),this.notifyViewable(r)):(this.pendingViewableListeners.has(e)||this.pendingViewableListeners.set(e,new Set),this.pendingViewableListeners.get(e).add(n)),()=>{this.slotViewabilityRecords.get(e)?.viewableListeners.delete(n),this.pendingViewableListeners.get(e)?.delete(n)}}scheduleThresholdTimers(e){if(!e.inView||typeof document<"u"&&document.visibilityState==="hidden")return;let t=this.getCurrentTimeInView(e);for(let n of e.thresholdListeners)if(!n.fired)if(t>=n.thresholdMs){n.fired=!0,n.timer&&(clearTimeout(n.timer),n.timer=null);try{n.callback(e.slotId,t)}catch(r){this.log("ERROR","Error in threshold listener callback",r)}}else{n.timer&&clearTimeout(n.timer);let r=n.thresholdMs-t;n.timer=setTimeout(()=>{if(n.timer=null,!n.fired&&e.inView&&(typeof document>"u"||document.visibilityState==="visible")){let s=this.getCurrentTimeInView(e);if(s>=n.thresholdMs){n.fired=!0;try{n.callback(e.slotId,s)}catch(o){this.log("ERROR","Error in threshold listener callback",o)}}}},r)}}checkThresholdListeners(e){let t=this.getCurrentTimeInView(e);for(let n of e.thresholdListeners)if(!n.fired&&t>=n.thresholdMs){n.fired=!0,n.timer&&(clearTimeout(n.timer),n.timer=null);try{n.callback(e.slotId,t)}catch(r){this.log("ERROR","Error in threshold listener callback",r)}}}getCurrentTimeInView(e){let t=e.accumulatedTimeInViewMs;if(e.inView&&e.lastEnteredViewAt!==null){let n=typeof performance<"u"&&performance.now?performance.now():Date.now();t+=Math.max(0,n-e.lastEnteredViewAt)}return t}flushSlotTimeInView(e){let t=this.slotViewabilityRecords.get(e);if(!t)return;if(t.inView&&t.lastEnteredViewAt!==null){let r=typeof performance<"u"&&performance.now?performance.now():Date.now();t.accumulatedTimeInViewMs+=Math.max(0,r-t.lastEnteredViewAt),t.lastEnteredViewAt=null}let n=Math.round(t.accumulatedTimeInViewMs);n>0&&this.enqueue(b.TIME_IN_VIEW,"timeInView",{auctionId:t.auctionId,transactionId:t.transactionId,adUnitCode:t.adUnitCode,viewableDurationMs:n,bid:t.bidPayload,metadata:{...t.metadata,refresh_index:String(t.refreshIndex)}}),t.accumulatedTimeInViewMs=0}flushAllSlotsTimeInView(){for(let e of Array.from(this.slotViewabilityRecords.keys()))this.flushSlotTimeInView(e)}observeSlot(e,t,n){if(!this.config.viewabilityEnabled)return;let r=null;if(typeof e=="string"){if(typeof document<"u"){try{r=document.querySelector(e)||document.getElementById(e)}catch{r=document.getElementById(e)}r||(r=document.getElementById(e))}}else r=e;let s=t||n?.adUnitCode||(r?r.id:"")||W(),o=this.slotViewabilityRecords.get(s);if(o){if(n?.refreshIndex===void 0||n.refreshIndex>o.refreshIndex){this.flushSlotTimeInView(s);let a=n?.refreshIndex!==void 0?n.refreshIndex:(this.slotRefreshIndices.get(s)??o.refreshIndex)+1;this.slotRefreshIndices.set(s,a),n?.emitRefreshEvent!==!1&&this.enqueue(b.REFRESH,"refresh",{auctionId:n?.auctionId||o.auctionId,transactionId:n?.transactionId||o.transactionId,adUnitCode:s,bid:n?.bid??o.bidPayload,metadata:{...n?.metadata,refresh_index:String(a)}}),o.dwellTimer&&(clearTimeout(o.dwellTimer),o.dwellTimer=null,o.dwellStartedAt=null);for(let u of o.thresholdListeners)u.fired=!1,u.timer&&(clearTimeout(u.timer),u.timer=null);o.viewableFired=!1,o.accumulatedTimeInViewMs=0;let c=typeof performance<"u"&&performance.now?performance.now():Date.now();if(o.lastEnteredViewAt=o.inView?c:null,o.refreshIndex=a,o.auctionId=n?.auctionId||o.auctionId,o.transactionId=n?.transactionId||o.transactionId,o.mediaType=n?.mediaType||o.mediaType||"banner",o.bidPayload=n?.bid!==void 0?n.bid:o.bidPayload,o.metadata=n?.metadata??o.metadata,o.inView&&(typeof document>"u"||document.visibilityState==="visible")){let u=o.mediaType==="video"?2e3:1e3;o.dwellStartedAt=c,o.dwellTimer=setTimeout(()=>{this.handleDwellComplete(o)},u),this.scheduleThresholdTimers(o)}}else o.auctionId=n?.auctionId||o.auctionId,o.transactionId=n?.transactionId||o.transactionId,o.mediaType=n?.mediaType||o.mediaType,n?.bid!==void 0&&(o.bidPayload=n.bid),n?.metadata!==void 0&&(o.metadata=n.metadata);n?.auctionId&&this.slotLastAuctionIds.set(s,n.auctionId),r&&(o.element&&o.element!==r&&this.intersectionObserver&&(this.intersectionObserver.unobserve(o.element),this.elementToSlotId.delete(o.element)),o.element=r,this.elementToSlotId.set(r,s),this.intersectionObserver?.observe(r))}else{let d=n?.refreshIndex??this.slotRefreshIndices.get(s)??0;this.slotRefreshIndices.set(s,d),n?.auctionId&&this.slotLastAuctionIds.set(s,n.auctionId);let a=this.pendingThresholdListeners.get(s)||new Set;this.pendingThresholdListeners.delete(s);let c=this.pendingViewableListeners.get(s)||new Set;this.pendingViewableListeners.delete(s);let u={slotId:s,element:r,adUnitCode:n?.adUnitCode||s,auctionId:n?.auctionId||"",transactionId:n?.transactionId||"",mediaType:n?.mediaType||"banner",bidPayload:n?.bid,metadata:n?.metadata,refreshIndex:d,inView:!1,lastEnteredViewAt:null,accumulatedTimeInViewMs:0,viewableFired:!1,dwellTimer:null,dwellStartedAt:null,thresholdListeners:a,viewableListeners:c};this.slotViewabilityRecords.set(s,u),r&&(this.elementToSlotId.set(r,s),this.intersectionObserver?.observe(r))}}unobserveSlot(e){let t=this.slotViewabilityRecords.get(e);if(t){this.flushSlotTimeInView(e),t.dwellTimer&&(clearTimeout(t.dwellTimer),t.dwellTimer=null,t.dwellStartedAt=null);for(let n of t.thresholdListeners)n.timer&&(clearTimeout(n.timer),n.timer=null);t.thresholdListeners=new Set,t.viewableListeners=new Set,t.element&&this.intersectionObserver&&(this.intersectionObserver.unobserve(t.element),this.elementToSlotId.delete(t.element),t.element=null),t.inView=!1,t.lastEnteredViewAt=null}}destroySlot(e){this.unobserveSlot(e),this.slotViewabilityRecords.delete(e),this.slotRefreshIndices.delete(e),this.slotLastAuctionIds.delete(e),this.pendingThresholdListeners.delete(e),this.pendingViewableListeners.delete(e);let t=`${h(e)}:`;for(let r of Array.from(this.slotEmittedImpressionKeys))(r===e||r.startsWith(t))&&this.slotEmittedImpressionKeys.delete(r);let n=this.cachedWinningBids.get(e);n&&this.deleteCachedBidEntry(n)}getCachedBid(e){let t=this.cachedWinningBids.get(e);if(t){if(Date.now()-t.timestamp>V){this.deleteCachedBidEntry(t);return}return t}}deleteCachedBidEntry(e){for(let[t,n]of Array.from(this.cachedWinningBids))n===e&&this.cachedWinningBids.delete(t)}pruneCachedWinningBids(){let e=Date.now();for(let[t,n]of Array.from(this.cachedWinningBids))e-n.timestamp>V&&this.cachedWinningBids.delete(t);for(;this.cachedWinningBids.size>Ct;){let t=this.cachedWinningBids.keys().next();if(t.done)break;this.cachedWinningBids.delete(t.value)}}findCachedWinningBid(e){let t=Date.now(),n=o=>this.hasImpressionEmitted(o.adUnitCode,void 0,o.auctionId,o.bidTrace.creativeId);if(e?.creativeId||e?.adId){for(let o of Array.from(this.cachedWinningBids.values()))if(!(t-o.timestamp>V)&&(e.creativeId&&(o.bidTrace.creativeId===e.creativeId||o.rawBid?.creativeId===e.creativeId)||e.adId&&(o.rawBid?.adId===e.adId||o.adUnitCode===e.adId)))return o}let r;if(e?.mediaType){for(let d of Array.from(this.cachedWinningBids.values())){if(t-d.timestamp>V)continue;(d.bidTrace.mediaType===e.mediaType||d.rawBid?.mediaType===e.mediaType||e.mediaType==="video"&&d.rawBid?.mediaTypes?.video!==void 0)&&(n(d)||(!r||d.timestamp<r.timestamp)&&(r=d))}if(r)return r;let o;for(let d of Array.from(this.cachedWinningBids.values())){if(t-d.timestamp>V)continue;(d.bidTrace.mediaType===e.mediaType||d.rawBid?.mediaType===e.mediaType||e.mediaType==="video"&&d.rawBid?.mediaTypes?.video!==void 0)&&(!o||d.timestamp>o.timestamp)&&(o=d)}if(o)return o}for(let o of Array.from(this.cachedWinningBids.values()))t-o.timestamp>V||n(o)||(!r||o.timestamp>r.timestamp)&&(r=o);if(r)return r;let s;for(let o of Array.from(this.cachedWinningBids.values()))t-o.timestamp>V||(!s||o.timestamp>s.timestamp)&&(s=o);return s}addImpressionKey(e){if(!this.slotEmittedImpressionKeys.has(e)){for(;this.slotEmittedImpressionKeys.size>=Lt;){let t=this.slotEmittedImpressionKeys.values().next();if(t.done)break;this.slotEmittedImpressionKeys.delete(t.value)}this.slotEmittedImpressionKeys.add(e)}}getOrCreateAuctionOutcomes(e){let t=this.auctionBidderOutcomes.get(e);for(t||(t=new Map,this.auctionBidderOutcomes.set(e,t));this.auctionBidderOutcomes.size>St;){let n=this.auctionBidderOutcomes.keys().next();if(n.done||n.value===e)break;this.auctionBidderOutcomes.delete(n.value)}return t}hasImpressionEmitted(e,t,n,r){let s=t??this.slotRefreshIndices.get(e)??0,o=`${h(e)}:${s}`;return r?n?this.slotEmittedImpressionKeys.has(`${o}:auc:${h(n)}:${h(r)}`)||this.slotEmittedImpressionKeys.has(`${o}:${h(r)}`):this.slotEmittedImpressionKeys.has(`${o}:${h(r)}`):n?this.slotEmittedImpressionKeys.has(`${o}:auc:${h(n)}`):this.slotEmittedImpressionKeys.has(o)}markImpressionEmitted(e,t,n,r){let s=`${h(e)}:${t}`;this.addImpressionKey(s),r&&this.addImpressionKey(`${s}:${h(r)}`),n&&(this.addImpressionKey(`${s}:auc:${h(n)}`),r&&this.addImpressionKey(`${s}:auc:${h(n)}:${h(r)}`))}recordImpression(e,t){if(!this.isEnabled)return!1;let n=e||t?.adUnitCode||"",r=t?.adUnitCode||n,s=(t?.auctionId&&n?this.getCachedBid(`${t.auctionId}:${n}`):void 0)||(t?.auctionId&&r?this.getCachedBid(`${t.auctionId}:${r}`):void 0)||(n?this.getCachedBid(n):void 0)||(r?this.getCachedBid(r):void 0),o=t?.bid||s?.rawBid||{},d=t?.auctionId||o.auctionId||s?.auctionId||"",a=t?.transactionId||o.transactionId||s?.transactionId||"",c=o.creativeId||s?.bidTrace?.creativeId||t?.bid?.creativeId||"",u=t?.mediaType||o.mediaType||s?.bidTrace?.mediaType||"banner",g=n||r,f=(n?this.slotViewabilityRecords.get(n):void 0)||(r?this.slotViewabilityRecords.get(r):void 0),I=g?this.slotLastAuctionIds.get(g)||(f?f.auctionId:void 0):void 0,R=!!(g&&d&&I&&I!==d&&t?.refreshIndex===void 0),y={bidder:o.bidderCode||o.bidder||s?.bidTrace?.bidder||"",cpm:Number.isFinite(o.originalCpm)?o.originalCpm:Number.isFinite(o.cpm)?o.cpm:s?.bidTrace?.cpm??0,currency:o.originalCurrency??o.currency??s?.bidTrace?.currency??"USD",...N(o).width?N(o):s?.bidTrace?{width:s.bidTrace.width,height:s.bidTrace.height}:N(o),dealId:o.dealId||s?.bidTrace?.dealId||"",mediaType:u,latencyMs:Number.isFinite(o.timeToRespond)?o.timeToRespond:s?.bidTrace?.latencyMs??0,advertiserDomain:o.meta?.advertiserDomains?.[0]||s?.bidTrace?.advertiserDomain||"",creativeId:o.creativeId||s?.bidTrace?.creativeId||""};if(R&&g){this.flushSlotTimeInView(g);let w=(this.slotRefreshIndices.get(g)??(f?f.refreshIndex:0))+1;this.slotRefreshIndices.set(g,w),this.slotLastAuctionIds.set(g,d),f&&(f.refreshIndex=w,f.auctionId=d,f.transactionId=a,f.bidPayload=y,f.viewableFired=!1,f.accumulatedTimeInViewMs=0),this.enqueue(b.REFRESH,"refresh",{auctionId:d,transactionId:a,adUnitCode:g,bid:y,metadata:{...t?.metadata,refresh_index:String(w)}})}else g&&(d&&this.slotLastAuctionIds.set(g,d),this.slotRefreshIndices.has(g)||this.slotRefreshIndices.set(g,0));let T=t?.refreshIndex??(n?this.slotRefreshIndices.get(n)??(r?this.slotRefreshIndices.get(r):void 0)??(f?f.refreshIndex:0):0);return n&&this.hasImpressionEmitted(n,T,d,c)||r&&r!==n&&this.hasImpressionEmitted(r,T,d,c)?(this.log("DEBUG",`Impression already emitted for slot ${n||r} in cycle ${T}`),!1):(n&&this.markImpressionEmitted(n,T,d,c),r&&r!==n&&this.markImpressionEmitted(r,T,d,c),this.enqueue(b.IMPRESSION,"impression",{auctionId:d,transactionId:a,adUnitCode:r,bid:y,metadata:{...t?.metadata,refresh_index:String(T)}}),f&&(!f.bidPayload&&y&&(f.bidPayload=y),!f.auctionId&&d&&(f.auctionId=d),!f.transactionId&&a&&(f.transactionId=a)),!0)}attachImaAdsManager(e,t){if(!e||typeof e.addEventListener!="function")return this.log("WARN","Invalid AdsManager passed to attachImaAdsManager"),()=>{};if(!e.__bidkernelAttachedInstances)try{Object.defineProperty(e,"__bidkernelAttachedInstances",{value:new Map,configurable:!0,writable:!0})}catch{e.__bidkernelAttachedInstances=new Map}let n=e.__bidkernelAttachedInstances,r=n.get(this);if(r){if(!t)return()=>{};r()}let s=t?.slotId||t?.adUnitCode||"video",o=t?.adUnitCode||s,d=t?.auctionId||"",a=t?.transactionId||"",c=p=>{let l=(d?this.getCachedBid(`${d}:${o}`):void 0)||(d&&s!==o?this.getCachedBid(`${d}:${s}`):void 0)||(o!=="video"?this.getCachedBid(o):void 0)||(s!==o&&s!=="video"?this.getCachedBid(s):void 0);return l||(l=this.findCachedWinningBid({creativeId:p?.creativeId,adId:p?.adId,mediaType:"video"})),l},u=!1,g=p=>{u=!0,this.log("DEBUG","IMA AdEvent.STARTED / IMPRESSION received",p);let l=typeof p?.getAd=="function"?p.getAd():p?.ad,v={};l&&(v.creativeId=(typeof l.getCreativeId=="function"?l.getCreativeId():l.creativeId)||"",v.adId=(typeof l.getAdId=="function"?l.getAdId():l.id)||"",v.title=(typeof l.getTitle=="function"?l.getTitle():l.title)||"",v.duration=typeof l.getDuration=="function"?l.getDuration():l.duration,v.advertiserName=typeof l.getAdvertiserName=="function"?l.getAdvertiserName():"");let _=c(v),C=t?.slotId&&t.slotId!=="video"?t.slotId:t?.adUnitCode&&t.adUnitCode!=="video"?t.adUnitCode:_?.adUnitCode||t?.slotId||t?.adUnitCode||"video",ie=t?.adUnitCode&&t.adUnitCode!=="video"?t.adUnitCode:_?.adUnitCode||C,ne=d||_?.auctionId||"",it=a||_?.transactionId||"",we={..._?.rawBid||t?.bid,mediaType:"video",creativeId:v.creativeId||_?.bidTrace?.creativeId||t?.bid?.creativeId||""};if(this.recordImpression(C,{adUnitCode:ie,auctionId:ne,transactionId:it,mediaType:"video",bid:we,metadata:{...t?.metadata,media_type:"video",...v.title?{ad_title:v.title}:{},...Number.isFinite(v.duration)?{ad_duration_s:String(v.duration)}:{}}})&&t?.onImpression)try{t.onImpression(C,{ad:l,bid:we})}catch(nt){this.log("ERROR","Error in onImpression callback",nt)}},f=p=>{if(this.log("DEBUG",`IMA AdEvent milestone: ${p}`),t?.onMilestone)try{t.onMilestone(p,s)}catch(l){this.log("ERROR","Error in onMilestone callback",l)}},I=p=>{this.log("DEBUG","IMA AdEvent.CLICK received",p);let l=c(),v=t?.adUnitCode&&t.adUnitCode!=="video"?t.adUnitCode:l?.adUnitCode||s;this.enqueue(b.CLICK,"click",{auctionId:d||l?.auctionId,transactionId:a||l?.transactionId,adUnitCode:v,bid:l?.bidTrace||t?.bid,metadata:{...t?.metadata,media_type:"video"}})},R=p=>{this.log("WARN","IMA AdErrorEvent received",p);let l=typeof p?.getError=="function"?p.getError():p?.error||p,v=(l&&typeof l.getMessage=="function"?l.getMessage():l?.message)||String(l||"IMA ad error"),_=(l&&typeof l.getErrorCode=="function"?l.getErrorCode():l?.code)||"",C=c(),ie=t?.adUnitCode&&t.adUnitCode!=="video"?t.adUnitCode:C?.adUnitCode||s;if(this.enqueue(b.AD_RENDER_FAILED,"adRenderFailed",{auctionId:d||C?.auctionId,transactionId:a||C?.transactionId,adUnitCode:ie,bid:C?.bidTrace||t?.bid,metadata:{...t?.metadata,reason:u?"ima_playback_error":"ima_ad_error",playback_phase:u?"post_start":"pre_start",message:v,..._?{ima_error_code:String(_)}:{}},error:typeof l=="object"?l:new Error(v)}),t?.onError)try{t.onError(l)}catch(ne){this.log("ERROR","Error in onError callback",ne)}},y=typeof window<"u"?window.google?.ima:void 0,T=y?.AdEvent?.Type||{},$=y?.AdErrorEvent?.Type||{},w=[{type:T.STARTED||"started",handler:g},{type:T.IMPRESSION||"impression",handler:g},{type:T.FIRST_QUARTILE||"firstQuartile",handler:()=>f("firstQuartile")},{type:T.MIDPOINT||"midpoint",handler:()=>f("midpoint")},{type:T.THIRD_QUARTILE||"thirdQuartile",handler:()=>f("thirdQuartile")},{type:T.COMPLETE||"complete",handler:()=>f("complete")},{type:T.CLICK||"click",handler:I},{type:$.AD_ERROR||"adError",handler:R}],E=new Set,B=[];for(let p of w)E.has(p.type)||(E.add(p.type),B.push(p));for(let{type:p,handler:l}of B)try{e.addEventListener(p,l)}catch{}let m=()=>{n.delete(this);for(let{type:p,handler:l}of B)try{e.removeEventListener(p,l)}catch{}this.videoDetachCleanups.delete(m)};return n.set(this,m),this.videoDetachCleanups.add(m),m}attachVideoPlayer(e,t){if(!e)return this.log("WARN","attachVideoPlayer called with null/undefined target"),()=>{};let n=null;if(typeof e=="string"){if(typeof document<"u")try{n=document.querySelector(e)||document.getElementById(e)}catch{n=document.getElementById(e)}}else if(typeof HTMLElement<"u"&&e instanceof HTMLElement)n=e;else if(e&&typeof e=="object"&&e.nodeType===1)n=e;else{if(typeof e.addEventListener=="function"&&(typeof e.init=="function"||typeof e.start=="function"||typeof e.getCuePoints=="function"||typeof e.getVolume=="function"||e.__imaAdsManager))return this.attachImaAdsManager(e,t);e&&typeof e.addEventListener=="function"&&(n=e)}let r=t?.slotId||t?.adUnitCode||(n?n.id:"")||"video",s=t?.adUnitCode||r,o=t?.auctionId||"",d=t?.transactionId||"",a=()=>(o?this.getCachedBid(`${o}:${s}`):void 0)||(o&&r!==s?this.getCachedBid(`${o}:${r}`):void 0)||this.getCachedBid(s)||(r!==s?this.getCachedBid(r):void 0),c=null;n&&(n.tagName&&n.tagName.toLowerCase()==="video"?c=n:c=n.querySelector("video"));let u={q1:!1,q2:!1,q3:!1,q4:!1},g=m=>{let p=m||c||(n?.querySelector?n.querySelector("video"):null),l=a(),v={...l?.rawBid||t?.bid,mediaType:"video"};if(this.recordImpression(r,{adUnitCode:s,auctionId:o||l?.auctionId,transactionId:d||l?.transactionId,mediaType:"video",bid:v,metadata:{...t?.metadata,media_type:"video",...p&&Number.isFinite(p.duration)?{video_duration_s:String(Math.round(p.duration))}:{}}})&&t?.onImpression)try{t.onImpression(r,{element:p||n,bid:v})}catch(C){this.log("ERROR","Error in onImpression callback",C)}},f=m=>{this.log("DEBUG","HTML5 video playing event received");let p=m?.target instanceof HTMLVideoElement?m.target:c;g(p)},I=m=>{let p=m?.target instanceof HTMLVideoElement?m.target:c;if(p&&p.currentTime>0&&(g(p),Number.isFinite(p.duration)&&p.duration>0)){let l=p.currentTime/p.duration;l>=.25&&!u.q1&&(u.q1=!0,t?.onMilestone?.("firstQuartile",r)),l>=.5&&!u.q2&&(u.q2=!0,t?.onMilestone?.("midpoint",r)),l>=.75&&!u.q3&&(u.q3=!0,t?.onMilestone?.("thirdQuartile",r))}},R=()=>{u.q4||(u.q4=!0,t?.onMilestone?.("complete",r))},y=m=>{let l=(m?.target instanceof HTMLVideoElement?m.target:c)?.error||c?.error,v=a(),_=l?`HTML5 video error code ${l.code}: ${l.message}`:"Video playback error";if(this.log("WARN",_),this.enqueue(b.AD_RENDER_FAILED,"adRenderFailed",{auctionId:o||v?.auctionId,transactionId:d||v?.transactionId,adUnitCode:s,bid:v?.bidTrace||t?.bid,metadata:{...t?.metadata,reason:"html5_video_error",message:_,...l?.code?{video_error_code:String(l.code)}:{}},error:l?new Error(_):void 0}),t?.onError)try{t.onError(l)}catch(C){this.log("ERROR","Error in onError callback",C)}},T=m=>{m.addEventListener("playing",f),m.addEventListener("play",f),m.addEventListener("timeupdate",I),m.addEventListener("ended",R),m.addEventListener("error",y)},$=m=>{m.removeEventListener("playing",f),m.removeEventListener("play",f),m.removeEventListener("timeupdate",I),m.removeEventListener("ended",R),m.removeEventListener("error",y)},w=null;n&&n!==c&&(n.addEventListener("playing",f,!0),n.addEventListener("play",f,!0),n.addEventListener("timeupdate",I,!0),n.addEventListener("ended",R,!0),n.addEventListener("error",y,!0)),c&&T(c),n&&n.tagName?.toLowerCase()!=="video"&&typeof MutationObserver<"u"&&(w=new MutationObserver(()=>{let m=n.querySelector("video");m&&m!==c&&(c&&$(c),c=m,c&&T(c))}),w.observe(n,{childList:!0,subtree:!0}));let E=a();t?.trackViewability!==!1&&n&&this.observeSlot(n,r,{adUnitCode:s,auctionId:o||E?.auctionId,transactionId:d||E?.transactionId,mediaType:"video",bid:E?.bidTrace||t?.bid,metadata:t?.metadata,emitRefreshEvent:!1});let B=()=>{w&&(w.disconnect(),w=null),n&&n!==c&&(n.removeEventListener("playing",f,!0),n.removeEventListener("play",f,!0),n.removeEventListener("timeupdate",I,!0),n.removeEventListener("ended",R,!0),n.removeEventListener("error",y,!0)),c&&$(c),this.videoDetachCleanups.delete(B)};return this.videoDetachCleanups.add(B),B}onTimeInViewThreshold(e,t,n){let r={thresholdMs:t,callback:n,timer:null,fired:!1},s=this.slotViewabilityRecords.get(e);if(s){s.thresholdListeners.add(r);let o=this.getCurrentTimeInView(s);if(o>=t){r.fired=!0;try{n(e,o)}catch(d){this.log("ERROR","Error in threshold callback",d)}}else if(s.inView&&(typeof document>"u"||document.visibilityState==="visible")){let d=t-o;r.timer=setTimeout(()=>{if(r.timer=null,!r.fired&&s.inView&&(typeof document>"u"||document.visibilityState==="visible")){let a=this.getCurrentTimeInView(s);if(a>=t){r.fired=!0;try{n(e,a)}catch(c){this.log("ERROR","Error in threshold callback",c)}}}},d)}}else this.pendingThresholdListeners.has(e)||this.pendingThresholdListeners.set(e,new Set),this.pendingThresholdListeners.get(e).add(r);return()=>{r.timer&&(clearTimeout(r.timer),r.timer=null),s&&s.thresholdListeners.delete(r);let o=this.pendingThresholdListeners.get(e);o&&o.delete(r)}}getViewabilityState(e){let t=this.slotViewabilityRecords.get(e);if(!t)return;let n=Math.round(this.getCurrentTimeInView(t));return{inView:t.inView,viewable:t.viewableFired,timeInViewMs:n,refreshIndex:t.refreshIndex}}getEndpoint(){return this.config.endpoint}getRefreshIndex(e){return this.slotRefreshIndices.get(e)??0}triggerSlotRefresh(e,t){let n=this.slotViewabilityRecords.get(e);n&&n.element&&this.observeSlot(n.element,e,t)}trackRawEvent(e,t,n){let r=_t[t]??(e==="ERROR"?b.ERROR:b.TRACE_EVENT_TYPE_UNSPECIFIED);this.enqueue(r,t,n,e)}setUserId(e){this.config.userId=e}setSessionId(e){this.config.sessionId=e}navigate(e,t){if(this.disable(),this.slotRefreshIndices.clear(),this.pendingThresholdListeners.clear(),this.config.pageviewId=e||W(),t)try{let n=new URL(t);this.pageUrl=n.origin+n.pathname}catch{this.pageUrl=t}else this.pageUrl="";this.logger.resetTiming(),Xe(),this.enable()}handleAuctionInit(e){if(this.isDuplicate("auctionInit",e))return;this.log("DEBUG","auctionInit",e);let t=e.auctionId||"";t&&(this.auctionBidderOutcomes.delete(t),this.getOrCreateAuctionOutcomes(t)),this.enqueue(b.AUCTION_START,"auctionStart",{auctionId:t,transactionId:e.transactionId||""})}handleAuctionEnd(e){if(this.isDuplicate("auctionEnd",e))return;this.log("DEBUG","auctionEnd",e);let t=e.auctionId||"",n=t?this.auctionBidderOutcomes.get(t):void 0,r=n?Array.from(n.values()):[];t&&this.auctionBidderOutcomes.delete(t),this.enqueue(b.AUCTION_END,"auctionEnd",{auctionId:t,transactionId:e.transactionId||"",bidderOutcomes:r})}handleBidRequested(e){if(this.isDuplicate("bidRequested",e))return;this.log("DEBUG","bidRequested",e);let t=e.auctionId||"",n=e.bidderCode||e.bidder||"";if(!t||!n)return;let r=this.getOrCreateAuctionOutcomes(t);Array.isArray(e.bids)&&e.bids.forEach(s=>{let o=s.adUnitCode||"",d=Object.keys(s.mediaTypes||{}),a=d.length>0?d[0]:s.mediaType||"banner",c=`${n}:${o}`;r.has(c)||r.set(c,{bidder:n,adUnitCode:o,mediaType:a,outcome:D.BIDDER_OUTCOME_NO_RESPONSE,latencyMs:0})})}handleBidResponse(e){if(this.isDuplicate("bidResponse",e))return;this.log("DEBUG","bidResponse",e);let t=e.auctionId||"",n=e.bidderCode||e.bidder||"",r=e.adUnitCode||"",s=Number.isFinite(e.originalCpm)?e.originalCpm:Number.isFinite(e.cpm)?e.cpm:0,o=Number.isFinite(e.timeToRespond)?e.timeToRespond:0,d=Object.keys(e.mediaTypes||{}),a=e.mediaType||(e.mediaTypes?.video?"video":d.length>0?d[0]:"banner");if(t&&n){let c=this.getOrCreateAuctionOutcomes(t),u=`${n}:${r}`,g=c.get(u),f=s>0?D.BIDDER_OUTCOME_BID:D.BIDDER_OUTCOME_NO_BID;g?(g.outcome=f,g.latencyMs=o,a&&(g.mediaType=a)):c.set(u,{bidder:n,adUnitCode:r,mediaType:a,outcome:f,latencyMs:o})}s>0&&this.enqueue(b.BID_RESPONSE,"bidResponse",{auctionId:t,transactionId:e.transactionId||"",adUnitCode:r,bid:{bidder:n,cpm:s,currency:e.originalCurrency??e.currency??"USD",...N(e),dealId:e.dealId||"",mediaType:a,latencyMs:o,advertiserDomain:e.meta?.advertiserDomains?.[0]||"",creativeId:e.creativeId||""}})}handleBidTimeout(e){if(this.isDuplicate("bidTimeout",e))return;this.log("DEBUG","bidTimeout",e);let t=Array.isArray(e)?e:e?[e]:[];for(let n of t){let r=n.auctionId||"",s=n.bidderCode||n.bidder||"",o=n.adUnitCode||"",d=Number.isFinite(n.timeout)?n.timeout:0;if(r&&s){let a=this.getOrCreateAuctionOutcomes(r),c=`${s}:${o}`,u=a.get(c);u?(u.outcome=D.BIDDER_OUTCOME_TIMEOUT,d>0&&(u.latencyMs=d)):a.set(c,{bidder:s,adUnitCode:o,mediaType:"banner",outcome:D.BIDDER_OUTCOME_TIMEOUT,latencyMs:d})}}}handleBidWon(e){if(this.isDuplicate("bidWon",e))return;this.log("DEBUG","bidWon",e);let t=e.auctionId||"",n=e.transactionId||"",r=e.adUnitCode||e.adId||"",s=Object.keys(e.mediaTypes||{}),o=e.mediaType||(e.mediaTypes?.video?"video":s.length>0?s[0]:"banner"),d={bidder:e.bidderCode||e.bidder||"",cpm:Number.isFinite(e.originalCpm)?e.originalCpm:Number.isFinite(e.cpm)?e.cpm:0,currency:e.originalCurrency??e.currency??"USD",...N(e),dealId:e.dealId||"",mediaType:o,latencyMs:Number.isFinite(e.timeToRespond)?e.timeToRespond:0,advertiserDomain:e.meta?.advertiserDomains?.[0]||"",creativeId:e.creativeId||""};if(r){let a={bidTrace:d,auctionId:t,transactionId:n,adUnitCode:r,rawBid:e,timestamp:Date.now()};this.cachedWinningBids.set(r,a),e.adId&&e.adId!==r&&this.cachedWinningBids.set(e.adId,a),t&&(this.cachedWinningBids.set(`${t}:${r}`,a),e.adId&&e.adId!==r&&this.cachedWinningBids.set(`${t}:${e.adId}`,a)),this.pruneCachedWinningBids()}this.enqueue(b.BID_WIN,"bidWon",{auctionId:t,transactionId:n,adUnitCode:r,bid:d})}handleNoBid(e){if(this.isDuplicate("noBid",e))return;this.log("DEBUG","noBid",e);let t=e.auctionId||"",n=e.bidderCode||e.bidder||"",r=e.adUnitCode||"";if(t&&n){let s=this.getOrCreateAuctionOutcomes(t),o=`${n}:${r}`,d=s.get(o);d?d.outcome===D.BIDDER_OUTCOME_NO_RESPONSE&&(d.outcome=D.BIDDER_OUTCOME_NO_BID):s.set(o,{bidder:n,adUnitCode:r,mediaType:"banner",outcome:D.BIDDER_OUTCOME_NO_BID,latencyMs:0})}}handleAdRenderFailed(e){if(this.isDuplicate("adRenderFailed",e))return;this.log("DEBUG","adRenderFailed",e);let t=e.bid||{};this.enqueue(b.AD_RENDER_FAILED,"adRenderFailed",{auctionId:t.auctionId||e.auctionId||"",transactionId:t.transactionId||e.transactionId||"",adUnitCode:t.adUnitCode||e.adUnitCode||"",bid:{bidder:t.bidderCode||t.bidder||e.bidderCode||e.bidder||""},metadata:{reason:String(e.reason||""),message:String(e.message||e.error?.message||"")},error:e.error||(e.message?new Error(String(e.message)):void 0)})}handleAdRenderSucceeded(e){if(this.isDuplicate("adRenderSucceeded",e))return;this.log("DEBUG","adRenderSucceeded",e);let t=e.bid||e||{},n=e.adUnitCode||t.adUnitCode||e.adId||t.adId||"",r=t.auctionId||e.auctionId||"",s=t.transactionId||e.transactionId||"",o=t.mediaType||"banner",d=e.adUnitCode||t.adUnitCode||"",a=e.adId||t.adId||"",c=(r&&d?this.getCachedBid(`${r}:${d}`):void 0)||(r&&a?this.getCachedBid(`${r}:${a}`):void 0)||(d?this.getCachedBid(d):void 0)||(a?this.getCachedBid(a):void 0),u=o==="video"||t.mediaType==="video"||t.mediaTypes?.video!==void 0||c?.bidTrace?.mediaType==="video"||c?.rawBid?.mediaType==="video"||n&&this.slotViewabilityRecords.get(n)?.mediaType==="video",g=u?"video":o||c?.bidTrace?.mediaType||"banner",f={bidder:t.bidderCode||t.bidder||c?.bidTrace?.bidder||"",cpm:Number.isFinite(t.originalCpm)?t.originalCpm:Number.isFinite(t.cpm)?t.cpm:c?.bidTrace?.cpm??0,currency:t.originalCurrency??t.currency??c?.bidTrace?.currency??"USD",...N(t).width?N(t):c?.bidTrace?{width:c.bidTrace.width,height:c.bidTrace.height}:N(t),dealId:t.dealId||c?.bidTrace?.dealId||"",mediaType:g,latencyMs:Number.isFinite(t.timeToRespond)?t.timeToRespond:c?.bidTrace?.latencyMs??0,advertiserDomain:t.meta?.advertiserDomains?.[0]||c?.bidTrace?.advertiserDomain||"",creativeId:t.creativeId||c?.bidTrace?.creativeId||""},I=r||c?.auctionId||"",R=s||c?.transactionId||"",y=n?this.slotViewabilityRecords.get(n):void 0,T=y&&I&&y.auctionId&&y.auctionId!==I;if(!!(n&&y&&T)){this.flushSlotTimeInView(n);let E=(this.slotRefreshIndices.get(n)??(y?y.refreshIndex:0))+1;this.slotRefreshIndices.set(n,E),this.slotLastAuctionIds.set(n,I),y&&(y.refreshIndex=E,y.auctionId=I,y.transactionId=R,y.bidPayload=f,y.viewableFired=!1,y.accumulatedTimeInViewMs=0),this.enqueue(b.REFRESH,"refresh",{auctionId:I,transactionId:R,adUnitCode:n,bid:f,metadata:{refresh_index:String(E)}})}else n&&(I&&this.slotLastAuctionIds.set(n,I),this.slotRefreshIndices.has(n)||this.slotRefreshIndices.set(n,0));let w=n?this.slotRefreshIndices.get(n)??(y?y.refreshIndex:0):0;if(u?this.log("DEBUG",`adRenderSucceeded received for video ad unit ${n||"unknown"}: suppressing IMPRESSION until verified video lifecycle event`):n&&this.hasImpressionEmitted(n,w,I,f.creativeId)||(n&&this.markImpressionEmitted(n,w,I,f.creativeId),this.enqueue(b.IMPRESSION,"impression",{auctionId:I,transactionId:R,adUnitCode:n,bid:f,metadata:{refresh_index:String(w)}})),this.config.viewabilityEnabled&&typeof document<"u"){let E=n&&this.slotElements.get(n)||null,B=n||e.adId||t.adId;if(!E&&B&&(E=document.getElementById(B)),!E&&typeof window<"u"&&window.googletag?.pubads)try{let m=window.googletag.pubads().getSlots();for(let p of m)if((p.getAdUnitPath?.()===n||p.getSlotElementId?.()===n)&&(E=document.getElementById(p.getSlotElementId()),E))break}catch{}if(!E&&B)try{for(let m of Array.from(document.querySelectorAll("[data-ad-slot]")))if(m.getAttribute("data-ad-slot")===B){E=m;break}}catch{}E&&this.observeSlot(E,n||B,{adUnitCode:n,auctionId:I,transactionId:R,mediaType:g,bid:f,refreshIndex:w,emitRefreshEvent:!1})}}isDuplicate(e,t){return this.deduper.isDuplicate(e,t)}enqueue(e,t,n,r){if(!this.isEnabled||!this.shouldSample(e,r))return;Xe();let s={eventId:W(),timestampMs:Date.now(),type:e,eventName:t,auctionId:n.auctionId||"",transactionId:n.transactionId||"",adUnitCode:n.adUnitCode||n.elementId||"",namespace:n.ns||n.namespace||""};n.bid&&(s.bid={bidder:n.bid.bidder||"",cpm:Number.isFinite(n.bid.cpm)?n.bid.cpm:0,currency:n.bid.currency||"",width:Number.isFinite(n.bid.width)?n.bid.width:0,height:Number.isFinite(n.bid.height)?n.bid.height:0,dealId:n.bid.dealId||"",mediaType:n.bid.mediaType||"",latencyMs:Number.isFinite(n.bid.latencyMs)?n.bid.latencyMs:0,advertiserDomain:n.bid.advertiserDomain||"",creativeId:n.bid.creativeId||""}),n.viewableDurationMs!==void 0&&(s.viewableDurationMs=Number.isFinite(n.viewableDurationMs)?n.viewableDurationMs:0),n.bidderOutcomes&&Array.isArray(n.bidderOutcomes)&&(s.bidderOutcomes=n.bidderOutcomes);let o={...n.metadata};n.error!==void 0&&n.error!==null&&(o.error=typeof n.error=="object"&&n.error.message?String(n.error.message):String(n.error)),n.gpid&&(o.gpid=String(n.gpid)),n.refreshIndex!==void 0&&o.refresh_index===void 0&&(o.refresh_index=String(n.refreshIndex));let d=Ut(o);Object.keys(d).length>0&&(s.metadata=d),this.queue.push(s),this.queue.length>J&&this.queue.splice(0,this.queue.length-J),this.queue.length>=bt?this.flush():xt.has(e)&&this.revenueFlushTimer===null&&(this.revenueFlushTimer=setTimeout(()=>{this.revenueFlushTimer=null,this.flush()},this.config.revenueFlushDelayMs))}shouldSample(e,t){return e===b.ERROR?(this.errorCount++,this.errorCount>It?!1:this.config.errorsEnabled):t==="WARN"?this.config.warningsEnabled:this.config.auctionEnabled}requeue(e){e.length&&(this.queue=e.concat(this.queue),this.queue.length>J&&this.queue.splice(0,this.queue.length-J))}drainBatch(){if(this.queue.length===0||!this.config.endpoint)return null;let e=typeof window<"u"?window.location.hostname:"",t=n=>({propertyId:this.config.propertyId,pageviewId:this.config.pageviewId,sessionId:this.config.sessionId,pageUrl:this.pageUrl,country:this.config.country,region:this.config.region,deviceType:this.config.deviceType,userId:this.config.userId,domain:e,events:n});for(;;){if(this.queue.length===0)return null;let n=this.queue,r=Z.encode(t(n)).finish();for(;n.length>1&&r.byteLength>ge;)n=n.slice(0,Math.floor(n.length/2)),r=Z.encode(t(n)).finish();if(r.byteLength>ge){let[s]=this.queue.splice(0,1);this.log("WARN",`Dropping oversized event ${s?.eventName||s?.eventId} (${r.byteLength} bytes exceeds the ${ge}-byte cap on its own)`);continue}return this.queue=this.queue.slice(n.length),{url:`${this.config.endpoint}/${this.config.propertyId}`,encoded:r,events:n}}}sendFetch(e,t=!1,n,r=!1){let s={method:"POST",headers:{"Content-Type":ze},body:e.encoded};t&&(s.keepalive=!0),fetch(e.url,s).then(d=>{if(d.ok)r||(this.consecutiveSendFailures=0,this.nextSendAllowedAt=0),n&&n();else{if(this.log("WARN",`Failed to send batch: HTTP ${d.status}`),d.status>=400&&d.status<500&&d.status!==429&&d.status!==408){this.log("WARN",`Dropping batch due to non-retryable client error HTTP ${d.status}`);return}r||this.handleSendFailure(e.events)}}).catch(d=>{this.log("ERROR","Failed to send batch",d),r||this.handleSendFailure(e.events)});let o=typeof globalThis<"u"?globalThis.process:void 0;if(o&&typeof o._tickCallback=="function")try{o._tickCallback()}catch{}}handleSendFailure(e){this.consecutiveSendFailures++;let t=Math.min(Ge*2**(this.consecutiveSendFailures-1),vt);this.nextSendAllowedAt=Date.now()+t,this.consecutiveSendFailures<=Et?this.requeue(e):this.log("WARN",`Dropping ${e.length} events after ${this.consecutiveSendFailures} consecutive send failures`)}flush(){if(Date.now()<this.nextSendAllowedAt)return;let e=this.drainBatch();for(;e&&(this.sendFetch(e,!1),!(Date.now()<this.nextSendAllowedAt));)e=this.drainBatch()}flushBeacon(){let e=this.drainBatch();for(;e;){let t=!1;if(typeof navigator<"u"&&typeof navigator.sendBeacon=="function")try{let n=new Blob([e.encoded],{type:ze});t=navigator.sendBeacon(e.url,n)}catch{t=!1}if(!t){let n=this.persistBatch(e.encoded);this.sendFetch(e,!0,()=>this.removePersistedBatch(n))}e=this.drainBatch()}this.schedulePersistedCleanup()}pendingKeyPrefix(){return`${ee}${encodeURIComponent(this.config.propertyId)}_`}persistBatch(e){if(!G)return null;try{if(typeof localStorage>"u"||!this.config.propertyId)return null;let t=0;for(let r=0;r<localStorage.length;r++){let s=localStorage.key(r);s&&s.startsWith(ee)&&t++}if(t>=wt)return null;let n=`${this.pendingKeyPrefix()}${Date.now()}_${Math.floor(Math.random()*1e6)}`;return localStorage.setItem(n,Mt(e)),this.persistedBatchKeys.push(n),n}catch{return null}}removePersistedBatch(e){if(!e)return;try{typeof localStorage<"u"&&localStorage.removeItem(e)}catch{}let t=this.persistedBatchKeys.indexOf(e);t!==-1&&this.persistedBatchKeys.splice(t,1)}schedulePersistedCleanup(){this.persistedBatchKeys.length!==0&&(this.persistedCleanupTimer&&clearTimeout(this.persistedCleanupTimer),this.persistedCleanupTimer=setTimeout(()=>{this.persistedCleanupTimer=null;for(let e of Array.from(this.persistedBatchKeys))this.removePersistedBatch(e)},Rt))}resendPersistedBatches(){try{if(typeof localStorage>"u"||!this.config.endpoint||!this.config.propertyId)return;let e=this.pendingKeyPrefix(),t=[],n=[];for(let r=0;r<localStorage.length;r++){let s=localStorage.key(r);!s||!s.startsWith(ee)||(s.startsWith(e)?t.push(s):Pt(s)&&n.push(s))}for(let r of n)try{localStorage.removeItem(r)}catch{}for(let r of t){let s=null;try{s=localStorage.getItem(r),localStorage.removeItem(r)}catch{continue}if(!s)continue;let o=parseInt(r.slice(e.length),10);if(!Number.isFinite(o)||Date.now()-o>At)continue;let d;try{d=kt(s)}catch{continue}d.byteLength!==0&&(this.log("DEBUG",`Resending persisted exit batch (${d.byteLength} bytes)`),this.sendFetch({url:`${this.config.endpoint}/${this.config.propertyId}`,encoded:d,events:[]},!1,void 0,!0))}}catch{}}log(e,t,...n){this.logger.log(e,t,...n)}},Ie=se({prefix:"[bidkernel]",logLevel:"INFO"})});var qt=rt(()=>{et();var tt="https://by.bidkernel.io/t",Wt=window._bidkernelPbjsGlobal||"pbjs";Te(Wt,{endpoint:tt});window.bidkernelPrebidAnalytics={...window.bidkernelPrebidAnalytics,register:(i,e)=>Te(i,{endpoint:tt,...e}),attachVideoPlayer:(i,e)=>{let t=window._bidkernelPrebidAnalytics;return t?.attachVideoPlayer?t.attachVideoPlayer(i,e):()=>{}},attachImaAdsManager:(i,e)=>{let t=window._bidkernelPrebidAnalytics;return t?.attachImaAdsManager?t.attachImaAdsManager(i,e):()=>{}},recordImpression:(i,e)=>{let t=window._bidkernelPrebidAnalytics;return t?.recordImpression?t.recordImpression(i,e):!1}}});return qt();})();
|
package/dist/index.d.mts
CHANGED
|
@@ -54,11 +54,24 @@ interface AnalyticsConfig {
|
|
|
54
54
|
errorsEnabled?: boolean;
|
|
55
55
|
/** Whether to enable client-side IAB viewability and time-in-view measurement. Defaults to true. */
|
|
56
56
|
viewabilityEnabled?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Whether identifiers may be written to localStorage (session id and its
|
|
59
|
+
* timestamp, exit batches). Defaults to true. Set false until storage
|
|
60
|
+
* consent is known, then flip with setStorageAllowed(true); events are
|
|
61
|
+
* always collected and sent regardless.
|
|
62
|
+
*/
|
|
63
|
+
storageAllowed?: boolean;
|
|
57
64
|
logLevel?: "DEBUG" | "INFO" | "WARN" | "ERROR";
|
|
58
65
|
/** Window global holding the Prebid instance to attach to. Defaults to "pbjs". */
|
|
59
66
|
pbjsGlobalName?: string;
|
|
60
67
|
/** Whether to attach pbjs.onEvent listeners. Defaults to true. Set false for full SDK mode. */
|
|
61
68
|
attachPbjsListeners?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Milliseconds a batch holding a revenue event (impression, win, click)
|
|
71
|
+
* waits before it is sent, so the events of one render cycle share a POST.
|
|
72
|
+
* 0 sends on the next tick. Defaults to 3000.
|
|
73
|
+
*/
|
|
74
|
+
revenueFlushDelayMs?: number;
|
|
62
75
|
}
|
|
63
76
|
interface SlotObserveOptions {
|
|
64
77
|
adUnitCode?: string;
|
|
@@ -117,6 +130,15 @@ interface SlotViewabilityState {
|
|
|
117
130
|
* registerPrebidAnalytics.
|
|
118
131
|
*/
|
|
119
132
|
declare function isTrustedEndpoint(raw: string): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* The visitor's session id: a 30-minute rolling session persisted in
|
|
135
|
+
* localStorage when storage is allowed, kept in memory otherwise. A session
|
|
136
|
+
* begun in memory (before storage consent) is adopted and persisted the
|
|
137
|
+
* first time this runs with storage allowed, so consent never splits a
|
|
138
|
+
* session. Exported so an integration can report the same id the adapter
|
|
139
|
+
* stamps on its batches.
|
|
140
|
+
*/
|
|
141
|
+
declare function getOrCreateSessionId(): string;
|
|
120
142
|
/**
|
|
121
143
|
* Canonical duplicate-detection key for a Prebid event. Shared by the adapter
|
|
122
144
|
* and the diagnostic extension so the two can never drift apart. Covers the
|
|
@@ -143,6 +165,13 @@ declare class BidkernelPrebidAnalytics {
|
|
|
143
165
|
private static activeInstances;
|
|
144
166
|
static getActiveInstances(): Set<BidkernelPrebidAnalytics>;
|
|
145
167
|
static initImaInterception(): void;
|
|
168
|
+
/**
|
|
169
|
+
* Allows or forbids localStorage writes for every instance on the page.
|
|
170
|
+
* Collection and delivery are unaffected: only the persisted session id,
|
|
171
|
+
* its timestamp and exit batches are gated.
|
|
172
|
+
*/
|
|
173
|
+
static setStorageAllowed(allowed: boolean): void;
|
|
174
|
+
static isStorageAllowed(): boolean;
|
|
146
175
|
private config;
|
|
147
176
|
private queue;
|
|
148
177
|
private errorCount;
|
|
@@ -156,7 +185,7 @@ declare class BidkernelPrebidAnalytics {
|
|
|
156
185
|
private consecutiveSendFailures;
|
|
157
186
|
private nextSendAllowedAt;
|
|
158
187
|
private replayedEventCount;
|
|
159
|
-
private
|
|
188
|
+
private revenueFlushTimer;
|
|
160
189
|
private persistedBatchKeys;
|
|
161
190
|
private persistedCleanupTimer;
|
|
162
191
|
private intersectionObserver;
|
|
@@ -165,6 +194,10 @@ declare class BidkernelPrebidAnalytics {
|
|
|
165
194
|
private slotRefreshIndices;
|
|
166
195
|
private slotLastAuctionIds;
|
|
167
196
|
private pendingThresholdListeners;
|
|
197
|
+
private pendingViewableListeners;
|
|
198
|
+
private slotElements;
|
|
199
|
+
private clickDetachCleanups;
|
|
200
|
+
private lastClickAt;
|
|
168
201
|
private slotEmittedImpressionKeys;
|
|
169
202
|
private cachedWinningBids;
|
|
170
203
|
private videoDetachCleanups;
|
|
@@ -172,10 +205,48 @@ declare class BidkernelPrebidAnalytics {
|
|
|
172
205
|
private logger;
|
|
173
206
|
constructor(config: AnalyticsConfig);
|
|
174
207
|
enable(): void;
|
|
208
|
+
/**
|
|
209
|
+
* Binds the Prebid event handlers on the configured global and replays
|
|
210
|
+
* pbjs.getEvents() history. enable() calls this when attachPbjsListeners is
|
|
211
|
+
* true. An integration that loads Prebid lazily constructs the instance with
|
|
212
|
+
* attachPbjsListeners=false and calls this once pbjs exists; disable() (and
|
|
213
|
+
* therefore navigate()) drops the handlers, so call it again after either.
|
|
214
|
+
* Idempotent. Returns true when handlers are bound after the call, false
|
|
215
|
+
* when the instance is disabled or pbjs.onEvent is not available yet.
|
|
216
|
+
*/
|
|
217
|
+
attachPbjs(): boolean;
|
|
175
218
|
disable(): void;
|
|
176
219
|
private handleVisibilityChange;
|
|
177
220
|
private handleIntersection;
|
|
178
221
|
private handleDwellComplete;
|
|
222
|
+
private notifyViewable;
|
|
223
|
+
/**
|
|
224
|
+
* Calls back once per render cycle when the slot has met the IAB viewable
|
|
225
|
+
* standard this adapter measures (immediately if it already has). Works
|
|
226
|
+
* before the slot is observed: the listener waits for observeSlot. Returns
|
|
227
|
+
* an unsubscribe function.
|
|
228
|
+
*/
|
|
229
|
+
/**
|
|
230
|
+
* Names the element to measure for a slot when the creative renders
|
|
231
|
+
* somewhere other than the slot element (a sticky bar, an interstitial).
|
|
232
|
+
* Applies to the current cycle at once and to every later render.
|
|
233
|
+
*/
|
|
234
|
+
setSlotElement(slotId: string, element: HTMLElement): void;
|
|
235
|
+
/**
|
|
236
|
+
* Records a click on the slot's current creative, attributed to the cached
|
|
237
|
+
* winning bid. Repeats within one second are one click. Returns whether a
|
|
238
|
+
* CLICK was recorded.
|
|
239
|
+
*/
|
|
240
|
+
recordClick(slotId: string, options?: {
|
|
241
|
+
metadata?: Record<string, string>;
|
|
242
|
+
}): boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Detects clicks into a cross-origin creative frame: a click inside an
|
|
245
|
+
* iframe moves focus into it and blurs the window. Returns a detach
|
|
246
|
+
* function; every tracker is detached on disable().
|
|
247
|
+
*/
|
|
248
|
+
attachClickTracker(element: HTMLElement, slotId: string): () => void;
|
|
249
|
+
onViewable(slotId: string, callback: (slotId: string) => void): () => void;
|
|
179
250
|
private scheduleThresholdTimers;
|
|
180
251
|
private checkThresholdListeners;
|
|
181
252
|
private getCurrentTimeInView;
|
|
@@ -331,4 +402,4 @@ interface AdsGlobal {
|
|
|
331
402
|
*/
|
|
332
403
|
declare function getbidkernel(alias?: string): AdsGlobal;
|
|
333
404
|
|
|
334
|
-
export { type AdsGlobal, type AnalyticsConfig, BidkernelPrebidAnalytics, type CachedWinningBid, PrebidEventDeduper, type SizeMapping, type SlotConfig, type SlotObserveOptions, type SlotSize, type SlotSizes, type SlotViewabilityState, type VideoPlayerOptions, getPrebidEventKey, getbidkernel, hookImaPrototype, initImaInterception, isTrustedEndpoint, registerPrebidAnalytics };
|
|
405
|
+
export { type AdsGlobal, type AnalyticsConfig, BidkernelPrebidAnalytics, type CachedWinningBid, PrebidEventDeduper, type SizeMapping, type SlotConfig, type SlotObserveOptions, type SlotSize, type SlotSizes, type SlotViewabilityState, type VideoPlayerOptions, getOrCreateSessionId, getPrebidEventKey, getbidkernel, hookImaPrototype, initImaInterception, isTrustedEndpoint, registerPrebidAnalytics };
|