@bidkernel/analytics 0.32.0 → 0.33.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.
@@ -1 +1 @@
1
- "use strict";var bidkernelPrebidAnalyticsBundle=(()=>{var L=(i,e)=>()=>(i&&(e=i(i=0)),e);var Ct=(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 St}function Lt(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 P(i){if(typeof i=="string"){let e=i.toUpperCase();if(e==="DEBUG"||e==="INFO"||e==="WARN"||e==="ERROR")return e}return C.INFO}function ue(i){return new le(i)}var C,xe,$,_t,St,le,De=L(()=>{"use strict";C={DEBUG:"DEBUG",INFO:"INFO",WARN:"WARN",ERROR:"ERROR"},xe={[C.DEBUG]:10,[C.INFO]:20,[C.WARN]:30,[C.ERROR]:40},$={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"},_t=0,St=new Set;le=class i{_prefix;_level;_loadedAt;_now;_console;_customFormatTime;_listeners=new Set;constructor(e={}){this._prefix=e.prefix??"[bidkernel]",this._level=P(e.logLevel??C.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=P(e)}getLevel(){return this._level}setLevel(e){this._level=P(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=P(e);return(xe[t]??20)>=(xe[this._level]??20)}formatTime(e){return this._customFormatTime?this._customFormatTime(e):Lt(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=P(e);if(!this.isEnabled(r))return;let o=this._getElapsed(),s=this.formatTime(o),d=Date.now(),u={id:`bk_log_${d}_${++_t}`,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(u);let c=this._getConsole();if(!c)return;let I=$.badge,g=$.event;r===C.WARN?(I=$.badgeWarn,g=$.eventWarn):r===C.ERROR&&(I=$.badgeError,g=$.eventError);let f=`%c${this._prefix}%c ${s} %c${t}%c`,R=[I,$.dim,g,$.reset],y=[f,...R];switch(n.length>0&&y.push(...n),r){case C.DEBUG:typeof c.log=="function"?c.log(...y):typeof c.debug=="function"&&c.debug(...y);break;case C.INFO:typeof c.info=="function"?c.info(...y):typeof c.log=="function"&&c.log(...y);break;case C.WARN:typeof c.warn=="function"?c.warn(...y):typeof c.log=="function"&&c.log(...y);break;case C.ERROR:typeof c.error=="function"?c.error(...y):typeof c.log=="function"&&c.log(...y);break;default:typeof c.log=="function"&&c.log(...y);break}}debug(e,...t){this.log(C.DEBUG,e,...t)}info(e,...t){this.log(C.INFO,e,...t)}warn(e,...t){this.log(C.WARN,e,...t)}error(e,...t){this.log(C.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 Ue(){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 ie(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 fe(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>=ne&&(r=r+(n/ne|0),n=n%ne)}return o(-24,-18),o(-18,-12),o(-12,-6),o(-6),e?Ne(n,r):pe(n,r)}function Me(i,e){let t=pe(i,e),n=t.hi&2147483648;n&&(t=Ne(t.lo,t.hi));let r=he(t.lo,t.hi);return n?"-"+r:r}function he(i,e){if({lo:i,hi:e}=Ot(i,e),e<=2097151)return String(ne*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()+ke(s)+ke(o)}function Ot(i,e){return{lo:i>>>0,hi:e>>>0}}function pe(i,e){return{lo:i|0,hi:e|0}}function Ne(i,e){return e=~e,i?i=~i+1:e+=1,pe(i,e)}function ge(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 Pe(){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 ne,ke,ye=L(()=>{"use strict";ne=4294967296;ke=i=>{let e=String(i);return"0000000".slice(e.length)+e}});function Bt(){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()),Fe(t),t},uParse(t){return typeof t!="string"&&(t=t.toString()),Ve(t),t},enc(t){return typeof t!="string"&&(t=t.toString()),Fe(t),fe(t)},uEnc(t){return typeof t!="string"&&(t=t.toString()),Ve(t),fe(t)},dec(t,n){return Me(t,n)},uDec(t,n){return he(t,n)}}}function Fe(i){if(!/^-?[0-9]+$/.test(i))throw new Error("invalid int64: "+i)}function Ve(i){if(!/^[0-9]+$/.test(i))throw new Error("invalid uint64: "+i)}var k,$e=L(()=>{"use strict";ye();k=Bt()});function me(){if(globalThis[be]==null){let i=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[be]={encodeUtf8(t){return i.encode(t)},decodeUtf8(t){return e.decode(t)},checkUtf8(t){try{return encodeURIComponent(t),!0}catch{return!1}}}}return globalThis[be]}var be,Ie=L(()=>{"use strict";be=Symbol.for("@bufbuild/protobuf/text-encoding")});function ve(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<Mt)throw new Error("invalid int32: "+i)}function We(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>kt||i<0)throw new Error("invalid uint32: "+i)}function Nt(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>xt||i<Dt))throw new Error("invalid float32: "+i)}var W,xt,Dt,kt,Ut,Mt,j,O,je=L(()=>{"use strict";ye();$e();Ie();(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"})(W||(W={}));xt=34028234663852886e22,Dt=-34028234663852886e22,kt=4294967295,Ut=2147483647,Mt=-2147483648,j=class{constructor(e=me().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(We(e);e>127;)this.buf.push(e&127|128),e=e>>>7;return this.buf.push(e),this}int32(e){return ve(e),ge(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){Nt(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){We(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){ve(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return ve(e),e=(e<<1^e>>31)>>>0,ge(e,this.buf),this}sfixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=k.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=k.uEnc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=k.enc(e);return ie(t.lo,t.hi,this.buf),this}sint64(e){let t=k.enc(e),n=t.hi>>31,r=t.lo<<1^n,o=(t.hi<<1|t.lo>>>31)^n;return ie(r,o,this.buf),this}uint64(e){let t=k.uEnc(e);return ie(t.lo,t.hi,this.buf),this}},O=class{constructor(e,t=me().decodeUtf8){this.decodeUtf8=t,this.varint64=Ue,this.uint32=Pe,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 W.Varint:for(;this.buf[this.pos++]&128;);break;case W.Bit64:this.pos+=4;case W.Bit32:this.pos+=4;break;case W.LengthDelimited:let r=this.uint32();this.pos+=r;break;case W.StartGroup:for(;;){let[o,s]=this.tag();if(s===W.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 k.dec(...this.varint64())}uint64(){return k.uDec(...this.varint64())}sint64(){let[e,t]=this.varint64(),n=-(e&1);return e=(e>>>1|(t&1)<<31)^n,t=t>>>1^n,k.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 k.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return k.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 qe=L(()=>{"use strict"});var Ke=L(()=>{"use strict"});var Ge=L(()=>{"use strict"});var He=L(()=>{"use strict";je();qe();Ie();Ke();Ge()});function Pt(){return{propertyId:new Uint8Array(0),pageviewId:new Uint8Array(0),sessionId:new Uint8Array(0),pageUrl:"",country:"",region:"",deviceType:"",userId:new Uint8Array(0),domain:"",events:[],browser:"",deviceManufacturer:"",deviceModel:"",city:"",postalCode:""}}function Ft(){return{timestampMs:0,type:0,eventName:"",auctionId:new Uint8Array(0),transactionId:new Uint8Array(0),adUnitCode:"",bid:void 0,namespace:"",eventId:new Uint8Array(0),metadata:{},viewableDurationMs:void 0,bidderOutcomes:[]}}function Vt(){return{key:"",value:""}}function $t(){return{adUnitCode:"",outcome:0,bid:void 0,refreshIndex:0,floorCents:void 0,floorSource:0,floorTreatmentBp:void 0}}function Wt(){return{bidder:"",cpm:0,currency:"",width:0,height:0,dealId:"",mediaType:"",latencyMs:0,advertiserDomain:"",creativeId:""}}var b,F,oe,Ee,Ye,ze,Xe,re,Te=L(()=>{"use strict";He();b={TRACE_EVENT_TYPE_UNSPECIFIED:0,AUCTION_START:1,AUCTION_END:2,BID_WIN:4,IMPRESSION:5,VIEWABLE:6,TIME_IN_VIEW:7,ERROR:9,SLOT_DEFINED:10,SLOT_DESTROYED:11,CLICK:12,AD_RENDER_FAILED:13,WARN:17,UNRECOGNIZED:-1},F={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},oe={FLOOR_SOURCE_UNSPECIFIED:0,FLOOR_SOURCE_STATIC:1,FLOOR_SOURCE_POOL:2,FLOOR_SOURCE_NONE:3,UNRECOGNIZED:-1};Ee={encode(i,e=new j){if(i.propertyId!==void 0&&i.propertyId.length!==0&&e.uint32(10).bytes(i.propertyId),i.pageviewId!==void 0&&i.pageviewId.length!==0&&e.uint32(18).bytes(i.pageviewId),i.sessionId!==void 0&&i.sessionId.length!==0&&e.uint32(26).bytes(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.length!==0&&e.uint32(66).bytes(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)Ye.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 O?i:new O(i),n=e===void 0?t.len:t.pos+e,r=Pt();for(;t.pos<n;){let o=t.uint32();switch(o>>>3){case 1:{if(o!==10)break;r.propertyId=t.bytes();continue}case 2:{if(o!==18)break;r.pageviewId=t.bytes();continue}case 3:{if(o!==26)break;r.sessionId=t.bytes();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.bytes();continue}case 9:{if(o!==74)break;r.domain=t.string();continue}case 10:{if(o!==82)break;let s=Ye.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}};Ye={encode(i,e=new j){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.length!==0&&e.uint32(34).bytes(i.auctionId),i.transactionId!==void 0&&i.transactionId.length!==0&&e.uint32(42).bytes(i.transactionId),i.adUnitCode!==void 0&&i.adUnitCode!==""&&e.uint32(50).string(i.adUnitCode),i.bid!==void 0&&re.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.length!==0&&e.uint32(74).bytes(i.eventId),globalThis.Object.entries(i.metadata||{}).forEach(([t,n])=>{ze.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)Xe.encode(t,e.uint32(98).fork()).join();return e},decode(i,e){let t=i instanceof O?i:new O(i),n=e===void 0?t.len:t.pos+e,r=Ft();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.bytes();continue}case 5:{if(o!==42)break;r.transactionId=t.bytes();continue}case 6:{if(o!==50)break;r.adUnitCode=t.string();continue}case 7:{if(o!==58)break;r.bid=re.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.bytes();continue}case 10:{if(o!==82)break;let s=ze.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=Xe.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}};ze={encode(i,e=new j){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 O?i:new O(i),n=e===void 0?t.len:t.pos+e,r=Vt();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}};Xe={encode(i,e=new j){return i.adUnitCode!==void 0&&i.adUnitCode!==""&&e.uint32(18).string(i.adUnitCode),i.outcome!==void 0&&i.outcome!==0&&e.uint32(32).int32(i.outcome),i.bid!==void 0&&re.encode(i.bid,e.uint32(50).fork()).join(),i.refreshIndex!==void 0&&i.refreshIndex!==0&&e.uint32(56).int32(i.refreshIndex),i.floorCents!==void 0&&e.uint32(64).int32(i.floorCents),i.floorSource!==void 0&&i.floorSource!==0&&e.uint32(72).int32(i.floorSource),i.floorTreatmentBp!==void 0&&e.uint32(80).int32(i.floorTreatmentBp),e},decode(i,e){let t=i instanceof O?i:new O(i),n=e===void 0?t.len:t.pos+e,r=$t();for(;t.pos<n;){let o=t.uint32();switch(o>>>3){case 2:{if(o!==18)break;r.adUnitCode=t.string();continue}case 4:{if(o!==32)break;r.outcome=t.int32();continue}case 6:{if(o!==50)break;r.bid=re.decode(t,t.uint32());continue}case 7:{if(o!==56)break;r.refreshIndex=t.int32();continue}case 8:{if(o!==64)break;r.floorCents=t.int32();continue}case 9:{if(o!==72)break;r.floorSource=t.int32();continue}case 10:{if(o!==80)break;r.floorTreatmentBp=t.int32();continue}}if((o&7)===4||o===0)break;t.skip(o&7)}return r}};re={encode(i,e=new j){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 O?i:new O(i),n=e===void 0?t.len:t.pos+e,r=Wt();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}}});function q(i){if(!i)return new Uint8Array(0);if(jt.test(i)){let t=i.replace(/-/g,""),n=new Uint8Array(16);for(let r=0;r<16;r++)n[r]=parseInt(t.slice(r*2,r*2+2),16);return n}if(Ze)return Ze.encode(i);let e=new Uint8Array(i.length);for(let t=0;t<i.length;t++)e[t]=i.charCodeAt(t)&255;return e}var jt,Ze,Yn,Je=L(()=>{"use strict";jt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,Ze=typeof TextEncoder<"u"?new TextEncoder:null,Yn=typeof TextDecoder<"u"?new TextDecoder:null});function X(){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 cn(i){let e="";for(let n=0;n<i.length;n+=8192)e+=String.fromCharCode(...i.subarray(n,n+8192));return btoa(e)}function ln(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 un(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 fn(i){let e={},t=0;for(let n of Object.keys(i)){if(t>=Ht)break;let r=i[n];if(r==null)continue;let o=String(r);e[n]=o.length>tt?`${o.slice(0,tt)}...[truncated]`:o,t++}return e}function hn(i){let e=i.slice(se.length).split("_");return e.length===2&&/^\d+$/.test(e[0])}function pn(i,e){if(!i||!e)return!1;try{return new URL(i).origin===new URL(e).origin}catch{return!1}}function dt(i){try{typeof localStorage<"u"&&(localStorage.setItem(ot,i.toString()),z=i)}catch{}}function at(i=Date.now()){return V>0&&i-V<=st}function de(){let i=Date.now(),e=!!x&&!at(i);if(V=i,e){x=null;for(let t of bn)t();return}!Z||!x||z===0||i-z<gn||dt(i)}function mn(){return!x||Z&&z===0}function In(){if(rt||typeof window>"u")return;rt=!0;let i=()=>de();for(let e of yn)window.addEventListener(e,i,{passive:!0,capture:!0});typeof document<"u"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&de()})}function Ae(){let i=Date.now(),e=!!x&&at(i);try{if(Z&&typeof localStorage<"u"){let t=localStorage.getItem(it),n=localStorage.getItem(ot),r=n&&parseInt(n,10)||0;if(t&&r&&i-r<=st)return(x!==t||V<r)&&(x=t,V=Math.max(V,r)),z===0&&(z=r),t;let o=e?x:X();return e||(V=i),localStorage.setItem(it,o),dt(V),x=o,o}}catch{}return e||(x=X(),V=i),x}function l(i){return String(i??"").replace(/%/g,"%25").replace(/:/g,"%3A")}function vn(i,e){switch(i){case"auctionInit":return`auctionInit:${l(e?.auctionId)}`;case"auctionEnd":return`auctionEnd:${l(e?.auctionId)}`;case"bidRequested":{let t=Array.isArray(e?.bids)?e.bids.map(n=>l(n?.bidId||n?.transactionId||n?.adUnitCode)).join(","):"";return`bidRequested:${l(e?.auctionId)}:${l(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:${l(t.auctionId)}:${l(t.adUnitCode)}:${l(t.bidderCode||t.bidder)}:${l(n)}:${l(r)}`}case"bidTimeout":return"bidTimeout:"+(Array.isArray(e)?e:e?[e]:[]).map(n=>`${l(n?.auctionId)}:${l(n?.bidderCode||n?.bidder)}:${l(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:${l(t.auctionId)}:${l(t.adUnitCode)}:${l(t.bidderCode||t.bidder)}:${l(n)}:${l(r)}`}case"noBid":return`noBid:${l(e?.auctionId)}:${l(e?.adUnitCode)}:${l(e?.bidderCode||e?.bidder)}:${l(e?.bidId||e?.transactionId)}`;case"adRenderFailed":{let t=e?.bid||{};return`adRenderFailed:${l(t.auctionId||e?.auctionId)}:${l(t.adUnitCode||e?.adUnitCode)}:${l(t.bidderCode||t.bidder||e?.bidderCode||e?.bidder)}:${l(e?.reason)}:${l(e?.message)}`}case"adRenderSucceeded":{let t=e?.bid||e||{},n=t.creativeId||t.adId||e?.adId||"",r=t.originalCpm??t.cpm??"";return`adRenderSucceeded:${l(t.auctionId||e?.auctionId)}:${l(t.adUnitCode||e?.adUnitCode)}:${l(t.bidderCode||t.bidder)}:${l(n)}:${l(r)}`}case"setTargeting":return`setTargeting:${Object.keys(e||{}).sort().map(l).join(",")}`;case"auctionDebug":return`auctionDebug:${l(e?.type)}:${l(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 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 En(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 _e(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?.()||"",u={pbjsGlobalName:i,...e,...s};if(a&&!pn(u.endpoint||"",a)&&(Y.warn(`Ignoring analytics endpoint change to ${u.endpoint||"(empty)"}: this page is pinned to ${a}. Reload to change the ingest endpoint.`),u.endpoint=a),d)try{d.disable()}catch(I){Y.warn("Failed to disable previous analytics instance:",I)}let c=new S(u);return c.enable(),t._bidkernelPrebidAnalytics=c,c},o=()=>{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 s=En(t);s&&(s.propertyId||e?.propertyId)&&r(s)}catch(s){Y.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 et,qt,ee,Kt,Gt,we,tt,Ht,nt,se,Yt,zt,Xt,Qt,Zt,Jt,en,tn,G,nn,rn,on,sn,dn,an,it,ot,st,x,V,Z,gn,z,yn,rt,bn,Ce,Y,S,Se=L(()=>{"use strict";De();Te();Je();et=1e4,qt=50,ee=200,Kt=300*1e3,Gt=10,we=32*1024,tt=1024,Ht=16,nt="text/plain",se="_bidkernel_pending_",Yt=20,zt=7200*1e3,Xt=1e4,Qt={auctionStart:b.AUCTION_START,auctionEnd:b.AUCTION_END,bidWin:b.BID_WIN,adRenderFailed:b.AD_RENDER_FAILED,click:b.CLICK,impression:b.IMPRESSION,timeInView:b.TIME_IN_VIEW,viewable:b.VIEWABLE},Zt={WARN:b.WARN,ERROR:b.ERROR},Jt=new Set([b.ERROR,b.WARN]),en=3e3,tn=new Set([b.IMPRESSION,b.BID_WIN,b.CLICK]),G=1800*1e3,nn=200,rn=1e3,on=50,sn=200,dn={static:oe.FLOOR_SOURCE_STATIC,pool:oe.FLOOR_SOURCE_POOL,none:oe.FLOOR_SOURCE_NONE},an=1e3,it="_bidkernel_session",ot="_bidkernel_session_ts",st=1800*1e3,x=null,V=0,Z=!0;gn=60*1e3,z=0,yn=["pointerdown","pointermove","keydown","scroll","wheel","touchstart"],rt=!1,bn=new Set;Ce=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=vn(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}};Y=ue({prefix:"[analytics]",logLevel:"INFO"}),S=class i{static activeInstances=new Set;static allInstances=new Set;static getActiveInstances(){return i.activeInstances}static setLogLevel(e){let t=P(e);Y.setLevel(t);for(let n of i.allInstances)n.setLogLevel(t)}static getLogLevel(){return Y.getLevel()}static setStorageAllowed(e){Z=e,z=0}static isStorageAllowed(){return Z}config;queue=[];errorCount=0;flushTimer=null;boundFlushBeacon;boundVisibilityChange;isEnabled=!1;boundPbjsHandlers=[];pageUrl="";deduper=new Ce;consecutiveSendFailures=0;nextSendAllowedAt=0;replayedEventCount=0;revenueFlushTimer=null;persistedBatchKeys=[];persistedCleanupTimer=null;intersectionObserver=null;slotViewabilityRecords=new Map;elementToSlotId=new Map;slotRefreshIndices=new Map;slotAdSessionCounters=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;floorDecisions=new Map;logger;managesSessionId;constructor(e){e.storageAllowed!==void 0&&i.setStorageAllowed(e.storageAllowed);let t=e.endpoint||"",n=!t||un(t)?t:"";this.config={endpoint:n,propertyId:e.propertyId||"",pageviewId:e.pageviewId||X(),sessionId:e.sessionId||"",userId:e.userId||"",deviceType:e.deviceType||"desktop",country:e.country||"",region:e.region||"",auctionEnabled:e.auctionEnabled??!0,warningsEnabled:e.warningsEnabled??!0,viewabilityEnabled:e.viewabilityEnabled??!0,storageAllowed:e.storageAllowed??!0,logLevel:e.logLevel?P(e.logLevel):Y.getLevel(),pbjsGlobalName:e.pbjsGlobalName||"pbjs",attachPbjsListeners:e.attachPbjsListeners??!0,revenueFlushDelayMs:Number.isFinite(e.revenueFlushDelayMs)&&e.revenueFlushDelayMs>=0?e.revenueFlushDelayMs:en},i.allInstances.add(this),this.logger=ue({prefix:"[analytics]",logLevel:this.config.logLevel}),de(),this.managesSessionId=!e.sessionId,this.managesSessionId&&(this.config.sessionId=Ae()),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()}setLogLevel(e){let t=P(e);this.config.logLevel=t,this.logger.setLevel(t),Y.setLevel(t)}getLogLevel(){return this.logger.getLevel()}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),In(),this.flushTimer=setInterval(()=>this.flush(),et),this.resendPersistedBatches()}}}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,o]of Object.entries(n))t.onEvent(r,o),this.boundPbjsHandlers.push({event:r,handler:o});if(typeof t.getEvents=="function")try{let r=t.getEvents();if(Array.isArray(r)){let o=r.slice(this.replayedEventCount);if(this.replayedEventCount=r.length,o.length>0){this.log("DEBUG",`Replaying ${o.length} historical events from pbjs.getEvents()`);for(let s of o){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,u=n[d];u&&u(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.floorDecisions.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 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)}})),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})}recordClick(e,t){if(!this.isEnabled||!e)return!1;let n=Date.now();if(n-(this.lastClickAt.get(e)||0)<an)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 o=document.activeElement;o&&(o===e||e.contains(o))&&(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 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:"")||X(),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),s.dwellTimer&&(clearTimeout(s.dwellTimer),s.dwellTimer=null,s.dwellStartedAt=null);for(let c of s.thresholdListeners)c.fired=!1,c.timer&&(clearTimeout(c.timer),c.timer=null);s.viewableFired=!1,s.accumulatedTimeInViewMs=0;let u=typeof performance<"u"&&performance.now?performance.now():Date.now();if(s.lastEnteredViewAt=s.inView?u: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 c=s.mediaType==="video"?2e3:1e3;s.dwellStartedAt=u,s.dwellTimer=setTimeout(()=>{this.handleDwellComplete(s)},c),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 u=this.pendingViewableListeners.get(o)||new Set;this.pendingViewableListeners.delete(o);let c={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,viewableListeners:u};this.slotViewabilityRecords.set(o,c),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.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.slotAdSessionCounters.delete(e),this.slotLastAuctionIds.delete(e),this.pendingThresholdListeners.delete(e),this.pendingViewableListeners.delete(e);let t=`${l(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>G){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>G&&this.cachedWinningBids.delete(t);for(;this.cachedWinningBids.size>nn;){let t=this.cachedWinningBids.keys().next();if(t.done)break;this.cachedWinningBids.delete(t.value)}}addImpressionKey(e){if(!this.slotEmittedImpressionKeys.has(e)){for(;this.slotEmittedImpressionKeys.size>=rn;){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>on;){let n=this.auctionBidderOutcomes.keys().next();if(n.done||n.value===e)break;this.auctionBidderOutcomes.delete(n.value)}return t}nextSlotAdSession(e){let t=(this.slotAdSessionCounters.get(e)??0)+1;return this.slotAdSessionCounters.set(e,t),`ad-session-${t}`}hasImpressionEmitted(e,t,n,r,o){let s=t??this.slotRefreshIndices.get(e)??0,d=`${l(e)}:${s}`;if(o){if(n){if(this.slotEmittedImpressionKeys.has(`${d}:auc:${l(n)}:ad:${l(o)}`)||this.slotEmittedImpressionKeys.has(`${d}:ad:${l(o)}`))return!0}else if(this.slotEmittedImpressionKeys.has(`${d}:ad:${l(o)}`))return!0;if(r&&r!==o){if(n){if(this.slotEmittedImpressionKeys.has(`${d}:auc:${l(n)}:${l(r)}`)||this.slotEmittedImpressionKeys.has(`${d}:${l(r)}`))return!0}else if(this.slotEmittedImpressionKeys.has(`${d}:${l(r)}`))return!0}return!1}return r?n?this.slotEmittedImpressionKeys.has(`${d}:auc:${l(n)}:${l(r)}`)||this.slotEmittedImpressionKeys.has(`${d}:${l(r)}`):this.slotEmittedImpressionKeys.has(`${d}:${l(r)}`):n?this.slotEmittedImpressionKeys.has(`${d}:auc:${l(n)}`):this.slotEmittedImpressionKeys.has(d)}markImpressionEmitted(e,t,n,r,o){let s=`${l(e)}:${t}`;!!(o||r)?(o&&(this.addImpressionKey(`${s}:ad:${l(o)}`),n&&this.addImpressionKey(`${s}:auc:${l(n)}:ad:${l(o)}`)),r&&r!==o&&(this.addImpressionKey(`${s}:${l(r)}`),n&&this.addImpressionKey(`${s}:auc:${l(n)}:${l(r)}`)),n&&this.addImpressionKey(`${s}:auc:${l(n)}`)):(this.addImpressionKey(s),n&&this.addImpressionKey(`${s}:auc:${l(n)}`))}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||"",u=s.creativeId||o?.bidTrace?.creativeId||t?.bid?.creativeId||"",c=t?.adId||s.adId||t?.bid?.adId||"",I=t?.mediaType||s.mediaType||o?.bidTrace?.mediaType||"banner",g=n||r,f=(n?this.slotViewabilityRecords.get(n):void 0)||(r?this.slotViewabilityRecords.get(r):void 0),R=g?this.slotLastAuctionIds.get(g)||(f?f.auctionId:void 0):void 0,y=!!(g&&d&&R&&R!==d&&t?.refreshIndex===void 0),_={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:I,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(y&&g){this.flushSlotTimeInView(g);let v=(this.slotRefreshIndices.get(g)??(f?f.refreshIndex:0))+1;this.slotRefreshIndices.set(g,v),this.slotLastAuctionIds.set(g,d),f&&(f.refreshIndex=v,f.auctionId=d,f.transactionId=a,f.bidPayload=_,f.viewableFired=!1,f.accumulatedTimeInViewMs=0)}else g&&(d&&this.slotLastAuctionIds.set(g,d),this.slotRefreshIndices.has(g)||this.slotRefreshIndices.set(g,0));let B=t?.refreshIndex??(n?this.slotRefreshIndices.get(n)??(r?this.slotRefreshIndices.get(r):void 0)??(f?f.refreshIndex:0):0);return n&&this.hasImpressionEmitted(n,B,d,u,c)||r&&r!==n&&this.hasImpressionEmitted(r,B,d,u,c)?(this.log("DEBUG",`Impression already emitted for slot ${n||r} in cycle ${B}`),!1):(n&&this.markImpressionEmitted(n,B,d,u,c),r&&r!==n&&this.markImpressionEmitted(r,B,d,u,c),this.enqueue(b.IMPRESSION,"impression",{auctionId:d,transactionId:a,adUnitCode:r,bid:_,metadata:{...t?.metadata,refresh_index:String(B)}}),f&&(!f.bidPayload&&_&&(f.bidPayload=_),!f.auctionId&&d&&(f.auctionId=d),!f.transactionId&&a&&(f.transactionId=a)),!0)}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(u){this.log("ERROR","Error in threshold callback",u)}}}},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=Zt[e]??Qt[t];r!==void 0&&this.enqueue(r,t,n)}recordFloorDecision(e,t,n){if(!e||!t)return;let r=`${e}:${t}`;for(this.floorDecisions.delete(r),this.floorDecisions.set(r,{floorCents:n.floorCents!==void 0&&Number.isFinite(n.floorCents)?Math.round(n.floorCents):void 0,source:n.source,treatment:Number.isFinite(n.treatment)?n.treatment:1});this.floorDecisions.size>sn;){let o=this.floorDecisions.keys().next();if(o.done)break;this.floorDecisions.delete(o.value)}}floorDecisionFor(e,t){return e&&t?this.floorDecisions.get(`${e}:${t}`):void 0}setUserId(e){this.config.userId=e}setSessionId(e){this.config.sessionId=e,this.managesSessionId=!e,this.managesSessionId&&(this.config.sessionId=Ae())}navigate(e,t){if(this.disable(),this.slotRefreshIndices.clear(),this.slotAdSessionCounters.clear(),this.floorDecisions.clear(),this.pendingThresholdListeners.clear(),this.config.pageviewId=e||X(),t)try{let n=new URL(t);this.pageUrl=n.origin+n.pathname}catch{this.pageUrl=t}else this.pageUrl="";this.logger.resetTiming(),de(),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})}auctionCycleIndex(e){if(!e)return 0;let t=this.slotRefreshIndices.get(e)??this.slotViewabilityRecords.get(e)?.refreshIndex;return t===void 0?0:t+1}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",u=`${n}:${s}`;r.has(u)||r.set(u,{adUnitCode:s,outcome:F.BIDDER_OUTCOME_NO_RESPONSE,bid:{bidder:n,mediaType:a,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)return;let u=o>0?{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||""}:{bidder:n,mediaType:a,latencyMs:s};this.getOrCreateAuctionOutcomes(t).set(`${n}:${r}`,{adUnitCode:r,outcome:o>0?F.BIDDER_OUTCOME_BID:F.BIDDER_OUTCOME_NO_BID,bid:u})}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),u=`${o}:${s}`,c=a.get(u);c?(c.outcome=F.BIDDER_OUTCOME_TIMEOUT,d>0&&c.bid&&(c.bid.latencyMs=d)):a.set(u,{adUnitCode:s,outcome:F.BIDDER_OUTCOME_TIMEOUT,bid:{bidder:o,mediaType:"banner",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===F.BIDDER_OUTCOME_NO_RESPONSE&&(d.outcome=F.BIDDER_OUTCOME_NO_BID):o.set(s,{adUnitCode:r,outcome:F.BIDDER_OUTCOME_NO_BID,bid:{bidder:n,mediaType:"banner",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||"",u=(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),c=s==="video"||t.mediaType==="video"||t.mediaTypes?.video!==void 0||u?.bidTrace?.mediaType==="video"||u?.rawBid?.mediaType==="video"||n&&this.slotViewabilityRecords.get(n)?.mediaType==="video",I=c?"video":s||u?.bidTrace?.mediaType||"banner",g={bidder:t.bidderCode||t.bidder||u?.bidTrace?.bidder||"",cpm:Number.isFinite(t.originalCpm)?t.originalCpm:Number.isFinite(t.cpm)?t.cpm:u?.bidTrace?.cpm??0,currency:t.originalCurrency??t.currency??u?.bidTrace?.currency??"USD",...K(t).width?K(t):u?.bidTrace?{width:u.bidTrace.width,height:u.bidTrace.height}:K(t),dealId:t.dealId||u?.bidTrace?.dealId||"",mediaType:I,latencyMs:Number.isFinite(t.timeToRespond)?t.timeToRespond:u?.bidTrace?.latencyMs??0,advertiserDomain:t.meta?.advertiserDomains?.[0]||u?.bidTrace?.advertiserDomain||"",creativeId:t.creativeId||u?.bidTrace?.creativeId||""},f=r||u?.auctionId||"",R=o||u?.transactionId||"",y=n?this.slotViewabilityRecords.get(n):void 0,_=y&&f&&y.auctionId&&y.auctionId!==f;if(!!(n&&y&&_)){this.flushSlotTimeInView(n);let v=(this.slotRefreshIndices.get(n)??(y?y.refreshIndex:0))+1;this.slotRefreshIndices.set(n,v),this.slotLastAuctionIds.set(n,f),y&&(y.refreshIndex=v,y.auctionId=f,y.transactionId=R,y.bidPayload=g,y.viewableFired=!1,y.accumulatedTimeInViewMs=0)}else n&&(f&&this.slotLastAuctionIds.set(n,f),this.slotRefreshIndices.has(n)||this.slotRefreshIndices.set(n,0));let U=n?this.slotRefreshIndices.get(n)??(y?y.refreshIndex:0):0;if(c?this.log("DEBUG",`adRenderSucceeded received for video ad unit ${n||"unknown"}: suppressing IMPRESSION until verified video lifecycle event`):n&&this.hasImpressionEmitted(n,U,f,g.creativeId)||(n&&this.markImpressionEmitted(n,U,f,g.creativeId),this.enqueue(b.IMPRESSION,"impression",{auctionId:f,transactionId:R,adUnitCode:n,bid:g,metadata:{refresh_index:String(U)}})),this.config.viewabilityEnabled&&typeof document<"u"){let v=n&&this.slotElements.get(n)||null,T=n||e.adId||t.adId;if(!v&&T&&(v=document.getElementById(T)),!v&&typeof window<"u"&&window.googletag?.pubads)try{let M=window.googletag.pubads().getSlots();for(let m of M)if((m.getAdUnitPath?.()===n||m.getSlotElementId?.()===n)&&(v=document.getElementById(m.getSlotElementId()),v))break}catch{}if(!v&&T)try{for(let M of Array.from(document.querySelectorAll("[data-ad-slot]")))if(M.getAttribute("data-ad-slot")===T){v=M;break}}catch{}v&&this.observeSlot(v,n||T,{adUnitCode:n,auctionId:f,transactionId:R,mediaType:I,bid:g,refreshIndex:U})}}isDuplicate(e,t){return this.deduper.isDuplicate(e,t)}enqueue(e,t,n){if(!this.isEnabled||!this.shouldSample(e))return;this.managesSessionId&&mn()&&(this.config.sessionId=Ae());let r={eventId:q(X()),timestampMs:Date.now(),type:e,eventName:Jt.has(e)?t:"",auctionId:q(String(n.auctionId||"")),transactionId:q(String(n.transactionId||"")),adUnitCode:n.adUnitCode||n.elementId||"",namespace:n.ns||n.namespace||""};n.bid&&(r.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&&(r.viewableDurationMs=Number.isFinite(n.viewableDurationMs)?n.viewableDurationMs:0),n.bidderOutcomes&&Array.isArray(n.bidderOutcomes)&&(r.bidderOutcomes=n.bidderOutcomes.map(d=>{let a=this.floorDecisionFor(String(n.auctionId||""),d.adUnitCode||"");return{...d,refreshIndex:d.refreshIndex??this.auctionCycleIndex(d.adUnitCode||""),...a?{floorCents:a.floorCents,floorSource:dn[a.source],floorTreatmentBp:Math.round(a.treatment*1e4)}:{}}}));let o={...n.metadata};if(e===b.BID_WIN||e===b.IMPRESSION){let d=this.floorDecisionFor(String(n.auctionId||""),r.adUnitCode||"");d&&(d.floorCents!==void 0&&(o.floor_cents=String(d.floorCents)),o.floor_source=d.source,o.floor_treatment=d.treatment.toFixed(2))}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 s=fn(o);Object.keys(s).length>0&&(r.metadata=s),this.queue.push(r),this.queue.length>=ee?(this.flush(),this.queue.length>ee&&this.queue.splice(0,this.queue.length-ee)):tn.has(e)&&this.revenueFlushTimer===null&&(this.revenueFlushTimer=setTimeout(()=>{this.revenueFlushTimer=null,this.flush()},this.config.revenueFlushDelayMs))}shouldSample(e){return e===b.ERROR?(this.errorCount++,this.errorCount<=qt):e===b.WARN?this.config.warningsEnabled:this.config.auctionEnabled}requeue(e){e.length&&(this.queue=e.concat(this.queue),this.queue.length>ee&&this.queue.splice(0,this.queue.length-ee))}drainBatch(){if(this.queue.length===0||!this.config.endpoint)return null;let e=typeof window<"u"?window.location.hostname:"",t=n=>({propertyId:q(this.config.propertyId),pageviewId:q(this.config.pageviewId),sessionId:q(this.config.sessionId),pageUrl:this.pageUrl,country:this.config.country,region:this.config.region,deviceType:this.config.deviceType,userId:q(this.config.userId),domain:e,events:n});for(;;){if(this.queue.length===0)return null;let n=this.queue,r=Ee.encode(t(n)).finish();for(;n.length>1&&r.byteLength>we;)n=n.slice(0,Math.floor(n.length/2)),r=Ee.encode(t(n)).finish();if(r.byteLength>we){let[o]=this.queue.splice(0,1);this.log("WARN",`Dropping oversized event (type ${o?.type}, ${r.byteLength} bytes exceeds the ${we}-byte cap on its own)`);continue}return this.queue=this.queue.slice(n.length),{url:this.batchUrl(),encoded:r,events:n}}}sendFetch(e,t=!1,n,r=!1){let o={method:"POST",headers:{"Content-Type":nt},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(et*2**(this.consecutiveSendFailures-1),Kt);this.nextSendAllowedAt=Date.now()+t,this.consecutiveSendFailures<=Gt?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()}batchUrl(){return`${this.config.endpoint}/${this.config.propertyId}`}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:nt});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`${se}${encodeURIComponent(this.config.propertyId)}_`}persistBatch(e){if(!Z)return null;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(se)&&t++}if(t>=Yt)return null;let n=`${this.pendingKeyPrefix()}${Date.now()}_${Math.floor(Math.random()*1e6)}`;return localStorage.setItem(n,cn(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)},Xt))}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(se)||(o.startsWith(e)?t.push(o):hn(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>zt)continue;let d;try{d=ln(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)}}});function Tn(i){let e=typeof i?.getError=="function"?i.getError():i?.error||i,t=a=>e&&typeof e[a]=="function"?e[a]():void 0,n=t("getMessage")||e?.message||String(e||"IMA ad error"),r=t("getErrorCode")??e?.code,o=t("getVastErrorCode"),s=t("getType")??e?.type,d={message:n};return r&&(d.error_code=String(r)),o&&(d.vast_error_code=String(o)),s&&(d.error_type=String(s)),{err:e,message:n,metadata:d}}function ht(i,e,t){let n=ae(i),{err:r,message:o,metadata:s}=Tn(e);return n.log("WARN","IMA AdErrorEvent received",e),n.enqueue(b.AD_RENDER_FAILED,"adRenderFailed",{auctionId:t.auctionId,transactionId:t.transactionId,adUnitCode:t.adUnitCode,bid:t.bid,metadata:{...t.metadata,reason:t.adStarted?"ima_playback_error":"ima_ad_error",playback_phase:t.adStarted?"post_start":"pre_start",...s},error:typeof r=="object"?r:new Error(o)}),r}function wn(i,e){if(!i||typeof i!="object"||ct.has(i))return;ct.add(i);let t=typeof window<"u"&&window.google?.ima?.AdErrorEvent?.Type?.AD_ERROR||"adError";try{e.call(i,t,n=>{for(let r of S.getActiveInstances())try{let o=gt(r,{mediaType:"video"});ht(r,n,{adStarted:!1,adUnitCode:o?.adUnitCode||"video",auctionId:o?.auctionId,transactionId:o?.transactionId,bid:o?.bidTrace})}catch{}})}catch{}}function lt(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 S.getActiveInstances())try{s.attachImaAdsManager(o)}catch{}return o};n.__bidkernelHooked=!0,e.getAdsManager=n}}catch{}}function ut(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 S.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 S.getActiveInstances())try{o.attachImaAdsManager(this)}catch{}return t.apply(this,r)};n.__bidkernelHooked=!0,e.start=n}}catch{}}function ft(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(wn(this,t),(r==="adsManagerLoaded"||r===(this?.AdsManagerLoadedEvent?.Type?.ADS_MANAGER_LOADED||"adsManagerLoaded"))&&typeof o=="function"){let d=Re.get(o);return d||(d=function(a){if(a&&typeof a.getAdsManager=="function"&&!a.getAdsManager.__bidkernelHooked){let u=a.getAdsManager;a.getAdsManager=function(...c){let I=u.apply(this,c);if(I)for(let g of S.getActiveInstances())try{g.attachImaAdsManager(I)}catch{}return I},a.getAdsManager.__bidkernelHooked=!0}return o.apply(this,arguments)},Re.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"?Re.get(o):void 0;return t.call(this,r,d||o,...s)};n.__bidkernelHooked=!0,e.removeEventListener=n}}catch{}}function te(i){if(!(!i||typeof i!="object"))try{i.AdsManagerLoadedEvent&&lt(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,lt(o)}})}catch{}}i.AdsLoader&&ft(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,ft(o)}})}catch{}}i.AdsManager&&ut(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,ut(o)}})}catch{}}}catch{}}function pt(){if(typeof window>"u")return;let i=window;if(i.google?.ima&&te(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,te(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&&te(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,te(s)}})}catch{}}}}})}catch{}}}function gt(i,e){let t=ae(i),n=Date.now(),r=d=>t.hasImpressionEmitted(d.adUnitCode,void 0,d.auctionId,d.bidTrace.creativeId);if(e?.creativeId||e?.adId){for(let d of Array.from(t.cachedWinningBids.values()))if(!(n-d.timestamp>G)&&(e.creativeId&&(d.bidTrace.creativeId===e.creativeId||d.rawBid?.creativeId===e.creativeId)||e.adId&&(d.rawBid?.adId===e.adId||d.adUnitCode===e.adId)))return d}let o;if(e?.mediaType){for(let a of Array.from(t.cachedWinningBids.values())){if(n-a.timestamp>G)continue;(a.bidTrace.mediaType===e.mediaType||a.rawBid?.mediaType===e.mediaType||e.mediaType==="video"&&a.rawBid?.mediaTypes?.video!==void 0)&&(r(a)||(!o||a.timestamp<o.timestamp)&&(o=a))}if(o)return o;let d;for(let a of Array.from(t.cachedWinningBids.values())){if(n-a.timestamp>G)continue;(a.bidTrace.mediaType===e.mediaType||a.rawBid?.mediaType===e.mediaType||e.mediaType==="video"&&a.rawBid?.mediaTypes?.video!==void 0)&&(!d||a.timestamp>d.timestamp)&&(d=a)}if(d)return d}for(let d of Array.from(t.cachedWinningBids.values()))n-d.timestamp>G||r(d)||(!o||d.timestamp>o.timestamp)&&(o=d);if(o)return o;let s;for(let d of Array.from(t.cachedWinningBids.values()))n-d.timestamp>G||(!s||d.timestamp>s.timestamp)&&(s=d);return s}function yt(i,e,t){let n=ae(i);if(!e||typeof e.addEventListener!="function")return n.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 r=e.__bidkernelAttachedInstances,o=r.get(i);if(o){if(!t)return()=>{};o()}let s=t?.slotId||t?.adUnitCode||"video",d=t?.adUnitCode||s,a=t?.auctionId||"",u=t?.transactionId||"",c=p=>{let h=(a?n.getCachedBid(`${a}:${d}`):void 0)||(a&&s!==d?n.getCachedBid(`${a}:${s}`):void 0)||(d!=="video"?n.getCachedBid(d):void 0)||(s!==d&&s!=="video"?n.getCachedBid(s):void 0);return h||(h=gt(i,{creativeId:p?.creativeId,adId:p?.adId,mediaType:"video"})),h},I=!1,g=null,f=p=>{let h=typeof n.nextSlotAdSession=="function"?n.nextSlotAdSession(s):`ad-session-${(n.slotAdSessionCounters?.get(s)??0)+1}`;if(n.slotAdSessionCounters&&typeof n.nextSlotAdSession!="function"){let N=(n.slotAdSessionCounters.get(s)??0)+1;n.slotAdSessionCounters.set(s,N)}let E=(typeof p?.getAdId=="function"?p.getAdId():p?.adId??p?.id)||"",H=(typeof p?.getCreativeId=="function"?p.getCreativeId():p?.creativeId)||"";return g={sessionId:h,adId:E||void 0,creativeId:H||void 0},g},R=p=>{let h=typeof p?.getAd=="function"?p.getAd():p?.ad;f(h),n.log("DEBUG","IMA AdEvent.LOADED received",{slotId:s,activeAdSession:g})},y=p=>{I=!0;let h=typeof p?.getAd=="function"?p.getAd():p?.ad,E={};h&&(E.creativeId=(typeof h.getCreativeId=="function"?h.getCreativeId():h.creativeId)||"",E.adId=(typeof h.getAdId=="function"?h.getAdId():h.id)||"",E.title=(typeof h.getTitle=="function"?h.getTitle():h.title)||"",E.duration=typeof h.getDuration=="function"?h.getDuration():h.duration,E.advertiserName=typeof h.getAdvertiserName=="function"?h.getAdvertiserName():""),!g||E.adId&&g.adId&&g.adId!==E.adId?f(h):(!g.adId&&E.adId&&(g.adId=E.adId),!g.creativeId&&E.creativeId&&(g.creativeId=E.creativeId));let H=g||f(h),N=c(E),ce=t?.slotId&&t.slotId!=="video"?t.slotId:t?.adUnitCode&&t.adUnitCode!=="video"?t.adUnitCode:N?.adUnitCode||t?.slotId||t?.adUnitCode||"video",It=t?.adUnitCode&&t.adUnitCode!=="video"?t.adUnitCode:N?.adUnitCode||ce,vt=a||N?.auctionId||"",Et=u||N?.transactionId||"",Le=H.creativeId||E.creativeId||N?.bidTrace?.creativeId||t?.bid?.creativeId||"",Tt=H.adId||E.adId||Le||H.sessionId,Oe={...N?.rawBid||t?.bid,mediaType:"video",creativeId:Le},Be=n.recordImpression(ce,{adUnitCode:It,auctionId:vt,transactionId:Et,mediaType:"video",bid:Oe,adId:Tt,metadata:{...t?.metadata,media_type:"video",...E.title?{ad_title:E.title}:{},...Number.isFinite(E.duration)?{ad_duration_s:String(E.duration)}:{}}}),J=typeof p?.type=="string"?p.type:typeof p?.getType=="function"?p.getType():typeof p=="string"?p:"";J.toLowerCase().startsWith("adevent.")&&(J=J.slice(8));let wt=J?J.toUpperCase():"STARTED/IMPRESSION";if(n.log("DEBUG",`IMA AdEvent.${wt} received${Be?"":" (second event for this ad, already counted)"}`,p),Be&&t?.onImpression)try{t.onImpression(ce,{ad:h,bid:Oe})}catch(At){n.log("ERROR","Error in onImpression callback",At)}},_=p=>{if(n.log("DEBUG",`IMA AdEvent milestone: ${p}`),t?.onMilestone)try{t.onMilestone(p,s)}catch(h){n.log("ERROR","Error in onMilestone callback",h)}},B=p=>{n.log("DEBUG","IMA AdEvent.CLICK received",p);let h=c(),E=t?.adUnitCode&&t.adUnitCode!=="video"?t.adUnitCode:h?.adUnitCode||s;n.enqueue(b.CLICK,"click",{auctionId:a||h?.auctionId,transactionId:u||h?.transactionId,adUnitCode:E,bid:h?.bidTrace||t?.bid,metadata:{...t?.metadata,media_type:"video"}})},U=p=>{g=null;let h=c(),E=t?.adUnitCode&&t.adUnitCode!=="video"?t.adUnitCode:h?.adUnitCode||s,H=ht(i,p,{adStarted:I,adUnitCode:E,auctionId:a||h?.auctionId,transactionId:u||h?.transactionId,bid:h?.bidTrace||t?.bid,metadata:t?.metadata});if(t?.onError)try{t.onError(H)}catch(N){n.log("ERROR","Error in onError callback",N)}},v=typeof window<"u"?window.google?.ima:void 0,T=v?.AdEvent?.Type||{},M=v?.AdErrorEvent?.Type||{},m=[{type:T.LOADED||"loaded",handler:R},{type:T.STARTED||"started",handler:y},{type:T.IMPRESSION||"impression",handler:y},{type:T.FIRST_QUARTILE||"firstQuartile",handler:()=>_("firstQuartile")},{type:T.MIDPOINT||"midpoint",handler:()=>_("midpoint")},{type:T.THIRD_QUARTILE||"thirdQuartile",handler:()=>_("thirdQuartile")},{type:T.COMPLETE||"complete",handler:()=>{g=null,_("complete")}},{type:T.ALL_ADS_COMPLETED||"allAdsCompleted",handler:()=>{g=null}},{type:T.CLICK||"click",handler:B},{type:M.AD_ERROR||"adError",handler:U}],A=new Set,w=[];for(let p of m)A.has(p.type)||(A.add(p.type),w.push(p));for(let{type:p,handler:h}of w)try{e.addEventListener(p,h)}catch{}let D=()=>{g=null,r.delete(i);for(let{type:p,handler:h}of w)try{e.removeEventListener(p,h)}catch{}n.videoDetachCleanups.delete(D)};return r.set(i,D),n.videoDetachCleanups.add(D),D}function An(i,e,t){let n=ae(i);if(!e)return n.log("WARN","attachVideoPlayer called with null/undefined target"),()=>{};let r=null;if(typeof e=="string"){if(typeof document<"u")try{r=document.querySelector(e)||document.getElementById(e)}catch{r=document.getElementById(e)}}else if(typeof HTMLElement<"u"&&e instanceof HTMLElement)r=e;else if(e&&typeof e=="object"&&e.nodeType===1)r=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 yt(i,e,t);e&&typeof e.addEventListener=="function"&&(r=e)}let o=t?.slotId||t?.adUnitCode||(r?r.id:"")||"video",s=t?.adUnitCode||o,d=t?.auctionId||"",a=t?.transactionId||"",u=()=>(d?n.getCachedBid(`${d}:${s}`):void 0)||(d&&o!==s?n.getCachedBid(`${d}:${o}`):void 0)||n.getCachedBid(s)||(o!==s?n.getCachedBid(o):void 0),c=null;r&&(r.tagName&&r.tagName.toLowerCase()==="video"?c=r:c=r.querySelector("video"));let I={q1:!1,q2:!1,q3:!1,q4:!1},g=m=>{let A=m||c||(r?.querySelector?r.querySelector("video"):null),w=u(),D={...w?.rawBid||t?.bid,mediaType:"video"};if(n.recordImpression(o,{adUnitCode:s,auctionId:d||w?.auctionId,transactionId:a||w?.transactionId,mediaType:"video",bid:D,metadata:{...t?.metadata,media_type:"video",...A&&Number.isFinite(A.duration)?{video_duration_s:String(Math.round(A.duration))}:{}}})&&t?.onImpression)try{t.onImpression(o,{element:A||r,bid:D})}catch(h){n.log("ERROR","Error in onImpression callback",h)}},f=m=>{n.log("DEBUG","HTML5 video playing event received");let A=m?.target instanceof HTMLVideoElement?m.target:c;g(A)},R=m=>{let A=m?.target instanceof HTMLVideoElement?m.target:c;if(A&&A.currentTime>0&&(g(A),Number.isFinite(A.duration)&&A.duration>0)){let w=A.currentTime/A.duration;w>=.25&&!I.q1&&(I.q1=!0,t?.onMilestone?.("firstQuartile",o)),w>=.5&&!I.q2&&(I.q2=!0,t?.onMilestone?.("midpoint",o)),w>=.75&&!I.q3&&(I.q3=!0,t?.onMilestone?.("thirdQuartile",o))}},y=()=>{I.q4||(I.q4=!0,t?.onMilestone?.("complete",o))},_=m=>{let w=(m?.target instanceof HTMLVideoElement?m.target:c)?.error||c?.error,D=u(),p=w?`HTML5 video error code ${w.code}: ${w.message}`:"Video playback error";if(n.log("WARN",p),n.enqueue(b.AD_RENDER_FAILED,"adRenderFailed",{auctionId:d||D?.auctionId,transactionId:a||D?.transactionId,adUnitCode:s,bid:D?.bidTrace||t?.bid,metadata:{...t?.metadata,reason:"html5_video_error",message:p,...w?.code?{error_code:String(w.code)}:{}},error:w?new Error(p):void 0}),t?.onError)try{t.onError(w)}catch(h){n.log("ERROR","Error in onError callback",h)}},B=m=>{m.addEventListener("playing",f),m.addEventListener("play",f),m.addEventListener("timeupdate",R),m.addEventListener("ended",y),m.addEventListener("error",_)},U=m=>{m.removeEventListener("playing",f),m.removeEventListener("play",f),m.removeEventListener("timeupdate",R),m.removeEventListener("ended",y),m.removeEventListener("error",_)},v=null;r&&r!==c&&(r.addEventListener("playing",f,!0),r.addEventListener("play",f,!0),r.addEventListener("timeupdate",R,!0),r.addEventListener("ended",y,!0),r.addEventListener("error",_,!0)),c&&B(c),r&&r.tagName?.toLowerCase()!=="video"&&typeof MutationObserver<"u"&&(v=new MutationObserver(()=>{let m=r.querySelector("video");m&&m!==c&&(c&&U(c),c=m,c&&B(c))}),v.observe(r,{childList:!0,subtree:!0}));let T=u();t?.trackViewability!==!1&&r&&n.observeSlot(r,o,{adUnitCode:s,auctionId:d||T?.auctionId,transactionId:a||T?.transactionId,mediaType:"video",bid:T?.bidTrace||t?.bid,metadata:t?.metadata});let M=()=>{v&&(v.disconnect(),v=null),r&&r!==c&&(r.removeEventListener("playing",f,!0),r.removeEventListener("play",f,!0),r.removeEventListener("timeupdate",R,!0),r.removeEventListener("ended",y,!0),r.removeEventListener("error",_,!0)),c&&U(c),n.videoDetachCleanups.delete(M)};return n.videoDetachCleanups.add(M),M}var ae,Re,ct,Cn,bt=L(()=>{"use strict";Se();Te();ae=i=>i,Re=new WeakMap,ct=new WeakSet;typeof window<"u"&&pt();S.prototype.attachImaAdsManager=function(i,e){return yt(this,i,e)};S.prototype.attachVideoPlayer=function(i,e){return An(this,i,e)};Cn=S.prototype.enable;S.prototype.enable=function(){Cn.call(this),typeof window<"u"&&(pt(),window.google?.ima&&te(window.google.ima))}});var Sn=Ct(()=>{Se();bt();var mt="https://by.bidkernel.io/t",_n=window._bidkernelPbjsGlobal||"pbjs";_e(_n,{endpoint:mt});window.bidkernelPrebidAnalytics={...window.bidkernelPrebidAnalytics,register:(i,e)=>_e(i,{endpoint:mt,...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},setLogLevel:i=>{S.setLogLevel(i)},getLogLevel:()=>S.getLogLevel()}});return Sn();})();
1
+ "use strict";var bidkernelPrebidAnalyticsBundle=(()=>{var L=(i,e)=>()=>(i&&(e=i(i=0)),e);var Ct=(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 St}function Lt(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 P(i){if(typeof i=="string"){let e=i.toUpperCase();if(e==="DEBUG"||e==="INFO"||e==="WARN"||e==="ERROR")return e}return C.INFO}function ue(i){return new le(i)}var C,De,$,_t,St,le,xe=L(()=>{"use strict";C={DEBUG:"DEBUG",INFO:"INFO",WARN:"WARN",ERROR:"ERROR"},De={[C.DEBUG]:10,[C.INFO]:20,[C.WARN]:30,[C.ERROR]:40},$={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"},_t=0,St=new Set;le=class i{_prefix;_level;_loadedAt;_now;_console;_customFormatTime;_listeners=new Set;constructor(e={}){this._prefix=e.prefix??"[bidkernel]",this._level=P(e.logLevel??C.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=P(e)}getLevel(){return this._level}setLevel(e){this._level=P(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=P(e);return(De[t]??20)>=(De[this._level]??20)}formatTime(e){return this._customFormatTime?this._customFormatTime(e):Lt(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=P(e);if(!this.isEnabled(r))return;let o=this._getElapsed(),s=this.formatTime(o),d=Date.now(),u={id:`bk_log_${d}_${++_t}`,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(u);let c=this._getConsole();if(!c)return;let I=$.badge,g=$.event;r===C.WARN?(I=$.badgeWarn,g=$.eventWarn):r===C.ERROR&&(I=$.badgeError,g=$.eventError);let f=`%c${this._prefix}%c ${s} %c${t}%c`,R=[I,$.dim,g,$.reset],y=[f,...R];switch(n.length>0&&y.push(...n),r){case C.DEBUG:typeof c.log=="function"?c.log(...y):typeof c.debug=="function"&&c.debug(...y);break;case C.INFO:typeof c.info=="function"?c.info(...y):typeof c.log=="function"&&c.log(...y);break;case C.WARN:typeof c.warn=="function"?c.warn(...y):typeof c.log=="function"&&c.log(...y);break;case C.ERROR:typeof c.error=="function"?c.error(...y):typeof c.log=="function"&&c.log(...y);break;default:typeof c.log=="function"&&c.log(...y);break}}debug(e,...t){this.log(C.DEBUG,e,...t)}info(e,...t){this.log(C.INFO,e,...t)}warn(e,...t){this.log(C.WARN,e,...t)}error(e,...t){this.log(C.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 Ue(){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 ie(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 fe(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>=ne&&(r=r+(n/ne|0),n=n%ne)}return o(-24,-18),o(-18,-12),o(-12,-6),o(-6),e?Ne(n,r):pe(n,r)}function Me(i,e){let t=pe(i,e),n=t.hi&2147483648;n&&(t=Ne(t.lo,t.hi));let r=he(t.lo,t.hi);return n?"-"+r:r}function he(i,e){if({lo:i,hi:e}=Ot(i,e),e<=2097151)return String(ne*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()+ke(s)+ke(o)}function Ot(i,e){return{lo:i>>>0,hi:e>>>0}}function pe(i,e){return{lo:i|0,hi:e|0}}function Ne(i,e){return e=~e,i?i=~i+1:e+=1,pe(i,e)}function ge(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 Pe(){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 ne,ke,ye=L(()=>{"use strict";ne=4294967296;ke=i=>{let e=String(i);return"0000000".slice(e.length)+e}});function Bt(){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()),Fe(t),t},uParse(t){return typeof t!="string"&&(t=t.toString()),Ve(t),t},enc(t){return typeof t!="string"&&(t=t.toString()),Fe(t),fe(t)},uEnc(t){return typeof t!="string"&&(t=t.toString()),Ve(t),fe(t)},dec(t,n){return Me(t,n)},uDec(t,n){return he(t,n)}}}function Fe(i){if(!/^-?[0-9]+$/.test(i))throw new Error("invalid int64: "+i)}function Ve(i){if(!/^[0-9]+$/.test(i))throw new Error("invalid uint64: "+i)}var k,$e=L(()=>{"use strict";ye();k=Bt()});function me(){if(globalThis[be]==null){let i=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[be]={encodeUtf8(t){return i.encode(t)},decodeUtf8(t){return e.decode(t)},checkUtf8(t){try{return encodeURIComponent(t),!0}catch{return!1}}}}return globalThis[be]}var be,Ie=L(()=>{"use strict";be=Symbol.for("@bufbuild/protobuf/text-encoding")});function ve(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<Mt)throw new Error("invalid int32: "+i)}function We(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>kt||i<0)throw new Error("invalid uint32: "+i)}function Nt(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>Dt||i<xt))throw new Error("invalid float32: "+i)}var W,Dt,xt,kt,Ut,Mt,j,O,je=L(()=>{"use strict";ye();$e();Ie();(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"})(W||(W={}));Dt=34028234663852886e22,xt=-34028234663852886e22,kt=4294967295,Ut=2147483647,Mt=-2147483648,j=class{constructor(e=me().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(We(e);e>127;)this.buf.push(e&127|128),e=e>>>7;return this.buf.push(e),this}int32(e){return ve(e),ge(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){Nt(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){We(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){ve(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return ve(e),e=(e<<1^e>>31)>>>0,ge(e,this.buf),this}sfixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=k.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=k.uEnc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=k.enc(e);return ie(t.lo,t.hi,this.buf),this}sint64(e){let t=k.enc(e),n=t.hi>>31,r=t.lo<<1^n,o=(t.hi<<1|t.lo>>>31)^n;return ie(r,o,this.buf),this}uint64(e){let t=k.uEnc(e);return ie(t.lo,t.hi,this.buf),this}},O=class{constructor(e,t=me().decodeUtf8){this.decodeUtf8=t,this.varint64=Ue,this.uint32=Pe,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 W.Varint:for(;this.buf[this.pos++]&128;);break;case W.Bit64:this.pos+=4;case W.Bit32:this.pos+=4;break;case W.LengthDelimited:let r=this.uint32();this.pos+=r;break;case W.StartGroup:for(;;){let[o,s]=this.tag();if(s===W.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 k.dec(...this.varint64())}uint64(){return k.uDec(...this.varint64())}sint64(){let[e,t]=this.varint64(),n=-(e&1);return e=(e>>>1|(t&1)<<31)^n,t=t>>>1^n,k.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 k.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return k.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 qe=L(()=>{"use strict"});var Ke=L(()=>{"use strict"});var Ge=L(()=>{"use strict"});var He=L(()=>{"use strict";je();qe();Ie();Ke();Ge()});function Pt(){return{propertyId:new Uint8Array(0),pageviewId:new Uint8Array(0),sessionId:new Uint8Array(0),pageUrl:"",country:"",region:"",deviceType:"",userId:new Uint8Array(0),domain:"",events:[],browser:"",deviceManufacturer:"",deviceModel:"",city:"",postalCode:""}}function Ft(){return{timestampMs:0,type:0,eventName:"",auctionId:new Uint8Array(0),transactionId:new Uint8Array(0),adUnitCode:"",bid:void 0,namespace:"",eventId:new Uint8Array(0),metadata:{},viewableDurationMs:void 0,bidderOutcomes:[]}}function Vt(){return{key:"",value:""}}function $t(){return{adUnitCode:"",outcome:0,bid:void 0,refreshIndex:0,floorCents:void 0,floorSource:0,floorTreatmentBp:void 0}}function Wt(){return{bidder:"",cpm:0,currency:"",width:0,height:0,dealId:"",mediaType:"",latencyMs:0,advertiserDomain:"",creativeId:""}}var b,F,oe,Ee,Ye,ze,Xe,re,Te=L(()=>{"use strict";He();b={TRACE_EVENT_TYPE_UNSPECIFIED:0,AUCTION_START:1,AUCTION_END:2,BID_WIN:4,IMPRESSION:5,VIEWABLE:6,TIME_IN_VIEW:7,ERROR:9,SLOT_DEFINED:10,SLOT_DESTROYED:11,CLICK:12,AD_RENDER_FAILED:13,WARN:17,CONSENT:19,UNRECOGNIZED:-1},F={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},oe={FLOOR_SOURCE_UNSPECIFIED:0,FLOOR_SOURCE_STATIC:1,FLOOR_SOURCE_POOL:2,FLOOR_SOURCE_NONE:3,UNRECOGNIZED:-1};Ee={encode(i,e=new j){if(i.propertyId!==void 0&&i.propertyId.length!==0&&e.uint32(10).bytes(i.propertyId),i.pageviewId!==void 0&&i.pageviewId.length!==0&&e.uint32(18).bytes(i.pageviewId),i.sessionId!==void 0&&i.sessionId.length!==0&&e.uint32(26).bytes(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.length!==0&&e.uint32(66).bytes(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)Ye.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 O?i:new O(i),n=e===void 0?t.len:t.pos+e,r=Pt();for(;t.pos<n;){let o=t.uint32();switch(o>>>3){case 1:{if(o!==10)break;r.propertyId=t.bytes();continue}case 2:{if(o!==18)break;r.pageviewId=t.bytes();continue}case 3:{if(o!==26)break;r.sessionId=t.bytes();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.bytes();continue}case 9:{if(o!==74)break;r.domain=t.string();continue}case 10:{if(o!==82)break;let s=Ye.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}};Ye={encode(i,e=new j){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.length!==0&&e.uint32(34).bytes(i.auctionId),i.transactionId!==void 0&&i.transactionId.length!==0&&e.uint32(42).bytes(i.transactionId),i.adUnitCode!==void 0&&i.adUnitCode!==""&&e.uint32(50).string(i.adUnitCode),i.bid!==void 0&&re.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.length!==0&&e.uint32(74).bytes(i.eventId),globalThis.Object.entries(i.metadata||{}).forEach(([t,n])=>{ze.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)Xe.encode(t,e.uint32(98).fork()).join();return e},decode(i,e){let t=i instanceof O?i:new O(i),n=e===void 0?t.len:t.pos+e,r=Ft();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.bytes();continue}case 5:{if(o!==42)break;r.transactionId=t.bytes();continue}case 6:{if(o!==50)break;r.adUnitCode=t.string();continue}case 7:{if(o!==58)break;r.bid=re.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.bytes();continue}case 10:{if(o!==82)break;let s=ze.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=Xe.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}};ze={encode(i,e=new j){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 O?i:new O(i),n=e===void 0?t.len:t.pos+e,r=Vt();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}};Xe={encode(i,e=new j){return i.adUnitCode!==void 0&&i.adUnitCode!==""&&e.uint32(18).string(i.adUnitCode),i.outcome!==void 0&&i.outcome!==0&&e.uint32(32).int32(i.outcome),i.bid!==void 0&&re.encode(i.bid,e.uint32(50).fork()).join(),i.refreshIndex!==void 0&&i.refreshIndex!==0&&e.uint32(56).int32(i.refreshIndex),i.floorCents!==void 0&&e.uint32(64).int32(i.floorCents),i.floorSource!==void 0&&i.floorSource!==0&&e.uint32(72).int32(i.floorSource),i.floorTreatmentBp!==void 0&&e.uint32(80).int32(i.floorTreatmentBp),e},decode(i,e){let t=i instanceof O?i:new O(i),n=e===void 0?t.len:t.pos+e,r=$t();for(;t.pos<n;){let o=t.uint32();switch(o>>>3){case 2:{if(o!==18)break;r.adUnitCode=t.string();continue}case 4:{if(o!==32)break;r.outcome=t.int32();continue}case 6:{if(o!==50)break;r.bid=re.decode(t,t.uint32());continue}case 7:{if(o!==56)break;r.refreshIndex=t.int32();continue}case 8:{if(o!==64)break;r.floorCents=t.int32();continue}case 9:{if(o!==72)break;r.floorSource=t.int32();continue}case 10:{if(o!==80)break;r.floorTreatmentBp=t.int32();continue}}if((o&7)===4||o===0)break;t.skip(o&7)}return r}};re={encode(i,e=new j){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 O?i:new O(i),n=e===void 0?t.len:t.pos+e,r=Wt();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}}});function q(i){if(!i)return new Uint8Array(0);if(jt.test(i)){let t=i.replace(/-/g,""),n=new Uint8Array(16);for(let r=0;r<16;r++)n[r]=parseInt(t.slice(r*2,r*2+2),16);return n}if(Ze)return Ze.encode(i);let e=new Uint8Array(i.length);for(let t=0;t<i.length;t++)e[t]=i.charCodeAt(t)&255;return e}var jt,Ze,Xn,Je=L(()=>{"use strict";jt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,Ze=typeof TextEncoder<"u"?new TextEncoder:null,Xn=typeof TextDecoder<"u"?new TextDecoder:null});function X(){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 un(i){let e="";for(let n=0;n<i.length;n+=8192)e+=String.fromCharCode(...i.subarray(n,n+8192));return btoa(e)}function fn(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 hn(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 pn(i){let e={},t=0;for(let n of Object.keys(i)){if(t>=zt)break;let r=i[n];if(r==null)continue;let o=String(r);e[n]=o.length>tt?`${o.slice(0,tt)}...[truncated]`:o,t++}return e}function gn(i){let e=i.slice(se.length).split("_");return e.length===2&&/^\d+$/.test(e[0])}function yn(i,e){if(!i||!e)return!1;try{return new URL(i).origin===new URL(e).origin}catch{return!1}}function dt(i){try{typeof localStorage<"u"&&(localStorage.setItem(ot,i.toString()),z=i)}catch{}}function at(i=Date.now()){return V>0&&i-V<=st}function de(){let i=Date.now(),e=!!D&&!at(i);if(V=i,e){D=null;for(let t of In)t();return}!Z||!D||z===0||i-z<bn||dt(i)}function vn(){return!D||Z&&z===0}function En(){if(rt||typeof window>"u")return;rt=!0;let i=()=>de();for(let e of mn)window.addEventListener(e,i,{passive:!0,capture:!0});typeof document<"u"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&de()})}function Ae(){let i=Date.now(),e=!!D&&at(i);try{if(Z&&typeof localStorage<"u"){let t=localStorage.getItem(it),n=localStorage.getItem(ot),r=n&&parseInt(n,10)||0;if(t&&r&&i-r<=st)return(D!==t||V<r)&&(D=t,V=Math.max(V,r)),z===0&&(z=r),t;let o=e?D:X();return e||(V=i),localStorage.setItem(it,o),dt(V),D=o,o}}catch{}return e||(D=X(),V=i),D}function l(i){return String(i??"").replace(/%/g,"%25").replace(/:/g,"%3A")}function Tn(i,e){switch(i){case"auctionInit":return`auctionInit:${l(e?.auctionId)}`;case"auctionEnd":return`auctionEnd:${l(e?.auctionId)}`;case"bidRequested":{let t=Array.isArray(e?.bids)?e.bids.map(n=>l(n?.bidId||n?.transactionId||n?.adUnitCode)).join(","):"";return`bidRequested:${l(e?.auctionId)}:${l(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:${l(t.auctionId)}:${l(t.adUnitCode)}:${l(t.bidderCode||t.bidder)}:${l(n)}:${l(r)}`}case"bidTimeout":return"bidTimeout:"+(Array.isArray(e)?e:e?[e]:[]).map(n=>`${l(n?.auctionId)}:${l(n?.bidderCode||n?.bidder)}:${l(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:${l(t.auctionId)}:${l(t.adUnitCode)}:${l(t.bidderCode||t.bidder)}:${l(n)}:${l(r)}`}case"noBid":return`noBid:${l(e?.auctionId)}:${l(e?.adUnitCode)}:${l(e?.bidderCode||e?.bidder)}:${l(e?.bidId||e?.transactionId)}`;case"adRenderFailed":{let t=e?.bid||{};return`adRenderFailed:${l(t.auctionId||e?.auctionId)}:${l(t.adUnitCode||e?.adUnitCode)}:${l(t.bidderCode||t.bidder||e?.bidderCode||e?.bidder)}:${l(e?.reason)}:${l(e?.message)}`}case"adRenderSucceeded":{let t=e?.bid||e||{},n=t.creativeId||t.adId||e?.adId||"",r=t.originalCpm??t.cpm??"";return`adRenderSucceeded:${l(t.auctionId||e?.auctionId)}:${l(t.adUnitCode||e?.adUnitCode)}:${l(t.bidderCode||t.bidder)}:${l(n)}:${l(r)}`}case"setTargeting":return`setTargeting:${Object.keys(e||{}).sort().map(l).join(",")}`;case"auctionDebug":return`auctionDebug:${l(e?.type)}:${l(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 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 wn(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 _e(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?.()||"",u={pbjsGlobalName:i,...e,...s};if(a&&!yn(u.endpoint||"",a)&&(Y.warn(`Ignoring analytics endpoint change to ${u.endpoint||"(empty)"}: this page is pinned to ${a}. Reload to change the ingest endpoint.`),u.endpoint=a),d)try{d.disable()}catch(I){Y.warn("Failed to disable previous analytics instance:",I)}let c=new S(u);return c.enable(),t._bidkernelPrebidAnalytics=c,c},o=()=>{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 s=wn(t);s&&(s.propertyId||e?.propertyId)&&r(s)}catch(s){Y.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 qt,et,Kt,Gt,ee,Ht,Yt,we,tt,zt,nt,se,Xt,Qt,Zt,Jt,en,tn,nn,rn,G,on,sn,dn,an,cn,ln,it,ot,st,D,V,Z,bn,z,mn,rt,In,Ce,Y,S,Se=L(()=>{"use strict";xe();Te();Je();qt="bidkernel",et=1e4,Kt=50,Gt=20,ee=200,Ht=300*1e3,Yt=10,we=32*1024,tt=1024,zt=16,nt="text/plain",se="_bidkernel_pending_",Xt=20,Qt=7200*1e3,Zt=1e4,Jt={auctionStart:b.AUCTION_START,auctionEnd:b.AUCTION_END,bidWin:b.BID_WIN,adRenderFailed:b.AD_RENDER_FAILED,click:b.CLICK,impression:b.IMPRESSION,timeInView:b.TIME_IN_VIEW,viewable:b.VIEWABLE},en={WARN:b.WARN,ERROR:b.ERROR},tn=new Set([b.ERROR,b.WARN]),nn=3e3,rn=new Set([b.IMPRESSION,b.BID_WIN,b.CLICK]),G=1800*1e3,on=200,sn=1e3,dn=50,an=200,cn={static:oe.FLOOR_SOURCE_STATIC,pool:oe.FLOOR_SOURCE_POOL,none:oe.FLOOR_SOURCE_NONE},ln=1e3,it="_bidkernel_session",ot="_bidkernel_session_ts",st=1800*1e3,D=null,V=0,Z=!0;bn=60*1e3,z=0,mn=["pointerdown","pointermove","keydown","scroll","wheel","touchstart"],rt=!1,In=new Set;Ce=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=Tn(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}};Y=ue({prefix:"[analytics]",logLevel:"INFO"}),S=class i{static activeInstances=new Set;static allInstances=new Set;static getActiveInstances(){return i.activeInstances}static setLogLevel(e){let t=P(e);Y.setLevel(t);for(let n of i.allInstances)n.setLogLevel(t)}static getLogLevel(){return Y.getLevel()}static setStorageAllowed(e){Z=e,z=0}static isStorageAllowed(){return Z}config;queue=[];errorCount=0;flushTimer=null;boundFlushBeacon;boundVisibilityChange;isEnabled=!1;boundPbjsHandlers=[];pageUrl="";deduper=new Ce;consecutiveSendFailures=0;nextSendAllowedAt=0;replayedEventCount=0;revenueFlushTimer=null;persistedBatchKeys=[];persistedCleanupTimer=null;intersectionObserver=null;slotViewabilityRecords=new Map;elementToSlotId=new Map;slotRefreshIndices=new Map;slotAdSessionCounters=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;floorDecisions=new Map;recordedConsentKeys=new Set;consentCount=0;cmpDetach=null;logger;managesSessionId;constructor(e){e.storageAllowed!==void 0&&i.setStorageAllowed(e.storageAllowed);let t=e.endpoint||"",n=!t||hn(t)?t:"";this.config={endpoint:n,propertyId:e.propertyId||"",pageviewId:e.pageviewId||X(),sessionId:e.sessionId||"",userId:e.userId||"",deviceType:e.deviceType||"desktop",country:e.country||"",region:e.region||"",auctionEnabled:e.auctionEnabled??!0,warningsEnabled:e.warningsEnabled??!0,viewabilityEnabled:e.viewabilityEnabled??!0,storageAllowed:e.storageAllowed??!0,logLevel:e.logLevel?P(e.logLevel):Y.getLevel(),pbjsGlobalName:e.pbjsGlobalName||"pbjs",attachPbjsListeners:e.attachPbjsListeners??!0,revenueFlushDelayMs:Number.isFinite(e.revenueFlushDelayMs)&&e.revenueFlushDelayMs>=0?e.revenueFlushDelayMs:nn,alias:e.alias||qt},i.allInstances.add(this),this.logger=ue({prefix:"[analytics]",logLevel:this.config.logLevel}),de(),this.managesSessionId=!e.sessionId,this.managesSessionId&&(this.config.sessionId=Ae()),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()}setLogLevel(e){let t=P(e);this.config.logLevel=t,this.logger.setLevel(t),Y.setLevel(t)}getLogLevel(){return this.logger.getLevel()}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(),this.cmpDetach=this.attachCmp(),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),En(),this.flushTimer=setInterval(()=>this.flush(),et),this.resendPersistedBatches()}}}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,o]of Object.entries(n))t.onEvent(r,o),this.boundPbjsHandlers.push({event:r,handler:o});if(typeof t.getEvents=="function")try{let r=t.getEvents();if(Array.isArray(r)){let o=r.slice(this.replayedEventCount);if(this.replayedEventCount=r.length,o.length>0){this.log("DEBUG",`Replaying ${o.length} historical events from pbjs.getEvents()`);for(let s of o){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,u=n[d];u&&u(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.floorDecisions.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=[]}if(this.cmpDetach){try{this.cmpDetach()}catch{}this.cmpDetach=null}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)}})),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})}recordClick(e,t){if(!this.isEnabled||!e)return!1;let n=Date.now();if(n-(this.lastClickAt.get(e)||0)<ln)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 o=document.activeElement;o&&(o===e||e.contains(o))&&(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 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:"")||X(),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),s.dwellTimer&&(clearTimeout(s.dwellTimer),s.dwellTimer=null,s.dwellStartedAt=null);for(let c of s.thresholdListeners)c.fired=!1,c.timer&&(clearTimeout(c.timer),c.timer=null);s.viewableFired=!1,s.accumulatedTimeInViewMs=0;let u=typeof performance<"u"&&performance.now?performance.now():Date.now();if(s.lastEnteredViewAt=s.inView?u: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 c=s.mediaType==="video"?2e3:1e3;s.dwellStartedAt=u,s.dwellTimer=setTimeout(()=>{this.handleDwellComplete(s)},c),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 u=this.pendingViewableListeners.get(o)||new Set;this.pendingViewableListeners.delete(o);let c={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,viewableListeners:u};this.slotViewabilityRecords.set(o,c),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.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.slotAdSessionCounters.delete(e),this.slotLastAuctionIds.delete(e),this.pendingThresholdListeners.delete(e),this.pendingViewableListeners.delete(e);let t=`${l(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>G){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>G&&this.cachedWinningBids.delete(t);for(;this.cachedWinningBids.size>on;){let t=this.cachedWinningBids.keys().next();if(t.done)break;this.cachedWinningBids.delete(t.value)}}addImpressionKey(e){if(!this.slotEmittedImpressionKeys.has(e)){for(;this.slotEmittedImpressionKeys.size>=sn;){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>dn;){let n=this.auctionBidderOutcomes.keys().next();if(n.done||n.value===e)break;this.auctionBidderOutcomes.delete(n.value)}return t}nextSlotAdSession(e){let t=(this.slotAdSessionCounters.get(e)??0)+1;return this.slotAdSessionCounters.set(e,t),`ad-session-${t}`}hasImpressionEmitted(e,t,n,r,o){let s=t??this.slotRefreshIndices.get(e)??0,d=`${l(e)}:${s}`;if(o){if(n){if(this.slotEmittedImpressionKeys.has(`${d}:auc:${l(n)}:ad:${l(o)}`)||this.slotEmittedImpressionKeys.has(`${d}:ad:${l(o)}`))return!0}else if(this.slotEmittedImpressionKeys.has(`${d}:ad:${l(o)}`))return!0;if(r&&r!==o){if(n){if(this.slotEmittedImpressionKeys.has(`${d}:auc:${l(n)}:${l(r)}`)||this.slotEmittedImpressionKeys.has(`${d}:${l(r)}`))return!0}else if(this.slotEmittedImpressionKeys.has(`${d}:${l(r)}`))return!0}return!1}return r?n?this.slotEmittedImpressionKeys.has(`${d}:auc:${l(n)}:${l(r)}`)||this.slotEmittedImpressionKeys.has(`${d}:${l(r)}`):this.slotEmittedImpressionKeys.has(`${d}:${l(r)}`):n?this.slotEmittedImpressionKeys.has(`${d}:auc:${l(n)}`):this.slotEmittedImpressionKeys.has(d)}markImpressionEmitted(e,t,n,r,o){let s=`${l(e)}:${t}`;!!(o||r)?(o&&(this.addImpressionKey(`${s}:ad:${l(o)}`),n&&this.addImpressionKey(`${s}:auc:${l(n)}:ad:${l(o)}`)),r&&r!==o&&(this.addImpressionKey(`${s}:${l(r)}`),n&&this.addImpressionKey(`${s}:auc:${l(n)}:${l(r)}`)),n&&this.addImpressionKey(`${s}:auc:${l(n)}`)):(this.addImpressionKey(s),n&&this.addImpressionKey(`${s}:auc:${l(n)}`))}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||"",u=s.creativeId||o?.bidTrace?.creativeId||t?.bid?.creativeId||"",c=t?.adId||s.adId||t?.bid?.adId||"",I=t?.mediaType||s.mediaType||o?.bidTrace?.mediaType||"banner",g=n||r,f=(n?this.slotViewabilityRecords.get(n):void 0)||(r?this.slotViewabilityRecords.get(r):void 0),R=g?this.slotLastAuctionIds.get(g)||(f?f.auctionId:void 0):void 0,y=!!(g&&d&&R&&R!==d&&t?.refreshIndex===void 0),_={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:I,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(y&&g){this.flushSlotTimeInView(g);let v=(this.slotRefreshIndices.get(g)??(f?f.refreshIndex:0))+1;this.slotRefreshIndices.set(g,v),this.slotLastAuctionIds.set(g,d),f&&(f.refreshIndex=v,f.auctionId=d,f.transactionId=a,f.bidPayload=_,f.viewableFired=!1,f.accumulatedTimeInViewMs=0)}else g&&(d&&this.slotLastAuctionIds.set(g,d),this.slotRefreshIndices.has(g)||this.slotRefreshIndices.set(g,0));let B=t?.refreshIndex??(n?this.slotRefreshIndices.get(n)??(r?this.slotRefreshIndices.get(r):void 0)??(f?f.refreshIndex:0):0);return n&&this.hasImpressionEmitted(n,B,d,u,c)||r&&r!==n&&this.hasImpressionEmitted(r,B,d,u,c)?(this.log("DEBUG",`Impression already emitted for slot ${n||r} in cycle ${B}`),!1):(n&&this.markImpressionEmitted(n,B,d,u,c),r&&r!==n&&this.markImpressionEmitted(r,B,d,u,c),this.enqueue(b.IMPRESSION,"impression",{auctionId:d,transactionId:a,adUnitCode:r,bid:_,metadata:{...t?.metadata,refresh_index:String(B)}}),f&&(!f.bidPayload&&_&&(f.bidPayload=_),!f.auctionId&&d&&(f.auctionId=d),!f.transactionId&&a&&(f.transactionId=a)),!0)}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(u){this.log("ERROR","Error in threshold callback",u)}}}},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=en[e]??Jt[t];r!==void 0&&this.enqueue(r,t,n)}recordFloorDecision(e,t,n){if(!e||!t)return;let r=`${e}:${t}`;for(this.floorDecisions.delete(r),this.floorDecisions.set(r,{floorCents:n.floorCents!==void 0&&Number.isFinite(n.floorCents)?Math.round(n.floorCents):void 0,source:n.source,treatment:Number.isFinite(n.treatment)?n.treatment:1});this.floorDecisions.size>an;){let o=this.floorDecisions.keys().next();if(o.done)break;this.floorDecisions.delete(o.value)}}floorDecisionFor(e,t){return e&&t?this.floorDecisions.get(`${e}:${t}`):void 0}recordConsent(e){if(!this.isEnabled||!e)return!1;let t=`${e.regime}|${e.action}|${e.tcString??""}|${e.gppString??""}|${e.uspString??""}`;if(this.recordedConsentKeys.has(t))return!1;this.recordedConsentKeys.add(t);let n={},r=(o,s)=>{if(!(s==null||s===""))if(typeof s=="number"){if(!Number.isFinite(s))return;n[o]=String(s)}else if(typeof s=="boolean")n[o]=s?"true":"false";else if(Array.isArray(s)){if(s.length===0)return;n[o]=[...s].sort((d,a)=>d-a).join(",")}else typeof s=="string"&&(n[o]=s)};return r("regime",e.regime),r("action",e.action),r("cmp_id",e.cmpId),r("cmp_version",e.cmpVersion),r("gvl_version",e.gvlVersion),r("tc_string",e.tcString),r("ac_string",e.acString),r("gpp_string",e.gppString),r("usp_string",e.uspString),r("purposes_consented",e.purposesConsented),r("vendors_consented",e.vendorsConsented),r("vendors_total",e.vendorsTotal),r("language",e.language),r("opt_out",e.optOut),r("gpc",e.gpc),this.enqueue(b.CONSENT,"consent",{metadata:n}),!0}attachCmp(){if(typeof document>"u")return()=>{};let e=o=>{let s=o.detail;s&&this.recordConsent(s)};document.addEventListener("bidkernel:consent",e);let n=(typeof window<"u"?window:{})[this.config.alias]?.consent?.getRecord?.()||null;n&&this.recordConsent(n);let r=!1;return()=>{r||(r=!0,document.removeEventListener("bidkernel:consent",e))}}setUserId(e){this.config.userId=e}setSessionId(e){this.config.sessionId=e,this.managesSessionId=!e,this.managesSessionId&&(this.config.sessionId=Ae())}navigate(e,t){if(this.disable(),this.slotRefreshIndices.clear(),this.slotAdSessionCounters.clear(),this.floorDecisions.clear(),this.pendingThresholdListeners.clear(),this.recordedConsentKeys.clear(),this.consentCount=0,this.config.pageviewId=e||X(),t)try{let n=new URL(t);this.pageUrl=n.origin+n.pathname}catch{this.pageUrl=t}else this.pageUrl="";this.logger.resetTiming(),de(),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})}auctionCycleIndex(e){if(!e)return 0;let t=this.slotRefreshIndices.get(e)??this.slotViewabilityRecords.get(e)?.refreshIndex;return t===void 0?0:t+1}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",u=`${n}:${s}`;r.has(u)||r.set(u,{adUnitCode:s,outcome:F.BIDDER_OUTCOME_NO_RESPONSE,bid:{bidder:n,mediaType:a,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)return;let u=o>0?{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||""}:{bidder:n,mediaType:a,latencyMs:s};this.getOrCreateAuctionOutcomes(t).set(`${n}:${r}`,{adUnitCode:r,outcome:o>0?F.BIDDER_OUTCOME_BID:F.BIDDER_OUTCOME_NO_BID,bid:u})}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),u=`${o}:${s}`,c=a.get(u);c?(c.outcome=F.BIDDER_OUTCOME_TIMEOUT,d>0&&c.bid&&(c.bid.latencyMs=d)):a.set(u,{adUnitCode:s,outcome:F.BIDDER_OUTCOME_TIMEOUT,bid:{bidder:o,mediaType:"banner",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===F.BIDDER_OUTCOME_NO_RESPONSE&&(d.outcome=F.BIDDER_OUTCOME_NO_BID):o.set(s,{adUnitCode:r,outcome:F.BIDDER_OUTCOME_NO_BID,bid:{bidder:n,mediaType:"banner",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||"",u=(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),c=s==="video"||t.mediaType==="video"||t.mediaTypes?.video!==void 0||u?.bidTrace?.mediaType==="video"||u?.rawBid?.mediaType==="video"||n&&this.slotViewabilityRecords.get(n)?.mediaType==="video",I=c?"video":s||u?.bidTrace?.mediaType||"banner",g={bidder:t.bidderCode||t.bidder||u?.bidTrace?.bidder||"",cpm:Number.isFinite(t.originalCpm)?t.originalCpm:Number.isFinite(t.cpm)?t.cpm:u?.bidTrace?.cpm??0,currency:t.originalCurrency??t.currency??u?.bidTrace?.currency??"USD",...K(t).width?K(t):u?.bidTrace?{width:u.bidTrace.width,height:u.bidTrace.height}:K(t),dealId:t.dealId||u?.bidTrace?.dealId||"",mediaType:I,latencyMs:Number.isFinite(t.timeToRespond)?t.timeToRespond:u?.bidTrace?.latencyMs??0,advertiserDomain:t.meta?.advertiserDomains?.[0]||u?.bidTrace?.advertiserDomain||"",creativeId:t.creativeId||u?.bidTrace?.creativeId||""},f=r||u?.auctionId||"",R=o||u?.transactionId||"",y=n?this.slotViewabilityRecords.get(n):void 0,_=y&&f&&y.auctionId&&y.auctionId!==f;if(!!(n&&y&&_)){this.flushSlotTimeInView(n);let v=(this.slotRefreshIndices.get(n)??(y?y.refreshIndex:0))+1;this.slotRefreshIndices.set(n,v),this.slotLastAuctionIds.set(n,f),y&&(y.refreshIndex=v,y.auctionId=f,y.transactionId=R,y.bidPayload=g,y.viewableFired=!1,y.accumulatedTimeInViewMs=0)}else n&&(f&&this.slotLastAuctionIds.set(n,f),this.slotRefreshIndices.has(n)||this.slotRefreshIndices.set(n,0));let U=n?this.slotRefreshIndices.get(n)??(y?y.refreshIndex:0):0;if(c?this.log("DEBUG",`adRenderSucceeded received for video ad unit ${n||"unknown"}: suppressing IMPRESSION until verified video lifecycle event`):n&&this.hasImpressionEmitted(n,U,f,g.creativeId)||(n&&this.markImpressionEmitted(n,U,f,g.creativeId),this.enqueue(b.IMPRESSION,"impression",{auctionId:f,transactionId:R,adUnitCode:n,bid:g,metadata:{refresh_index:String(U)}})),this.config.viewabilityEnabled&&typeof document<"u"){let v=n&&this.slotElements.get(n)||null,T=n||e.adId||t.adId;if(!v&&T&&(v=document.getElementById(T)),!v&&typeof window<"u"&&window.googletag?.pubads)try{let M=window.googletag.pubads().getSlots();for(let m of M)if((m.getAdUnitPath?.()===n||m.getSlotElementId?.()===n)&&(v=document.getElementById(m.getSlotElementId()),v))break}catch{}if(!v&&T)try{for(let M of Array.from(document.querySelectorAll("[data-ad-slot]")))if(M.getAttribute("data-ad-slot")===T){v=M;break}}catch{}v&&this.observeSlot(v,n||T,{adUnitCode:n,auctionId:f,transactionId:R,mediaType:I,bid:g,refreshIndex:U})}}isDuplicate(e,t){return this.deduper.isDuplicate(e,t)}enqueue(e,t,n){if(!this.isEnabled||!this.shouldSample(e))return;this.managesSessionId&&vn()&&(this.config.sessionId=Ae());let r={eventId:q(X()),timestampMs:Date.now(),type:e,eventName:tn.has(e)?t:"",auctionId:q(String(n.auctionId||"")),transactionId:q(String(n.transactionId||"")),adUnitCode:n.adUnitCode||n.elementId||"",namespace:n.ns||n.namespace||""};n.bid&&(r.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&&(r.viewableDurationMs=Number.isFinite(n.viewableDurationMs)?n.viewableDurationMs:0),n.bidderOutcomes&&Array.isArray(n.bidderOutcomes)&&(r.bidderOutcomes=n.bidderOutcomes.map(d=>{let a=this.floorDecisionFor(String(n.auctionId||""),d.adUnitCode||"");return{...d,refreshIndex:d.refreshIndex??this.auctionCycleIndex(d.adUnitCode||""),...a?{floorCents:a.floorCents,floorSource:cn[a.source],floorTreatmentBp:Math.round(a.treatment*1e4)}:{}}}));let o={...n.metadata};if(e===b.BID_WIN||e===b.IMPRESSION){let d=this.floorDecisionFor(String(n.auctionId||""),r.adUnitCode||"");d&&(d.floorCents!==void 0&&(o.floor_cents=String(d.floorCents)),o.floor_source=d.source,o.floor_treatment=d.treatment.toFixed(2))}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 s=pn(o);Object.keys(s).length>0&&(r.metadata=s),this.queue.push(r),this.queue.length>=ee?(this.flush(),this.queue.length>ee&&this.queue.splice(0,this.queue.length-ee)):rn.has(e)&&this.revenueFlushTimer===null&&(this.revenueFlushTimer=setTimeout(()=>{this.revenueFlushTimer=null,this.flush()},this.config.revenueFlushDelayMs))}shouldSample(e){return e===b.ERROR?(this.errorCount++,this.errorCount<=Kt):e===b.CONSENT?(this.consentCount++,this.consentCount<=Gt):e===b.WARN?this.config.warningsEnabled:this.config.auctionEnabled}requeue(e){e.length&&(this.queue=e.concat(this.queue),this.queue.length>ee&&this.queue.splice(0,this.queue.length-ee))}drainBatch(){if(this.queue.length===0||!this.config.endpoint)return null;let e=typeof window<"u"?window.location.hostname:"",t=n=>({propertyId:q(this.config.propertyId),pageviewId:q(this.config.pageviewId),sessionId:q(this.config.sessionId),pageUrl:this.pageUrl,country:this.config.country,region:this.config.region,deviceType:this.config.deviceType,userId:q(this.config.userId),domain:e,events:n});for(;;){if(this.queue.length===0)return null;let n=this.queue,r=Ee.encode(t(n)).finish();for(;n.length>1&&r.byteLength>we;)n=n.slice(0,Math.floor(n.length/2)),r=Ee.encode(t(n)).finish();if(r.byteLength>we){let[o]=this.queue.splice(0,1);this.log("WARN",`Dropping oversized event (type ${o?.type}, ${r.byteLength} bytes exceeds the ${we}-byte cap on its own)`);continue}return this.queue=this.queue.slice(n.length),{url:this.batchUrl(),encoded:r,events:n}}}sendFetch(e,t=!1,n,r=!1){let o={method:"POST",headers:{"Content-Type":nt},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(et*2**(this.consecutiveSendFailures-1),Ht);this.nextSendAllowedAt=Date.now()+t,this.consecutiveSendFailures<=Yt?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()}batchUrl(){return`${this.config.endpoint}/${this.config.propertyId}`}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:nt});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`${se}${encodeURIComponent(this.config.propertyId)}_`}persistBatch(e){if(!Z)return null;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(se)&&t++}if(t>=Xt)return null;let n=`${this.pendingKeyPrefix()}${Date.now()}_${Math.floor(Math.random()*1e6)}`;return localStorage.setItem(n,un(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)},Zt))}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(se)||(o.startsWith(e)?t.push(o):gn(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>Qt)continue;let d;try{d=fn(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)}}});function An(i){let e=typeof i?.getError=="function"?i.getError():i?.error||i,t=a=>e&&typeof e[a]=="function"?e[a]():void 0,n=t("getMessage")||e?.message||String(e||"IMA ad error"),r=t("getErrorCode")??e?.code,o=t("getVastErrorCode"),s=t("getType")??e?.type,d={message:n};return r&&(d.error_code=String(r)),o&&(d.vast_error_code=String(o)),s&&(d.error_type=String(s)),{err:e,message:n,metadata:d}}function ht(i,e,t){let n=ae(i),{err:r,message:o,metadata:s}=An(e);return n.log("WARN","IMA AdErrorEvent received",e),n.enqueue(b.AD_RENDER_FAILED,"adRenderFailed",{auctionId:t.auctionId,transactionId:t.transactionId,adUnitCode:t.adUnitCode,bid:t.bid,metadata:{...t.metadata,reason:t.adStarted?"ima_playback_error":"ima_ad_error",playback_phase:t.adStarted?"post_start":"pre_start",...s},error:typeof r=="object"?r:new Error(o)}),r}function Cn(i,e){if(!i||typeof i!="object"||ct.has(i))return;ct.add(i);let t=typeof window<"u"&&window.google?.ima?.AdErrorEvent?.Type?.AD_ERROR||"adError";try{e.call(i,t,n=>{for(let r of S.getActiveInstances())try{let o=gt(r,{mediaType:"video"});ht(r,n,{adStarted:!1,adUnitCode:o?.adUnitCode||"video",auctionId:o?.auctionId,transactionId:o?.transactionId,bid:o?.bidTrace})}catch{}})}catch{}}function lt(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 S.getActiveInstances())try{s.attachImaAdsManager(o)}catch{}return o};n.__bidkernelHooked=!0,e.getAdsManager=n}}catch{}}function ut(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 S.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 S.getActiveInstances())try{o.attachImaAdsManager(this)}catch{}return t.apply(this,r)};n.__bidkernelHooked=!0,e.start=n}}catch{}}function ft(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(Cn(this,t),(r==="adsManagerLoaded"||r===(this?.AdsManagerLoadedEvent?.Type?.ADS_MANAGER_LOADED||"adsManagerLoaded"))&&typeof o=="function"){let d=Re.get(o);return d||(d=function(a){if(a&&typeof a.getAdsManager=="function"&&!a.getAdsManager.__bidkernelHooked){let u=a.getAdsManager;a.getAdsManager=function(...c){let I=u.apply(this,c);if(I)for(let g of S.getActiveInstances())try{g.attachImaAdsManager(I)}catch{}return I},a.getAdsManager.__bidkernelHooked=!0}return o.apply(this,arguments)},Re.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"?Re.get(o):void 0;return t.call(this,r,d||o,...s)};n.__bidkernelHooked=!0,e.removeEventListener=n}}catch{}}function te(i){if(!(!i||typeof i!="object"))try{i.AdsManagerLoadedEvent&&lt(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,lt(o)}})}catch{}}i.AdsLoader&&ft(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,ft(o)}})}catch{}}i.AdsManager&&ut(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,ut(o)}})}catch{}}}catch{}}function pt(){if(typeof window>"u")return;let i=window;if(i.google?.ima&&te(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,te(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&&te(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,te(s)}})}catch{}}}}})}catch{}}}function gt(i,e){let t=ae(i),n=Date.now(),r=d=>t.hasImpressionEmitted(d.adUnitCode,void 0,d.auctionId,d.bidTrace.creativeId);if(e?.creativeId||e?.adId){for(let d of Array.from(t.cachedWinningBids.values()))if(!(n-d.timestamp>G)&&(e.creativeId&&(d.bidTrace.creativeId===e.creativeId||d.rawBid?.creativeId===e.creativeId)||e.adId&&(d.rawBid?.adId===e.adId||d.adUnitCode===e.adId)))return d}let o;if(e?.mediaType){for(let a of Array.from(t.cachedWinningBids.values())){if(n-a.timestamp>G)continue;(a.bidTrace.mediaType===e.mediaType||a.rawBid?.mediaType===e.mediaType||e.mediaType==="video"&&a.rawBid?.mediaTypes?.video!==void 0)&&(r(a)||(!o||a.timestamp<o.timestamp)&&(o=a))}if(o)return o;let d;for(let a of Array.from(t.cachedWinningBids.values())){if(n-a.timestamp>G)continue;(a.bidTrace.mediaType===e.mediaType||a.rawBid?.mediaType===e.mediaType||e.mediaType==="video"&&a.rawBid?.mediaTypes?.video!==void 0)&&(!d||a.timestamp>d.timestamp)&&(d=a)}if(d)return d}for(let d of Array.from(t.cachedWinningBids.values()))n-d.timestamp>G||r(d)||(!o||d.timestamp>o.timestamp)&&(o=d);if(o)return o;let s;for(let d of Array.from(t.cachedWinningBids.values()))n-d.timestamp>G||(!s||d.timestamp>s.timestamp)&&(s=d);return s}function yt(i,e,t){let n=ae(i);if(!e||typeof e.addEventListener!="function")return n.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 r=e.__bidkernelAttachedInstances,o=r.get(i);if(o){if(!t)return()=>{};o()}let s=t?.slotId||t?.adUnitCode||"video",d=t?.adUnitCode||s,a=t?.auctionId||"",u=t?.transactionId||"",c=p=>{let h=(a?n.getCachedBid(`${a}:${d}`):void 0)||(a&&s!==d?n.getCachedBid(`${a}:${s}`):void 0)||(d!=="video"?n.getCachedBid(d):void 0)||(s!==d&&s!=="video"?n.getCachedBid(s):void 0);return h||(h=gt(i,{creativeId:p?.creativeId,adId:p?.adId,mediaType:"video"})),h},I=!1,g=null,f=p=>{let h=typeof n.nextSlotAdSession=="function"?n.nextSlotAdSession(s):`ad-session-${(n.slotAdSessionCounters?.get(s)??0)+1}`;if(n.slotAdSessionCounters&&typeof n.nextSlotAdSession!="function"){let N=(n.slotAdSessionCounters.get(s)??0)+1;n.slotAdSessionCounters.set(s,N)}let E=(typeof p?.getAdId=="function"?p.getAdId():p?.adId??p?.id)||"",H=(typeof p?.getCreativeId=="function"?p.getCreativeId():p?.creativeId)||"";return g={sessionId:h,adId:E||void 0,creativeId:H||void 0},g},R=p=>{let h=typeof p?.getAd=="function"?p.getAd():p?.ad;f(h),n.log("DEBUG","IMA AdEvent.LOADED received",{slotId:s,activeAdSession:g})},y=p=>{I=!0;let h=typeof p?.getAd=="function"?p.getAd():p?.ad,E={};h&&(E.creativeId=(typeof h.getCreativeId=="function"?h.getCreativeId():h.creativeId)||"",E.adId=(typeof h.getAdId=="function"?h.getAdId():h.id)||"",E.title=(typeof h.getTitle=="function"?h.getTitle():h.title)||"",E.duration=typeof h.getDuration=="function"?h.getDuration():h.duration,E.advertiserName=typeof h.getAdvertiserName=="function"?h.getAdvertiserName():""),!g||E.adId&&g.adId&&g.adId!==E.adId?f(h):(!g.adId&&E.adId&&(g.adId=E.adId),!g.creativeId&&E.creativeId&&(g.creativeId=E.creativeId));let H=g||f(h),N=c(E),ce=t?.slotId&&t.slotId!=="video"?t.slotId:t?.adUnitCode&&t.adUnitCode!=="video"?t.adUnitCode:N?.adUnitCode||t?.slotId||t?.adUnitCode||"video",It=t?.adUnitCode&&t.adUnitCode!=="video"?t.adUnitCode:N?.adUnitCode||ce,vt=a||N?.auctionId||"",Et=u||N?.transactionId||"",Le=H.creativeId||E.creativeId||N?.bidTrace?.creativeId||t?.bid?.creativeId||"",Tt=H.adId||E.adId||Le||H.sessionId,Oe={...N?.rawBid||t?.bid,mediaType:"video",creativeId:Le},Be=n.recordImpression(ce,{adUnitCode:It,auctionId:vt,transactionId:Et,mediaType:"video",bid:Oe,adId:Tt,metadata:{...t?.metadata,media_type:"video",...E.title?{ad_title:E.title}:{},...Number.isFinite(E.duration)?{ad_duration_s:String(E.duration)}:{}}}),J=typeof p?.type=="string"?p.type:typeof p?.getType=="function"?p.getType():typeof p=="string"?p:"";J.toLowerCase().startsWith("adevent.")&&(J=J.slice(8));let wt=J?J.toUpperCase():"STARTED/IMPRESSION";if(n.log("DEBUG",`IMA AdEvent.${wt} received${Be?"":" (second event for this ad, already counted)"}`,p),Be&&t?.onImpression)try{t.onImpression(ce,{ad:h,bid:Oe})}catch(At){n.log("ERROR","Error in onImpression callback",At)}},_=p=>{if(n.log("DEBUG",`IMA AdEvent milestone: ${p}`),t?.onMilestone)try{t.onMilestone(p,s)}catch(h){n.log("ERROR","Error in onMilestone callback",h)}},B=p=>{n.log("DEBUG","IMA AdEvent.CLICK received",p);let h=c(),E=t?.adUnitCode&&t.adUnitCode!=="video"?t.adUnitCode:h?.adUnitCode||s;n.enqueue(b.CLICK,"click",{auctionId:a||h?.auctionId,transactionId:u||h?.transactionId,adUnitCode:E,bid:h?.bidTrace||t?.bid,metadata:{...t?.metadata,media_type:"video"}})},U=p=>{g=null;let h=c(),E=t?.adUnitCode&&t.adUnitCode!=="video"?t.adUnitCode:h?.adUnitCode||s,H=ht(i,p,{adStarted:I,adUnitCode:E,auctionId:a||h?.auctionId,transactionId:u||h?.transactionId,bid:h?.bidTrace||t?.bid,metadata:t?.metadata});if(t?.onError)try{t.onError(H)}catch(N){n.log("ERROR","Error in onError callback",N)}},v=typeof window<"u"?window.google?.ima:void 0,T=v?.AdEvent?.Type||{},M=v?.AdErrorEvent?.Type||{},m=[{type:T.LOADED||"loaded",handler:R},{type:T.STARTED||"started",handler:y},{type:T.IMPRESSION||"impression",handler:y},{type:T.FIRST_QUARTILE||"firstQuartile",handler:()=>_("firstQuartile")},{type:T.MIDPOINT||"midpoint",handler:()=>_("midpoint")},{type:T.THIRD_QUARTILE||"thirdQuartile",handler:()=>_("thirdQuartile")},{type:T.COMPLETE||"complete",handler:()=>{g=null,_("complete")}},{type:T.ALL_ADS_COMPLETED||"allAdsCompleted",handler:()=>{g=null}},{type:T.CLICK||"click",handler:B},{type:M.AD_ERROR||"adError",handler:U}],A=new Set,w=[];for(let p of m)A.has(p.type)||(A.add(p.type),w.push(p));for(let{type:p,handler:h}of w)try{e.addEventListener(p,h)}catch{}let x=()=>{g=null,r.delete(i);for(let{type:p,handler:h}of w)try{e.removeEventListener(p,h)}catch{}n.videoDetachCleanups.delete(x)};return r.set(i,x),n.videoDetachCleanups.add(x),x}function _n(i,e,t){let n=ae(i);if(!e)return n.log("WARN","attachVideoPlayer called with null/undefined target"),()=>{};let r=null;if(typeof e=="string"){if(typeof document<"u")try{r=document.querySelector(e)||document.getElementById(e)}catch{r=document.getElementById(e)}}else if(typeof HTMLElement<"u"&&e instanceof HTMLElement)r=e;else if(e&&typeof e=="object"&&e.nodeType===1)r=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 yt(i,e,t);e&&typeof e.addEventListener=="function"&&(r=e)}let o=t?.slotId||t?.adUnitCode||(r?r.id:"")||"video",s=t?.adUnitCode||o,d=t?.auctionId||"",a=t?.transactionId||"",u=()=>(d?n.getCachedBid(`${d}:${s}`):void 0)||(d&&o!==s?n.getCachedBid(`${d}:${o}`):void 0)||n.getCachedBid(s)||(o!==s?n.getCachedBid(o):void 0),c=null;r&&(r.tagName&&r.tagName.toLowerCase()==="video"?c=r:c=r.querySelector("video"));let I={q1:!1,q2:!1,q3:!1,q4:!1},g=m=>{let A=m||c||(r?.querySelector?r.querySelector("video"):null),w=u(),x={...w?.rawBid||t?.bid,mediaType:"video"};if(n.recordImpression(o,{adUnitCode:s,auctionId:d||w?.auctionId,transactionId:a||w?.transactionId,mediaType:"video",bid:x,metadata:{...t?.metadata,media_type:"video",...A&&Number.isFinite(A.duration)?{video_duration_s:String(Math.round(A.duration))}:{}}})&&t?.onImpression)try{t.onImpression(o,{element:A||r,bid:x})}catch(h){n.log("ERROR","Error in onImpression callback",h)}},f=m=>{n.log("DEBUG","HTML5 video playing event received");let A=m?.target instanceof HTMLVideoElement?m.target:c;g(A)},R=m=>{let A=m?.target instanceof HTMLVideoElement?m.target:c;if(A&&A.currentTime>0&&(g(A),Number.isFinite(A.duration)&&A.duration>0)){let w=A.currentTime/A.duration;w>=.25&&!I.q1&&(I.q1=!0,t?.onMilestone?.("firstQuartile",o)),w>=.5&&!I.q2&&(I.q2=!0,t?.onMilestone?.("midpoint",o)),w>=.75&&!I.q3&&(I.q3=!0,t?.onMilestone?.("thirdQuartile",o))}},y=()=>{I.q4||(I.q4=!0,t?.onMilestone?.("complete",o))},_=m=>{let w=(m?.target instanceof HTMLVideoElement?m.target:c)?.error||c?.error,x=u(),p=w?`HTML5 video error code ${w.code}: ${w.message}`:"Video playback error";if(n.log("WARN",p),n.enqueue(b.AD_RENDER_FAILED,"adRenderFailed",{auctionId:d||x?.auctionId,transactionId:a||x?.transactionId,adUnitCode:s,bid:x?.bidTrace||t?.bid,metadata:{...t?.metadata,reason:"html5_video_error",message:p,...w?.code?{error_code:String(w.code)}:{}},error:w?new Error(p):void 0}),t?.onError)try{t.onError(w)}catch(h){n.log("ERROR","Error in onError callback",h)}},B=m=>{m.addEventListener("playing",f),m.addEventListener("play",f),m.addEventListener("timeupdate",R),m.addEventListener("ended",y),m.addEventListener("error",_)},U=m=>{m.removeEventListener("playing",f),m.removeEventListener("play",f),m.removeEventListener("timeupdate",R),m.removeEventListener("ended",y),m.removeEventListener("error",_)},v=null;r&&r!==c&&(r.addEventListener("playing",f,!0),r.addEventListener("play",f,!0),r.addEventListener("timeupdate",R,!0),r.addEventListener("ended",y,!0),r.addEventListener("error",_,!0)),c&&B(c),r&&r.tagName?.toLowerCase()!=="video"&&typeof MutationObserver<"u"&&(v=new MutationObserver(()=>{let m=r.querySelector("video");m&&m!==c&&(c&&U(c),c=m,c&&B(c))}),v.observe(r,{childList:!0,subtree:!0}));let T=u();t?.trackViewability!==!1&&r&&n.observeSlot(r,o,{adUnitCode:s,auctionId:d||T?.auctionId,transactionId:a||T?.transactionId,mediaType:"video",bid:T?.bidTrace||t?.bid,metadata:t?.metadata});let M=()=>{v&&(v.disconnect(),v=null),r&&r!==c&&(r.removeEventListener("playing",f,!0),r.removeEventListener("play",f,!0),r.removeEventListener("timeupdate",R,!0),r.removeEventListener("ended",y,!0),r.removeEventListener("error",_,!0)),c&&U(c),n.videoDetachCleanups.delete(M)};return n.videoDetachCleanups.add(M),M}var ae,Re,ct,Sn,bt=L(()=>{"use strict";Se();Te();ae=i=>i,Re=new WeakMap,ct=new WeakSet;typeof window<"u"&&pt();S.prototype.attachImaAdsManager=function(i,e){return yt(this,i,e)};S.prototype.attachVideoPlayer=function(i,e){return _n(this,i,e)};Sn=S.prototype.enable;S.prototype.enable=function(){Sn.call(this),typeof window<"u"&&(pt(),window.google?.ima&&te(window.google.ima))}});var Ln=Ct(()=>{Se();bt();var mt="https://by.bidkernel.io/t",Rn=window._bidkernelPbjsGlobal||"pbjs";_e(Rn,{endpoint:mt});window.bidkernelPrebidAnalytics={...window.bidkernelPrebidAnalytics,register:(i,e)=>_e(i,{endpoint:mt,...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},setLogLevel:i=>{S.setLogLevel(i)},getLogLevel:()=>S.getLogLevel()}});return Ln();})();
package/dist/index.d.mts CHANGED
@@ -71,6 +71,28 @@ interface AnalyticsConfig {
71
71
  * 0 sends on the next tick. Defaults to 3000.
72
72
  */
73
73
  revenueFlushDelayMs?: number;
74
+ /** Window global alias for the CMP instance. Defaults to "bidkernel". */
75
+ alias?: string;
76
+ }
77
+ /**
78
+ * Canonical consent record shape from edge/src/cmp/types.ts.
79
+ */
80
+ interface ConsentRecord {
81
+ regime: "tcf" | "us";
82
+ action: "accept_all" | "reject_all" | "save" | "withdraw" | "replay" | "opt_out" | "opt_in" | "gpc";
83
+ cmpId: number;
84
+ cmpVersion: number;
85
+ gvlVersion?: number;
86
+ tcString?: string | null;
87
+ acString?: string | null;
88
+ gppString?: string | null;
89
+ uspString?: string | null;
90
+ purposesConsented?: number[];
91
+ vendorsConsented?: number;
92
+ vendorsTotal?: number;
93
+ language?: string;
94
+ optOut?: boolean;
95
+ gpc?: boolean;
74
96
  }
75
97
  interface SlotObserveOptions {
76
98
  adUnitCode?: string;
@@ -96,6 +118,7 @@ interface SlotViewabilityState {
96
118
  timeInViewMs: number;
97
119
  refreshIndex: number;
98
120
  }
121
+ declare const DEFAULT_ALIAS = "bidkernel";
99
122
  declare const CACHED_BID_TTL_MS: number;
100
123
  /** A Live Floors decision for one auction and ad unit, as the wrapper reports it. */
101
124
  interface FloorDecision {
@@ -203,6 +226,9 @@ declare class BidkernelPrebidAnalytics {
203
226
  private videoDetachCleanups;
204
227
  private auctionBidderOutcomes;
205
228
  private floorDecisions;
229
+ private recordedConsentKeys;
230
+ private consentCount;
231
+ private cmpDetach;
206
232
  private logger;
207
233
  private managesSessionId;
208
234
  constructor(config: AnalyticsConfig);
@@ -304,6 +330,16 @@ declare class BidkernelPrebidAnalytics {
304
330
  */
305
331
  recordFloorDecision(auctionId: string, adUnitCode: string, decision: FloorDecision): void;
306
332
  private floorDecisionFor;
333
+ /**
334
+ * Enqueues one CONSENT event with the record flattened into metadata under snake_case keys.
335
+ * Deduped on regime|action|tcString|gppString|uspString per pageview.
336
+ */
337
+ recordConsent(record: ConsentRecord): boolean;
338
+ /**
339
+ * Subscribes to bidkernel:consent on document, and replays the current CMP record if one
340
+ * is available from the configured alias. Returns a detach function.
341
+ */
342
+ attachCmp(): () => void;
307
343
  setUserId(userId: string): void;
308
344
  setSessionId(sessionId: string): void;
309
345
  navigate(pageviewId: string, pageUrl: string): void;
@@ -494,4 +530,4 @@ interface AdsGlobal {
494
530
  */
495
531
  declare function getbidkernel(alias?: string): AdsGlobal;
496
532
 
497
- export { type AdsGlobal, type AnalyticsConfig, BidkernelPrebidAnalytics, CACHED_BID_TTL_MS, type CachedWinningBid, type FloorDecision, ImaAdsManagerStub, LogLevel, PrebidEventDeduper, type SizeMapping, type SlotConfig, type SlotObserveOptions, type SlotSize, type SlotSizes, type SlotViewabilityState, type VideoPlayerOptions, attachImaAdsManager, attachVideoPlayer, getOrCreateSessionId, getPrebidEventKey, getbidkernel, hookImaPrototype, initImaInterception, isSessionActive, isTrustedEndpoint, normalizeImaEventName, normalizeLogLevel, onSessionResume, registerPrebidAnalytics };
533
+ export { type AdsGlobal, type AnalyticsConfig, BidkernelPrebidAnalytics, CACHED_BID_TTL_MS, type CachedWinningBid, type ConsentRecord, DEFAULT_ALIAS, type FloorDecision, ImaAdsManagerStub, LogLevel, PrebidEventDeduper, type SizeMapping, type SlotConfig, type SlotObserveOptions, type SlotSize, type SlotSizes, type SlotViewabilityState, type VideoPlayerOptions, attachImaAdsManager, attachVideoPlayer, getOrCreateSessionId, getPrebidEventKey, getbidkernel, hookImaPrototype, initImaInterception, isSessionActive, isTrustedEndpoint, normalizeImaEventName, normalizeLogLevel, onSessionResume, registerPrebidAnalytics };
package/dist/index.d.ts CHANGED
@@ -71,6 +71,28 @@ interface AnalyticsConfig {
71
71
  * 0 sends on the next tick. Defaults to 3000.
72
72
  */
73
73
  revenueFlushDelayMs?: number;
74
+ /** Window global alias for the CMP instance. Defaults to "bidkernel". */
75
+ alias?: string;
76
+ }
77
+ /**
78
+ * Canonical consent record shape from edge/src/cmp/types.ts.
79
+ */
80
+ interface ConsentRecord {
81
+ regime: "tcf" | "us";
82
+ action: "accept_all" | "reject_all" | "save" | "withdraw" | "replay" | "opt_out" | "opt_in" | "gpc";
83
+ cmpId: number;
84
+ cmpVersion: number;
85
+ gvlVersion?: number;
86
+ tcString?: string | null;
87
+ acString?: string | null;
88
+ gppString?: string | null;
89
+ uspString?: string | null;
90
+ purposesConsented?: number[];
91
+ vendorsConsented?: number;
92
+ vendorsTotal?: number;
93
+ language?: string;
94
+ optOut?: boolean;
95
+ gpc?: boolean;
74
96
  }
75
97
  interface SlotObserveOptions {
76
98
  adUnitCode?: string;
@@ -96,6 +118,7 @@ interface SlotViewabilityState {
96
118
  timeInViewMs: number;
97
119
  refreshIndex: number;
98
120
  }
121
+ declare const DEFAULT_ALIAS = "bidkernel";
99
122
  declare const CACHED_BID_TTL_MS: number;
100
123
  /** A Live Floors decision for one auction and ad unit, as the wrapper reports it. */
101
124
  interface FloorDecision {
@@ -203,6 +226,9 @@ declare class BidkernelPrebidAnalytics {
203
226
  private videoDetachCleanups;
204
227
  private auctionBidderOutcomes;
205
228
  private floorDecisions;
229
+ private recordedConsentKeys;
230
+ private consentCount;
231
+ private cmpDetach;
206
232
  private logger;
207
233
  private managesSessionId;
208
234
  constructor(config: AnalyticsConfig);
@@ -304,6 +330,16 @@ declare class BidkernelPrebidAnalytics {
304
330
  */
305
331
  recordFloorDecision(auctionId: string, adUnitCode: string, decision: FloorDecision): void;
306
332
  private floorDecisionFor;
333
+ /**
334
+ * Enqueues one CONSENT event with the record flattened into metadata under snake_case keys.
335
+ * Deduped on regime|action|tcString|gppString|uspString per pageview.
336
+ */
337
+ recordConsent(record: ConsentRecord): boolean;
338
+ /**
339
+ * Subscribes to bidkernel:consent on document, and replays the current CMP record if one
340
+ * is available from the configured alias. Returns a detach function.
341
+ */
342
+ attachCmp(): () => void;
307
343
  setUserId(userId: string): void;
308
344
  setSessionId(sessionId: string): void;
309
345
  navigate(pageviewId: string, pageUrl: string): void;
@@ -494,4 +530,4 @@ interface AdsGlobal {
494
530
  */
495
531
  declare function getbidkernel(alias?: string): AdsGlobal;
496
532
 
497
- export { type AdsGlobal, type AnalyticsConfig, BidkernelPrebidAnalytics, CACHED_BID_TTL_MS, type CachedWinningBid, type FloorDecision, ImaAdsManagerStub, LogLevel, PrebidEventDeduper, type SizeMapping, type SlotConfig, type SlotObserveOptions, type SlotSize, type SlotSizes, type SlotViewabilityState, type VideoPlayerOptions, attachImaAdsManager, attachVideoPlayer, getOrCreateSessionId, getPrebidEventKey, getbidkernel, hookImaPrototype, initImaInterception, isSessionActive, isTrustedEndpoint, normalizeImaEventName, normalizeLogLevel, onSessionResume, registerPrebidAnalytics };
533
+ export { type AdsGlobal, type AnalyticsConfig, BidkernelPrebidAnalytics, CACHED_BID_TTL_MS, type CachedWinningBid, type ConsentRecord, DEFAULT_ALIAS, type FloorDecision, ImaAdsManagerStub, LogLevel, PrebidEventDeduper, type SizeMapping, type SlotConfig, type SlotObserveOptions, type SlotSize, type SlotSizes, type SlotViewabilityState, type VideoPlayerOptions, attachImaAdsManager, attachVideoPlayer, getOrCreateSessionId, getPrebidEventKey, getbidkernel, hookImaPrototype, initImaInterception, isSessionActive, isTrustedEndpoint, normalizeImaEventName, normalizeLogLevel, onSessionResume, registerPrebidAnalytics };
package/dist/index.js CHANGED
@@ -22,6 +22,7 @@ var src_exports = {};
22
22
  __export(src_exports, {
23
23
  BidkernelPrebidAnalytics: () => BidkernelPrebidAnalytics,
24
24
  CACHED_BID_TTL_MS: () => CACHED_BID_TTL_MS,
25
+ DEFAULT_ALIAS: () => DEFAULT_ALIAS,
25
26
  ImaAdsManagerStub: () => ImaAdsManagerStub,
26
27
  LogLevel: () => LogLevel,
27
28
  PrebidEventDeduper: () => PrebidEventDeduper,
@@ -355,6 +356,15 @@ var TraceEventType = {
355
356
  * and were dropped for want of one, so warnings_enabled controlled nothing.
356
357
  */
357
358
  WARN: 17,
359
+ /**
360
+ * CONSENT - A visitor consent decision was recorded, whether or not consent was
361
+ * granted (accept_all, reject_all, save, withdraw, replay, opt_out,
362
+ * opt_in, gpc). Carries flattened metadata keys: regime, action, cmp_id,
363
+ * cmp_version, gvl_version, tc_string, ac_string, gpp_string, usp_string,
364
+ * purposes_consented, vendors_consented, vendors_total, language, opt_out,
365
+ * and gpc.
366
+ */
367
+ CONSENT: 19,
358
368
  UNRECOGNIZED: -1
359
369
  };
360
370
  var BidderOutcome = {
@@ -1038,8 +1048,10 @@ function idToBytes(id) {
1038
1048
  }
1039
1049
 
1040
1050
  // src/prebid-analytics.ts
1051
+ var DEFAULT_ALIAS = "bidkernel";
1041
1052
  var FLUSH_INTERVAL_MS = 1e4;
1042
1053
  var MAX_ERRORS_PER_SESSION = 50;
1054
+ var MAX_CONSENT_EVENTS_PER_PAGEVIEW = 20;
1043
1055
  var MAX_QUEUE_SIZE = 200;
1044
1056
  var MAX_SEND_BACKOFF_MS = 5 * 60 * 1e3;
1045
1057
  var MAX_CONSECUTIVE_SEND_FAILURES = 10;
@@ -1413,6 +1425,9 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
1413
1425
  auctionBidderOutcomes = /* @__PURE__ */ new Map();
1414
1426
  // Live Floors decisions: `${auctionId}:${adUnitCode}` -> decision (see recordFloorDecision)
1415
1427
  floorDecisions = /* @__PURE__ */ new Map();
1428
+ recordedConsentKeys = /* @__PURE__ */ new Set();
1429
+ consentCount = 0;
1430
+ cmpDetach = null;
1416
1431
  logger;
1417
1432
  // True when this instance owns its session id (none was supplied), so the
1418
1433
  // id follows the page-wide session as it lapses and restarts. An id the
@@ -1440,7 +1455,8 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
1440
1455
  logLevel: config.logLevel ? normalizeLogLevel(config.logLevel) : defaultLogger.getLevel(),
1441
1456
  pbjsGlobalName: config.pbjsGlobalName || "pbjs",
1442
1457
  attachPbjsListeners: config.attachPbjsListeners ?? true,
1443
- revenueFlushDelayMs: Number.isFinite(config.revenueFlushDelayMs) && config.revenueFlushDelayMs >= 0 ? config.revenueFlushDelayMs : REVENUE_FLUSH_DELAY_MS
1458
+ revenueFlushDelayMs: Number.isFinite(config.revenueFlushDelayMs) && config.revenueFlushDelayMs >= 0 ? config.revenueFlushDelayMs : REVENUE_FLUSH_DELAY_MS,
1459
+ alias: config.alias || DEFAULT_ALIAS
1444
1460
  };
1445
1461
  _BidkernelPrebidAnalytics.allInstances.add(this);
1446
1462
  this.logger = createLogger({
@@ -1494,6 +1510,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
1494
1510
  if (this.config.attachPbjsListeners) {
1495
1511
  this.attachPbjs();
1496
1512
  }
1513
+ this.cmpDetach = this.attachCmp();
1497
1514
  if (typeof window !== "undefined") {
1498
1515
  if (!this.pageUrl) {
1499
1516
  try {
@@ -1646,6 +1663,13 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
1646
1663
  }
1647
1664
  this.boundPbjsHandlers = [];
1648
1665
  }
1666
+ if (this.cmpDetach) {
1667
+ try {
1668
+ this.cmpDetach();
1669
+ } catch {
1670
+ }
1671
+ this.cmpDetach = null;
1672
+ }
1649
1673
  this.flush();
1650
1674
  }
1651
1675
  handleVisibilityChange() {
@@ -2454,6 +2478,78 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
2454
2478
  floorDecisionFor(auctionId, adUnitCode) {
2455
2479
  return auctionId && adUnitCode ? this.floorDecisions.get(`${auctionId}:${adUnitCode}`) : void 0;
2456
2480
  }
2481
+ /**
2482
+ * Enqueues one CONSENT event with the record flattened into metadata under snake_case keys.
2483
+ * Deduped on regime|action|tcString|gppString|uspString per pageview.
2484
+ */
2485
+ recordConsent(record) {
2486
+ if (!this.isEnabled || !record) return false;
2487
+ const dedupeKey = `${record.regime}|${record.action}|${record.tcString ?? ""}|${record.gppString ?? ""}|${record.uspString ?? ""}`;
2488
+ if (this.recordedConsentKeys.has(dedupeKey)) {
2489
+ return false;
2490
+ }
2491
+ this.recordedConsentKeys.add(dedupeKey);
2492
+ const metadata = {};
2493
+ const put = (key, value) => {
2494
+ if (value === void 0 || value === null || value === "") return;
2495
+ if (typeof value === "number") {
2496
+ if (!Number.isFinite(value)) return;
2497
+ metadata[key] = String(value);
2498
+ } else if (typeof value === "boolean") {
2499
+ metadata[key] = value ? "true" : "false";
2500
+ } else if (Array.isArray(value)) {
2501
+ if (value.length === 0) return;
2502
+ metadata[key] = [...value].sort((a, b) => a - b).join(",");
2503
+ } else if (typeof value === "string") {
2504
+ metadata[key] = value;
2505
+ }
2506
+ };
2507
+ put("regime", record.regime);
2508
+ put("action", record.action);
2509
+ put("cmp_id", record.cmpId);
2510
+ put("cmp_version", record.cmpVersion);
2511
+ put("gvl_version", record.gvlVersion);
2512
+ put("tc_string", record.tcString);
2513
+ put("ac_string", record.acString);
2514
+ put("gpp_string", record.gppString);
2515
+ put("usp_string", record.uspString);
2516
+ put("purposes_consented", record.purposesConsented);
2517
+ put("vendors_consented", record.vendorsConsented);
2518
+ put("vendors_total", record.vendorsTotal);
2519
+ put("language", record.language);
2520
+ put("opt_out", record.optOut);
2521
+ put("gpc", record.gpc);
2522
+ this.enqueue(TraceEventType.CONSENT, "consent", { metadata });
2523
+ return true;
2524
+ }
2525
+ /**
2526
+ * Subscribes to bidkernel:consent on document, and replays the current CMP record if one
2527
+ * is available from the configured alias. Returns a detach function.
2528
+ */
2529
+ attachCmp() {
2530
+ if (typeof document === "undefined") {
2531
+ return () => {
2532
+ };
2533
+ }
2534
+ const handler = (evt) => {
2535
+ const detail = evt.detail;
2536
+ if (detail) {
2537
+ this.recordConsent(detail);
2538
+ }
2539
+ };
2540
+ document.addEventListener("bidkernel:consent", handler);
2541
+ const win = typeof window !== "undefined" ? window : {};
2542
+ const existingRecord = win[this.config.alias]?.consent?.getRecord?.() || null;
2543
+ if (existingRecord) {
2544
+ this.recordConsent(existingRecord);
2545
+ }
2546
+ let detached = false;
2547
+ return () => {
2548
+ if (detached) return;
2549
+ detached = true;
2550
+ document.removeEventListener("bidkernel:consent", handler);
2551
+ };
2552
+ }
2457
2553
  setUserId(userId) {
2458
2554
  this.config.userId = userId;
2459
2555
  }
@@ -2468,6 +2564,8 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
2468
2564
  this.slotAdSessionCounters.clear();
2469
2565
  this.floorDecisions.clear();
2470
2566
  this.pendingThresholdListeners.clear();
2567
+ this.recordedConsentKeys.clear();
2568
+ this.consentCount = 0;
2471
2569
  this.config.pageviewId = pageviewId || generateUUID();
2472
2570
  if (pageUrl) {
2473
2571
  try {
@@ -2913,6 +3011,10 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
2913
3011
  this.errorCount++;
2914
3012
  return this.errorCount <= MAX_ERRORS_PER_SESSION;
2915
3013
  }
3014
+ if (type === TraceEventType.CONSENT) {
3015
+ this.consentCount++;
3016
+ return this.consentCount <= MAX_CONSENT_EVENTS_PER_PAGEVIEW;
3017
+ }
2916
3018
  if (type === TraceEventType.WARN) {
2917
3019
  return this.config.warningsEnabled;
2918
3020
  }
@@ -4223,7 +4325,7 @@ var ImaAdsManagerStub = class {
4223
4325
  };
4224
4326
 
4225
4327
  // src/index.ts
4226
- function getbidkernel(alias = "bidkernel") {
4328
+ function getbidkernel(alias = DEFAULT_ALIAS) {
4227
4329
  if (typeof window === "undefined") {
4228
4330
  return { q: [] };
4229
4331
  }
@@ -4256,6 +4358,7 @@ function getbidkernel(alias = "bidkernel") {
4256
4358
  0 && (module.exports = {
4257
4359
  BidkernelPrebidAnalytics,
4258
4360
  CACHED_BID_TTL_MS,
4361
+ DEFAULT_ALIAS,
4259
4362
  ImaAdsManagerStub,
4260
4363
  LogLevel,
4261
4364
  PrebidEventDeduper,
package/dist/index.mjs CHANGED
@@ -312,6 +312,15 @@ var TraceEventType = {
312
312
  * and were dropped for want of one, so warnings_enabled controlled nothing.
313
313
  */
314
314
  WARN: 17,
315
+ /**
316
+ * CONSENT - A visitor consent decision was recorded, whether or not consent was
317
+ * granted (accept_all, reject_all, save, withdraw, replay, opt_out,
318
+ * opt_in, gpc). Carries flattened metadata keys: regime, action, cmp_id,
319
+ * cmp_version, gvl_version, tc_string, ac_string, gpp_string, usp_string,
320
+ * purposes_consented, vendors_consented, vendors_total, language, opt_out,
321
+ * and gpc.
322
+ */
323
+ CONSENT: 19,
315
324
  UNRECOGNIZED: -1
316
325
  };
317
326
  var BidderOutcome = {
@@ -995,8 +1004,10 @@ function idToBytes(id) {
995
1004
  }
996
1005
 
997
1006
  // src/prebid-analytics.ts
1007
+ var DEFAULT_ALIAS = "bidkernel";
998
1008
  var FLUSH_INTERVAL_MS = 1e4;
999
1009
  var MAX_ERRORS_PER_SESSION = 50;
1010
+ var MAX_CONSENT_EVENTS_PER_PAGEVIEW = 20;
1000
1011
  var MAX_QUEUE_SIZE = 200;
1001
1012
  var MAX_SEND_BACKOFF_MS = 5 * 60 * 1e3;
1002
1013
  var MAX_CONSECUTIVE_SEND_FAILURES = 10;
@@ -1370,6 +1381,9 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
1370
1381
  auctionBidderOutcomes = /* @__PURE__ */ new Map();
1371
1382
  // Live Floors decisions: `${auctionId}:${adUnitCode}` -> decision (see recordFloorDecision)
1372
1383
  floorDecisions = /* @__PURE__ */ new Map();
1384
+ recordedConsentKeys = /* @__PURE__ */ new Set();
1385
+ consentCount = 0;
1386
+ cmpDetach = null;
1373
1387
  logger;
1374
1388
  // True when this instance owns its session id (none was supplied), so the
1375
1389
  // id follows the page-wide session as it lapses and restarts. An id the
@@ -1397,7 +1411,8 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
1397
1411
  logLevel: config.logLevel ? normalizeLogLevel(config.logLevel) : defaultLogger.getLevel(),
1398
1412
  pbjsGlobalName: config.pbjsGlobalName || "pbjs",
1399
1413
  attachPbjsListeners: config.attachPbjsListeners ?? true,
1400
- revenueFlushDelayMs: Number.isFinite(config.revenueFlushDelayMs) && config.revenueFlushDelayMs >= 0 ? config.revenueFlushDelayMs : REVENUE_FLUSH_DELAY_MS
1414
+ revenueFlushDelayMs: Number.isFinite(config.revenueFlushDelayMs) && config.revenueFlushDelayMs >= 0 ? config.revenueFlushDelayMs : REVENUE_FLUSH_DELAY_MS,
1415
+ alias: config.alias || DEFAULT_ALIAS
1401
1416
  };
1402
1417
  _BidkernelPrebidAnalytics.allInstances.add(this);
1403
1418
  this.logger = createLogger({
@@ -1451,6 +1466,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
1451
1466
  if (this.config.attachPbjsListeners) {
1452
1467
  this.attachPbjs();
1453
1468
  }
1469
+ this.cmpDetach = this.attachCmp();
1454
1470
  if (typeof window !== "undefined") {
1455
1471
  if (!this.pageUrl) {
1456
1472
  try {
@@ -1603,6 +1619,13 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
1603
1619
  }
1604
1620
  this.boundPbjsHandlers = [];
1605
1621
  }
1622
+ if (this.cmpDetach) {
1623
+ try {
1624
+ this.cmpDetach();
1625
+ } catch {
1626
+ }
1627
+ this.cmpDetach = null;
1628
+ }
1606
1629
  this.flush();
1607
1630
  }
1608
1631
  handleVisibilityChange() {
@@ -2411,6 +2434,78 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
2411
2434
  floorDecisionFor(auctionId, adUnitCode) {
2412
2435
  return auctionId && adUnitCode ? this.floorDecisions.get(`${auctionId}:${adUnitCode}`) : void 0;
2413
2436
  }
2437
+ /**
2438
+ * Enqueues one CONSENT event with the record flattened into metadata under snake_case keys.
2439
+ * Deduped on regime|action|tcString|gppString|uspString per pageview.
2440
+ */
2441
+ recordConsent(record) {
2442
+ if (!this.isEnabled || !record) return false;
2443
+ const dedupeKey = `${record.regime}|${record.action}|${record.tcString ?? ""}|${record.gppString ?? ""}|${record.uspString ?? ""}`;
2444
+ if (this.recordedConsentKeys.has(dedupeKey)) {
2445
+ return false;
2446
+ }
2447
+ this.recordedConsentKeys.add(dedupeKey);
2448
+ const metadata = {};
2449
+ const put = (key, value) => {
2450
+ if (value === void 0 || value === null || value === "") return;
2451
+ if (typeof value === "number") {
2452
+ if (!Number.isFinite(value)) return;
2453
+ metadata[key] = String(value);
2454
+ } else if (typeof value === "boolean") {
2455
+ metadata[key] = value ? "true" : "false";
2456
+ } else if (Array.isArray(value)) {
2457
+ if (value.length === 0) return;
2458
+ metadata[key] = [...value].sort((a, b) => a - b).join(",");
2459
+ } else if (typeof value === "string") {
2460
+ metadata[key] = value;
2461
+ }
2462
+ };
2463
+ put("regime", record.regime);
2464
+ put("action", record.action);
2465
+ put("cmp_id", record.cmpId);
2466
+ put("cmp_version", record.cmpVersion);
2467
+ put("gvl_version", record.gvlVersion);
2468
+ put("tc_string", record.tcString);
2469
+ put("ac_string", record.acString);
2470
+ put("gpp_string", record.gppString);
2471
+ put("usp_string", record.uspString);
2472
+ put("purposes_consented", record.purposesConsented);
2473
+ put("vendors_consented", record.vendorsConsented);
2474
+ put("vendors_total", record.vendorsTotal);
2475
+ put("language", record.language);
2476
+ put("opt_out", record.optOut);
2477
+ put("gpc", record.gpc);
2478
+ this.enqueue(TraceEventType.CONSENT, "consent", { metadata });
2479
+ return true;
2480
+ }
2481
+ /**
2482
+ * Subscribes to bidkernel:consent on document, and replays the current CMP record if one
2483
+ * is available from the configured alias. Returns a detach function.
2484
+ */
2485
+ attachCmp() {
2486
+ if (typeof document === "undefined") {
2487
+ return () => {
2488
+ };
2489
+ }
2490
+ const handler = (evt) => {
2491
+ const detail = evt.detail;
2492
+ if (detail) {
2493
+ this.recordConsent(detail);
2494
+ }
2495
+ };
2496
+ document.addEventListener("bidkernel:consent", handler);
2497
+ const win = typeof window !== "undefined" ? window : {};
2498
+ const existingRecord = win[this.config.alias]?.consent?.getRecord?.() || null;
2499
+ if (existingRecord) {
2500
+ this.recordConsent(existingRecord);
2501
+ }
2502
+ let detached = false;
2503
+ return () => {
2504
+ if (detached) return;
2505
+ detached = true;
2506
+ document.removeEventListener("bidkernel:consent", handler);
2507
+ };
2508
+ }
2414
2509
  setUserId(userId) {
2415
2510
  this.config.userId = userId;
2416
2511
  }
@@ -2425,6 +2520,8 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
2425
2520
  this.slotAdSessionCounters.clear();
2426
2521
  this.floorDecisions.clear();
2427
2522
  this.pendingThresholdListeners.clear();
2523
+ this.recordedConsentKeys.clear();
2524
+ this.consentCount = 0;
2428
2525
  this.config.pageviewId = pageviewId || generateUUID();
2429
2526
  if (pageUrl) {
2430
2527
  try {
@@ -2870,6 +2967,10 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
2870
2967
  this.errorCount++;
2871
2968
  return this.errorCount <= MAX_ERRORS_PER_SESSION;
2872
2969
  }
2970
+ if (type === TraceEventType.CONSENT) {
2971
+ this.consentCount++;
2972
+ return this.consentCount <= MAX_CONSENT_EVENTS_PER_PAGEVIEW;
2973
+ }
2873
2974
  if (type === TraceEventType.WARN) {
2874
2975
  return this.config.warningsEnabled;
2875
2976
  }
@@ -4180,7 +4281,7 @@ var ImaAdsManagerStub = class {
4180
4281
  };
4181
4282
 
4182
4283
  // src/index.ts
4183
- function getbidkernel(alias = "bidkernel") {
4284
+ function getbidkernel(alias = DEFAULT_ALIAS) {
4184
4285
  if (typeof window === "undefined") {
4185
4286
  return { q: [] };
4186
4287
  }
@@ -4212,6 +4313,7 @@ function getbidkernel(alias = "bidkernel") {
4212
4313
  export {
4213
4314
  BidkernelPrebidAnalytics,
4214
4315
  CACHED_BID_TTL_MS,
4316
+ DEFAULT_ALIAS,
4215
4317
  ImaAdsManagerStub,
4216
4318
  LogLevel,
4217
4319
  PrebidEventDeduper,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bidkernel/analytics",
3
- "version": "0.32.0",
3
+ "version": "0.33.0",
4
4
  "description": "Bidkernel auction analytics: a standalone Prebid.js analytics adapter, plus TypeScript bindings for the Bidkernel ad SDK.",
5
5
  "keywords": [
6
6
  "advertising",