@bidkernel/analytics 0.4.0 → 0.5.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 h=(t,e)=>()=>(t&&(e=t(t=0)),e);var be=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);function G(){let t=0,e=0;for(let i=0;i<28;i+=7){let r=this.buf[this.pos++];if(t|=(r&127)<<i,(r&128)==0)return this.assertBounds(),[t,e]}let n=this.buf[this.pos++];if(t|=(n&15)<<28,e=(n&112)>>4,(n&128)==0)return this.assertBounds(),[t,e];for(let i=3;i<=31;i+=7){let r=this.buf[this.pos++];if(e|=(r&127)<<i,(r&128)==0)return this.assertBounds(),[t,e]}throw new Error("invalid varint")}function v(t,e,n){for(let s=0;s<28;s=s+7){let o=t>>>s,d=!(!(o>>>7)&&e==0),u=(d?o|128:o)&255;if(n.push(u),!d)return}let i=t>>>28&15|(e&7)<<4,r=e>>3!=0;if(n.push((r?i|128:i)&255),!!r){for(let s=3;s<31;s=s+7){let o=e>>>s,d=!!(o>>>7),u=(d?o|128:o)&255;if(n.push(u),!d)return}n.push(e>>>31&1)}}function R(t){let e=t[0]==="-";e&&(t=t.slice(1));let n=1e6,i=0,r=0;function s(o,d){let u=Number(t.slice(o,d));r*=n,i=i*n+u,i>=g&&(r=r+(i/g|0),i=i%g)}return s(-24,-18),s(-18,-12),s(-12,-6),s(-6),e?K(i,r):U(i,r)}function z(t,e){let n=U(t,e),i=n.hi&2147483648;i&&(n=K(n.lo,n.hi));let r=S(n.lo,n.hi);return i?"-"+r:r}function S(t,e){if({lo:t,hi:e}=Ie(t,e),e<=2097151)return String(g*e+t);let n=t&16777215,i=(t>>>24|e<<8)&16777215,r=e>>16&65535,s=n+i*6777216+r*6710656,o=i+r*8147497,d=r*2,u=1e7;return s>=u&&(o+=Math.floor(s/u),s%=u),o>=u&&(d+=Math.floor(o/u),o%=u),d.toString()+W(o)+W(s)}function Ie(t,e){return{lo:t>>>0,hi:e>>>0}}function U(t,e){return{lo:t|0,hi:e|0}}function K(t,e){return e=~e,t?t=~t+1:e+=1,U(t,e)}function N(t,e){if(t>=0){for(;t>127;)e.push(t&127|128),t=t>>>7;e.push(t)}else{for(let n=0;n<9;n++)e.push(t&127|128),t=t>>7;e.push(1)}}function Y(){let t=this.buf[this.pos++],e=t&127;if((t&128)==0)return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(t&127)<<7,(t&128)==0)return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(t&127)<<14,(t&128)==0)return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(t&127)<<21,(t&128)==0)return this.assertBounds(),e;t=this.buf[this.pos++],e|=(t&15)<<28;for(let n=5;(t&128)!==0&&n<10;n++)t=this.buf[this.pos++];if((t&128)!=0)throw new Error("invalid varint");return this.assertBounds(),e>>>0}var g,W,_=h(()=>{"use strict";g=4294967296;W=t=>{let e=String(t);return"0000000".slice(e.length)+e}});function Te(){let t=new DataView(new ArrayBuffer(8));if(typeof BigInt=="function"&&typeof t.getBigInt64=="function"&&typeof t.getBigUint64=="function"&&typeof t.setBigInt64=="function"&&typeof t.setBigUint64=="function"&&(!!globalThis.Deno||typeof process!="object"||typeof process.env!="object"||process.env.BUF_BIGINT_DISABLE!=="1")){let n=BigInt("-9223372036854775808"),i=BigInt("9223372036854775807"),r=BigInt("0"),s=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(o){let d=typeof o=="bigint"?o:BigInt(o);if(d>i||d<n)throw new Error(`invalid int64: ${o}`);return d},uParse(o){let d=typeof o=="bigint"?o:BigInt(o);if(d>s||d<r)throw new Error(`invalid uint64: ${o}`);return d},enc(o){return t.setBigInt64(0,this.parse(o),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},uEnc(o){return t.setBigInt64(0,this.uParse(o),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},dec(o,d){return t.setInt32(0,o,!0),t.setInt32(4,d,!0),t.getBigInt64(0,!0)},uDec(o,d){return t.setInt32(0,o,!0),t.setInt32(4,d,!0),t.getBigUint64(0,!0)}}}return{zero:"0",supported:!1,parse(n){return typeof n!="string"&&(n=n.toString()),j(n),n},uParse(n){return typeof n!="string"&&(n=n.toString()),H(n),n},enc(n){return typeof n!="string"&&(n=n.toString()),j(n),R(n)},uEnc(n){return typeof n!="string"&&(n=n.toString()),H(n),R(n)},dec(n,i){return z(n,i)},uDec(n,i){return S(n,i)}}}function j(t){if(!/^-?[0-9]+$/.test(t))throw new Error("invalid int64: "+t)}function H(t){if(!/^[0-9]+$/.test(t))throw new Error("invalid uint64: "+t)}var f,X=h(()=>{"use strict";_();f=Te()});function C(){if(globalThis[P]==null){let t=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[P]={encodeUtf8(n){return t.encode(n)},decodeUtf8(n){return e.decode(n)},checkUtf8(n){try{return encodeURIComponent(n),!0}catch{return!1}}}}return globalThis[P]}var P,M=h(()=>{"use strict";P=Symbol.for("@bufbuild/protobuf/text-encoding")});function F(t){if(typeof t=="string")t=Number(t);else if(typeof t!="number")throw new Error("invalid int32: "+typeof t);if(!Number.isInteger(t)||t>we||t<me)throw new Error("invalid int32: "+t)}function Q(t){if(typeof t=="string")t=Number(t);else if(typeof t!="number")throw new Error("invalid uint32: "+typeof t);if(!Number.isInteger(t)||t>ve||t<0)throw new Error("invalid uint32: "+t)}function xe(t){if(typeof t=="string"){let e=t;if(t=Number(t),Number.isNaN(t)&&e!=="NaN")throw new Error("invalid float32: "+e)}else if(typeof t!="number")throw new Error("invalid float32: "+typeof t);if(Number.isFinite(t)&&(t>Ee||t<ge))throw new Error("invalid float32: "+t)}var y,Ee,ge,ve,we,me,b,l,Z=h(()=>{"use strict";_();X();M();(function(t){t[t.Varint=0]="Varint",t[t.Bit64=1]="Bit64",t[t.LengthDelimited=2]="LengthDelimited",t[t.StartGroup=3]="StartGroup",t[t.EndGroup=4]="EndGroup",t[t.Bit32=5]="Bit32"})(y||(y={}));Ee=34028234663852886e22,ge=-34028234663852886e22,ve=4294967295,we=2147483647,me=-2147483648,b=class{constructor(e=C().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 n=new Uint8Array(e),i=0;for(let r=0;r<this.chunks.length;r++)n.set(this.chunks[r],i),i+=this.chunks[r].length;return this.chunks=[],n}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let e=this.finish(),n=this.stack.pop();if(!n)throw new Error("invalid state, fork stack empty");return this.chunks=n.chunks,this.buf=n.buf,this.uint32(e.byteLength),this.raw(e)}tag(e,n){return this.uint32((e<<3|n)>>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for(Q(e);e>127;)this.buf.push(e&127|128),e=e>>>7;return this.buf.push(e),this}int32(e){return F(e),N(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 n=this.encodeUtf8(e);return this.uint32(n.byteLength),this.raw(n)}float(e){xe(e);let n=new Uint8Array(4);return new DataView(n.buffer).setFloat32(0,e,!0),this.raw(n)}double(e){let n=new Uint8Array(8);return new DataView(n.buffer).setFloat64(0,e,!0),this.raw(n)}fixed32(e){Q(e);let n=new Uint8Array(4);return new DataView(n.buffer).setUint32(0,e,!0),this.raw(n)}sfixed32(e){F(e);let n=new Uint8Array(4);return new DataView(n.buffer).setInt32(0,e,!0),this.raw(n)}sint32(e){return F(e),e=(e<<1^e>>31)>>>0,N(e,this.buf),this}sfixed64(e){let n=new Uint8Array(8),i=new DataView(n.buffer),r=f.enc(e);return i.setInt32(0,r.lo,!0),i.setInt32(4,r.hi,!0),this.raw(n)}fixed64(e){let n=new Uint8Array(8),i=new DataView(n.buffer),r=f.uEnc(e);return i.setInt32(0,r.lo,!0),i.setInt32(4,r.hi,!0),this.raw(n)}int64(e){let n=f.enc(e);return v(n.lo,n.hi,this.buf),this}sint64(e){let n=f.enc(e),i=n.hi>>31,r=n.lo<<1^i,s=(n.hi<<1|n.lo>>>31)^i;return v(r,s,this.buf),this}uint64(e){let n=f.uEnc(e);return v(n.lo,n.hi,this.buf),this}},l=class{constructor(e,n=C().decodeUtf8){this.decodeUtf8=n,this.varint64=G,this.uint32=Y,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(),n=e>>>3,i=e&7;if(n<=0||i<0||i>5)throw new Error("illegal tag: field no "+n+" wire type "+i);return[n,i]}skip(e,n){let i=this.pos;switch(e){case y.Varint:for(;this.buf[this.pos++]&128;);break;case y.Bit64:this.pos+=4;case y.Bit32:this.pos+=4;break;case y.LengthDelimited:let r=this.uint32();this.pos+=r;break;case y.StartGroup:for(;;){let[s,o]=this.tag();if(o===y.EndGroup){if(n!==void 0&&s!==n)throw new Error("invalid end group tag");break}this.skip(o,s)}break;default:throw new Error("cant skip wire type "+e)}return this.assertBounds(),this.buf.subarray(i,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 f.dec(...this.varint64())}uint64(){return f.uDec(...this.varint64())}sint64(){let[e,n]=this.varint64(),i=-(e&1);return e=(e>>>1|(n&1)<<31)^i,n=n>>>1^i,f.dec(e,n)}bool(){let[e,n]=this.varint64();return e!==0||n!==0}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return f.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return f.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(),n=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(n,n+e)}string(){return this.decodeUtf8(this.bytes())}}});var J=h(()=>{"use strict"});var ee=h(()=>{"use strict"});var te=h(()=>{"use strict"});var ne=h(()=>{"use strict";Z();J();M();ee();te()});function ie(){return{propertyId:"",pageviewId:"",sessionId:"",pageUrl:"",country:"",region:"",deviceType:"",userId:"",domain:"",events:[],browser:"",deviceManufacturer:"",deviceModel:"",city:"",postalCode:""}}function re(){return{timestampMs:0,type:0,eventName:"",auctionId:"",transactionId:"",adUnitCode:"",bid:void 0,namespace:"",eventId:"",metadata:{},viewableDurationMs:void 0}}function se(){return{key:"",value:""}}function oe(){return{bidder:"",cpm:0,currency:"",width:0,height:0,dealId:"",mediaType:"",latencyMs:0,advertiserDomain:"",creativeId:""}}var c,x,w,O,m,ae=h(()=>{"use strict";ne();c={TRACE_EVENT_TYPE_UNSPECIFIED:0,AUCTION_START:1,AUCTION_END:2,BID_REQUEST:3,BID_RESPONSE:4,BID_WIN:5,BID_TIMEOUT:6,IMPRESSION:7,VIEWABLE:8,TIME_IN_VIEW:14,REFRESH:9,ERROR:10,SLOT_DEFINED:11,SLOT_DESTROYED:12,CLICK:13,NO_BID:15,AD_RENDER_FAILED:16,UNRECOGNIZED:-1};x={encode(t,e=new b){if(t.propertyId!==void 0&&t.propertyId!==""&&e.uint32(10).string(t.propertyId),t.pageviewId!==void 0&&t.pageviewId!==""&&e.uint32(18).string(t.pageviewId),t.sessionId!==void 0&&t.sessionId!==""&&e.uint32(26).string(t.sessionId),t.pageUrl!==void 0&&t.pageUrl!==""&&e.uint32(34).string(t.pageUrl),t.country!==void 0&&t.country!==""&&e.uint32(42).string(t.country),t.region!==void 0&&t.region!==""&&e.uint32(50).string(t.region),t.deviceType!==void 0&&t.deviceType!==""&&e.uint32(58).string(t.deviceType),t.userId!==void 0&&t.userId!==""&&e.uint32(66).string(t.userId),t.domain!==void 0&&t.domain!==""&&e.uint32(74).string(t.domain),t.events!==void 0&&t.events.length!==0)for(let n of t.events)w.encode(n,e.uint32(82).fork()).join();return t.browser!==void 0&&t.browser!==""&&e.uint32(90).string(t.browser),t.deviceManufacturer!==void 0&&t.deviceManufacturer!==""&&e.uint32(98).string(t.deviceManufacturer),t.deviceModel!==void 0&&t.deviceModel!==""&&e.uint32(106).string(t.deviceModel),t.city!==void 0&&t.city!==""&&e.uint32(114).string(t.city),t.postalCode!==void 0&&t.postalCode!==""&&e.uint32(122).string(t.postalCode),e},decode(t,e){let n=t instanceof l?t:new l(t),i=e===void 0?n.len:n.pos+e,r=ie();for(;n.pos<i;){let s=n.uint32();switch(s>>>3){case 1:{if(s!==10)break;r.propertyId=n.string();continue}case 2:{if(s!==18)break;r.pageviewId=n.string();continue}case 3:{if(s!==26)break;r.sessionId=n.string();continue}case 4:{if(s!==34)break;r.pageUrl=n.string();continue}case 5:{if(s!==42)break;r.country=n.string();continue}case 6:{if(s!==50)break;r.region=n.string();continue}case 7:{if(s!==58)break;r.deviceType=n.string();continue}case 8:{if(s!==66)break;r.userId=n.string();continue}case 9:{if(s!==74)break;r.domain=n.string();continue}case 10:{if(s!==82)break;let o=w.decode(n,n.uint32());o!==void 0&&r.events.push(o);continue}case 11:{if(s!==90)break;r.browser=n.string();continue}case 12:{if(s!==98)break;r.deviceManufacturer=n.string();continue}case 13:{if(s!==106)break;r.deviceModel=n.string();continue}case 14:{if(s!==114)break;r.city=n.string();continue}case 15:{if(s!==122)break;r.postalCode=n.string();continue}}if((s&7)===4||s===0)break;n.skip(s&7)}return r},create(t){return x.fromPartial(t??{})},fromPartial(t){let e=ie();return e.propertyId=t.propertyId??"",e.pageviewId=t.pageviewId??"",e.sessionId=t.sessionId??"",e.pageUrl=t.pageUrl??"",e.country=t.country??"",e.region=t.region??"",e.deviceType=t.deviceType??"",e.userId=t.userId??"",e.domain=t.domain??"",e.events=t.events?.map(n=>w.fromPartial(n))||[],e.browser=t.browser??"",e.deviceManufacturer=t.deviceManufacturer??"",e.deviceModel=t.deviceModel??"",e.city=t.city??"",e.postalCode=t.postalCode??"",e}};w={encode(t,e=new b){return t.timestampMs!==void 0&&t.timestampMs!==0&&e.uint32(9).double(t.timestampMs),t.type!==void 0&&t.type!==0&&e.uint32(16).int32(t.type),t.eventName!==void 0&&t.eventName!==""&&e.uint32(26).string(t.eventName),t.auctionId!==void 0&&t.auctionId!==""&&e.uint32(34).string(t.auctionId),t.transactionId!==void 0&&t.transactionId!==""&&e.uint32(42).string(t.transactionId),t.adUnitCode!==void 0&&t.adUnitCode!==""&&e.uint32(50).string(t.adUnitCode),t.bid!==void 0&&m.encode(t.bid,e.uint32(58).fork()).join(),t.namespace!==void 0&&t.namespace!==""&&e.uint32(66).string(t.namespace),t.eventId!==void 0&&t.eventId!==""&&e.uint32(74).string(t.eventId),globalThis.Object.entries(t.metadata||{}).forEach(([n,i])=>{O.encode({key:n,value:i},e.uint32(82).fork()).join()}),t.viewableDurationMs!==void 0&&e.uint32(89).double(t.viewableDurationMs),e},decode(t,e){let n=t instanceof l?t:new l(t),i=e===void 0?n.len:n.pos+e,r=re();for(;n.pos<i;){let s=n.uint32();switch(s>>>3){case 1:{if(s!==9)break;r.timestampMs=n.double();continue}case 2:{if(s!==16)break;r.type=n.int32();continue}case 3:{if(s!==26)break;r.eventName=n.string();continue}case 4:{if(s!==34)break;r.auctionId=n.string();continue}case 5:{if(s!==42)break;r.transactionId=n.string();continue}case 6:{if(s!==50)break;r.adUnitCode=n.string();continue}case 7:{if(s!==58)break;r.bid=m.decode(n,n.uint32());continue}case 8:{if(s!==66)break;r.namespace=n.string();continue}case 9:{if(s!==74)break;r.eventId=n.string();continue}case 10:{if(s!==82)break;let o=O.decode(n,n.uint32());o.value!==void 0&&(r.metadata[o.key]=o.value);continue}case 11:{if(s!==89)break;r.viewableDurationMs=n.double();continue}}if((s&7)===4||s===0)break;n.skip(s&7)}return r},create(t){return w.fromPartial(t??{})},fromPartial(t){let e=re();return e.timestampMs=t.timestampMs??0,e.type=t.type??0,e.eventName=t.eventName??"",e.auctionId=t.auctionId??"",e.transactionId=t.transactionId??"",e.adUnitCode=t.adUnitCode??"",e.bid=t.bid!==void 0&&t.bid!==null?m.fromPartial(t.bid):void 0,e.namespace=t.namespace??"",e.eventId=t.eventId??"",e.metadata=globalThis.Object.entries(t.metadata??{}).reduce((n,[i,r])=>(r!==void 0&&(n[i]=globalThis.String(r)),n),{}),e.viewableDurationMs=t.viewableDurationMs??void 0,e}};O={encode(t,e=new b){return t.key!==""&&e.uint32(10).string(t.key),t.value!==""&&e.uint32(18).string(t.value),e},decode(t,e){let n=t instanceof l?t:new l(t),i=e===void 0?n.len:n.pos+e,r=se();for(;n.pos<i;){let s=n.uint32();switch(s>>>3){case 1:{if(s!==10)break;r.key=n.string();continue}case 2:{if(s!==18)break;r.value=n.string();continue}}if((s&7)===4||s===0)break;n.skip(s&7)}return r},create(t){return O.fromPartial(t??{})},fromPartial(t){let e=se();return e.key=t.key??"",e.value=t.value??"",e}};m={encode(t,e=new b){return t.bidder!==void 0&&t.bidder!==""&&e.uint32(10).string(t.bidder),t.cpm!==void 0&&t.cpm!==0&&e.uint32(17).double(t.cpm),t.currency!==void 0&&t.currency!==""&&e.uint32(26).string(t.currency),t.width!==void 0&&t.width!==0&&e.uint32(32).int32(t.width),t.height!==void 0&&t.height!==0&&e.uint32(40).int32(t.height),t.dealId!==void 0&&t.dealId!==""&&e.uint32(50).string(t.dealId),t.mediaType!==void 0&&t.mediaType!==""&&e.uint32(58).string(t.mediaType),t.latencyMs!==void 0&&t.latencyMs!==0&&e.uint32(65).double(t.latencyMs),t.advertiserDomain!==void 0&&t.advertiserDomain!==""&&e.uint32(74).string(t.advertiserDomain),t.creativeId!==void 0&&t.creativeId!==""&&e.uint32(82).string(t.creativeId),e},decode(t,e){let n=t instanceof l?t:new l(t),i=e===void 0?n.len:n.pos+e,r=oe();for(;n.pos<i;){let s=n.uint32();switch(s>>>3){case 1:{if(s!==10)break;r.bidder=n.string();continue}case 2:{if(s!==17)break;r.cpm=n.double();continue}case 3:{if(s!==26)break;r.currency=n.string();continue}case 4:{if(s!==32)break;r.width=n.int32();continue}case 5:{if(s!==40)break;r.height=n.int32();continue}case 6:{if(s!==50)break;r.dealId=n.string();continue}case 7:{if(s!==58)break;r.mediaType=n.string();continue}case 8:{if(s!==65)break;r.latencyMs=n.double();continue}case 9:{if(s!==74)break;r.advertiserDomain=n.string();continue}case 10:{if(s!==82)break;r.creativeId=n.string();continue}}if((s&7)===4||s===0)break;n.skip(s&7)}return r},create(t){return m.fromPartial(t??{})},fromPartial(t){let e=oe();return e.bidder=t.bidder??"",e.cpm=t.cpm??0,e.currency=t.currency??"",e.width=t.width??0,e.height=t.height??0,e.dealId=t.dealId??"",e.mediaType=t.mediaType??"",e.latencyMs=t.latencyMs??0,e.advertiserDomain=t.advertiserDomain??"",e.creativeId=t.creativeId??"",e}}});function E(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function fe(){let t=Date.now();T=t;try{typeof localStorage<"u"&&localStorage.setItem(A,t.toString())}catch{}}function Ne(){let t=Date.now();try{if(typeof localStorage<"u"){let e=localStorage.getItem(ce),n=localStorage.getItem(A),i=n&&parseInt(n,10)||0;if(e&&i&&t-i<=ue)return localStorage.setItem(A,t.toString()),e;let r=E();return localStorage.setItem(ce,r),localStorage.setItem(A,t.toString()),r}}catch{}return D&&T&&t-T<=ue?(T=t,D):(D=E(),T=t,D)}function a(t){return String(t??"").replace(/%/g,"%25").replace(/:/g,"%3A")}function _e(t,e){switch(t){case"auctionInit":return`auctionInit:${a(e?.auctionId)}`;case"auctionEnd":return`auctionEnd:${a(e?.auctionId)}`;case"bidRequested":{let n=Array.isArray(e?.bids)?e.bids.map(i=>a(i?.bidId||i?.transactionId||i?.adUnitCode)).join(","):"";return`bidRequested:${a(e?.auctionId)}:${a(e?.bidderCode||e?.bidder)}:${n}`}case"bidResponse":{let n=e||{},i=n.creativeId||n.adId||n.requestId||n.bidId||"",r=n.originalCpm??n.cpm??"";return`bidResponse:${a(n.auctionId)}:${a(n.adUnitCode)}:${a(n.bidderCode||n.bidder)}:${a(i)}:${a(r)}`}case"bidTimeout":return"bidTimeout:"+(Array.isArray(e)?e:e?[e]:[]).map(i=>`${a(i?.auctionId)}:${a(i?.bidderCode||i?.bidder)}:${a(i?.bidId||i?.transactionId||i?.adUnitCode)}`).join(",");case"bidWon":{let n=e||{},i=n.creativeId||n.adId||n.requestId||n.bidId||"",r=n.originalCpm??n.cpm??"";return`bidWon:${a(n.auctionId)}:${a(n.adUnitCode)}:${a(n.bidderCode||n.bidder)}:${a(i)}:${a(r)}`}case"noBid":return`noBid:${a(e?.auctionId)}:${a(e?.adUnitCode)}:${a(e?.bidderCode||e?.bidder)}:${a(e?.bidId||e?.transactionId)}`;case"adRenderFailed":{let n=e?.bid||{};return`adRenderFailed:${a(n.auctionId||e?.auctionId)}:${a(n.adUnitCode||e?.adUnitCode)}:${a(n.bidderCode||n.bidder||e?.bidderCode||e?.bidder)}:${a(e?.reason)}:${a(e?.message)}`}case"adRenderSucceeded":{let n=e?.bid||e||{},i=n.creativeId||n.adId||e?.adId||"",r=n.originalCpm??n.cpm??"";return`adRenderSucceeded:${a(n.auctionId||e?.auctionId)}:${a(n.adUnitCode||e?.adUnitCode)}:${a(n.bidderCode||n.bidder)}:${a(i)}:${a(r)}`}case"setTargeting":return`setTargeting:${Object.keys(e||{}).sort().map(a).join(",")}`;case"auctionDebug":return`auctionDebug:${a(e?.type)}:${a(String(e?.arguments?.[0]??"").slice(0,50))}`;default:return""}}function le(t){if(!t)return{width:0,height:0};let e=t;for(;Array.isArray(e)&&e.length>0&&Array.isArray(e[0]);)e=e[0];if(Array.isArray(e)&&e.length>=2){let n=Number(e[0]),i=Number(e[1]);return{width:Number.isFinite(n)?n:0,height:Number.isFinite(i)?i:0}}return{width:0,height:0}}function L(t){if(Number.isFinite(t?.width)&&Number.isFinite(t?.height))return{width:t.width,height:t.height};if(typeof t?.size=="string"){let e=t.size.match(/^(\d+)x(\d+)$/);if(e)return{width:Number(e[1]),height:Number(e[2])}}return{width:Number.isFinite(t?.width)?t.width:0,height:Number.isFinite(t?.height)?t.height:0}}function I(t){if(!t)return null;if(Array.isArray(t)){let e=t.find(n=>n?.provider==="bidkernel")??t.find(n=>n&&typeof n=="object"&&n.provider===void 0);return e?I(e):null}if(typeof t=="object"){if(t.options&&typeof t.options=="object")return t.options;if(t.config&&typeof t.config=="object")return t.config;if(t.propertyId||t.endpoint)return t}return null}function Pe(t){if(!t)return null;if(t._bidkernelAnalyticsConfig){let e=I(t._bidkernelAnalyticsConfig);if(e)return e}if(t.bidkernelPrebidAnalytics){let e=t.bidkernelPrebidAnalytics;if(e.options){let n=I(e.options);if(n)return n}if(e.config){let n=I(e.config);if(n)return n}if(e.propertyId)return I(e)}return null}function V(t="pbjs",e){let n=typeof window<"u"?window:{};n[t]=n[t]||{};let i=n[t],r=o=>{if(n._bidkernelPrebidAnalytics)try{n._bidkernelPrebidAnalytics.disable()}catch(u){console.warn("[bidkernel] Failed to disable previous analytics instance:",u)}let d=new $({pbjsGlobalName:t,...e,...o});return d.enable(),n._bidkernelPrebidAnalytics=d,d},s=()=>{try{i.adapterManager&&typeof i.adapterManager.registerAnalyticsAdapter=="function"&&i.adapterManager.registerAnalyticsAdapter({adapter:{enableAnalytics:d=>{let u=I(d);u&&r(u)},disableAnalytics:()=>{n._bidkernelPrebidAnalytics&&n._bidkernelPrebidAnalytics.disable()}},code:"bidkernel"});let o=Pe(n);o&&(o.propertyId||e?.propertyId)&&r(o)}catch(o){console.warn("[bidkernel] Failed to register standard Prebid analytics adapter:",o)}};i.adapterManager&&typeof i.adapterManager.registerAnalyticsAdapter=="function"?s():(i.que=i.que||[],i.que.push(s))}var De,de,Ae,B,ke,Re,Se,Ue,ce,A,ue,D,T,q,$,he=h(()=>{"use strict";ae();De=20,de=1e4,Ae=50,B=200,ke=300*1e3,Re=10,Se=32*1024,Ue={auctionStart:c.AUCTION_START,auctionEnd:c.AUCTION_END,bidRequest:c.BID_REQUEST,bidResponse:c.BID_RESPONSE,bidTimeout:c.BID_TIMEOUT,bidWin:c.BID_WIN,noBid:c.NO_BID,adRenderFailed:c.AD_RENDER_FAILED,click:c.CLICK,impression:c.IMPRESSION,refresh:c.REFRESH,timeInView:c.TIME_IN_VIEW,viewable:c.VIEWABLE},ce="_bidkernel_session",A="_bidkernel_session_ts",ue=1800*1e3,D=null,T=0;q=class{seenObjects=new WeakMap;seenKeys=new Set;isDuplicate(e,n){if(!n)return!1;if(typeof n=="object"){let r=this.seenObjects.get(n);if(r){if(r.has(e))return!0;r.add(e)}else this.seenObjects.set(n,new Set([e]))}let i=_e(e,n);if(i){if(this.seenKeys.has(i))return!0;if(this.seenKeys.size>=1e3){let r=this.seenKeys.values().next().value;r!==void 0&&this.seenKeys.delete(r)}this.seenKeys.add(i)}return!1}};$=class{config;queue=[];errorCount=0;flushTimer=null;boundFlushBeacon;boundVisibilityChange;isEnabled=!1;boundPbjsHandlers=[];pageUrl="";deduper=new q;consecutiveSendFailures=0;nextSendAllowedAt=0;replayedEventCount=0;constructor(e){this.config={endpoint:e.endpoint||"",propertyId:e.propertyId||"",pageviewId:e.pageviewId||E(),sessionId:e.sessionId||Ne(),userId:e.userId||"",deviceType:e.deviceType||"desktop",country:e.country||"",region:e.region||"",auctionEnabled:e.auctionEnabled??!0,warningsEnabled:e.warningsEnabled??!0,errorsEnabled:e.errorsEnabled??!0,logLevel:e.logLevel||"INFO",pbjsGlobalName:e.pbjsGlobalName||"pbjs",attachPbjsListeners:e.attachPbjsListeners??!0},this.boundFlushBeacon=()=>this.flushBeacon(),this.boundVisibilityChange=()=>this.handleVisibilityChange()}enable(){if(!this.isEnabled){if(this.isEnabled=!0,this.config.endpoint||this.log("WARN","Endpoint is empty. Analytics events will not be transmitted."),this.config.attachPbjsListeners){let n=(typeof window<"u"?window:{})[this.config.pbjsGlobalName]||{};if(typeof n.onEvent=="function"){this.log("DEBUG","Attaching event listeners to pbjs");let i=[["auctionInit",this.handleAuctionInit.bind(this)],["auctionEnd",this.handleAuctionEnd.bind(this)],["bidRequested",this.handleBidRequested.bind(this)],["bidResponse",this.handleBidResponse.bind(this)],["bidTimeout",this.handleBidTimeout.bind(this)],["bidWon",this.handleBidWon.bind(this)],["noBid",this.handleNoBid.bind(this)],["adRenderFailed",this.handleAdRenderFailed.bind(this)],["adRenderSucceeded",this.handleAdRenderSucceeded.bind(this)]];for(let[r,s]of i)n.onEvent(r,s),this.boundPbjsHandlers.push({event:r,handler:s})}else this.log("WARN","pbjs.onEvent is not defined. Prebid analytics will not function.");if(typeof n.getEvents=="function")try{let i=n.getEvents();if(Array.isArray(i)){let r=i.slice(this.replayedEventCount);if(this.replayedEventCount=i.length,r.length>0){this.log("DEBUG",`Replaying ${r.length} historical events from pbjs.getEvents()`);let s={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 o of r){if(!o)continue;let d=o.eventType||o.event||o.name,u=o.args!==void 0?o.args:o.data!==void 0?o.data:o,p=s[d];p&&p(u)}}}}catch(i){this.log("WARN","Failed to replay historical events from pbjs.getEvents()",i)}}if(typeof window<"u"){if(!this.pageUrl)try{let e=new URL(window.location.href);this.pageUrl=e.origin+e.pathname}catch{this.pageUrl=window.location.href}window.addEventListener("pagehide",this.boundFlushBeacon),typeof document<"u"&&document.addEventListener("visibilitychange",this.boundVisibilityChange),this.flushTimer=setInterval(()=>this.flush(),de)}}}disable(){if(this.isEnabled){if(this.isEnabled=!1,this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),typeof window<"u"&&(window.removeEventListener("pagehide",this.boundFlushBeacon),typeof document<"u"&&document.removeEventListener("visibilitychange",this.boundVisibilityChange)),this.boundPbjsHandlers.length>0){let n=(typeof window<"u"?window:{})[this.config.pbjsGlobalName]||{};if(typeof n.offEvent=="function")for(let{event:i,handler:r}of this.boundPbjsHandlers)n.offEvent(i,r);this.boundPbjsHandlers=[]}this.flush()}}handleVisibilityChange(){typeof document<"u"&&document.visibilityState==="hidden"&&this.flushBeacon()}trackRawEvent(e,n,i){let r=Ue[n]??(e==="ERROR"?c.ERROR:c.TRACE_EVENT_TYPE_UNSPECIFIED);this.enqueue(r,n,i,e)}setUserId(e){this.config.userId=e}setSessionId(e){this.config.sessionId=e}navigate(e,n){if(this.disable(),this.config.pageviewId=e||E(),n)try{let i=new URL(n);this.pageUrl=i.origin+i.pathname}catch{this.pageUrl=n}else this.pageUrl="";fe(),this.enable()}handleAuctionInit(e){this.isDuplicate("auctionInit",e)||(this.log("DEBUG","auctionInit",e),this.enqueue(c.AUCTION_START,"auctionStart",{auctionId:e.auctionId||"",transactionId:e.transactionId||""}))}handleAuctionEnd(e){this.isDuplicate("auctionEnd",e)||(this.log("DEBUG","auctionEnd",e),this.enqueue(c.AUCTION_END,"auctionEnd",{auctionId:e.auctionId||"",transactionId:e.transactionId||""}))}handleBidRequested(e){if(this.isDuplicate("bidRequested",e))return;this.log("DEBUG","bidRequested",e);let n=e.auctionId||"",i=e.bidderCode||e.bidder||"";Array.isArray(e.bids)&&e.bids.forEach(r=>{let s=Object.keys(r.mediaTypes||{}),o=r.ortb2Imp?.ext?.gpid||r.gpid||e.gpid||"",d=r.transactionId||r.ortb2Imp?.id||e.transactionId||"";if(s.length===0){let u=r.mediaType||"banner",{width:p,height:k}=le(r.sizes||r.playerSize);this.enqueue(c.BID_REQUEST,"bidRequest",{auctionId:n,transactionId:d,adUnitCode:r.adUnitCode||"",gpid:o,bid:{bidder:i,mediaType:u,width:p,height:k}});return}s.forEach(u=>{let p=null;u==="banner"?p=r.mediaTypes?.banner?.sizes||r.sizes:u==="video"?p=r.mediaTypes?.video?.playerSize||r.mediaTypes?.video?.sizes||r.playerSize:p=r.mediaTypes?.[u]?.sizes;let{width:k,height:ye}=le(p);this.enqueue(c.BID_REQUEST,"bidRequest",{auctionId:n,transactionId:d,adUnitCode:r.adUnitCode||"",gpid:o,bid:{bidder:i,mediaType:u,width:k,height:ye}})})})}handleBidResponse(e){this.isDuplicate("bidResponse",e)||(this.log("DEBUG","bidResponse",e),this.enqueue(c.BID_RESPONSE,"bidResponse",{auctionId:e.auctionId||"",transactionId:e.transactionId||"",adUnitCode:e.adUnitCode||"",bid:{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",...L(e),dealId:e.dealId||"",mediaType:e.mediaType||"banner",latencyMs:Number.isFinite(e.timeToRespond)?e.timeToRespond:0,advertiserDomain:e.meta?.advertiserDomains?.[0]||"",creativeId:e.creativeId||""}}))}handleBidTimeout(e){if(this.isDuplicate("bidTimeout",e))return;this.log("DEBUG","bidTimeout",e);let n=Array.isArray(e)?e:e?[e]:[];for(let i of n)this.enqueue(c.BID_TIMEOUT,"bidTimeout",{auctionId:i.auctionId||"",transactionId:i.transactionId||"",adUnitCode:i.adUnitCode||"",bid:{bidder:i.bidderCode||i.bidder||"",latencyMs:Number.isFinite(i.timeout)?i.timeout:0}})}handleBidWon(e){this.isDuplicate("bidWon",e)||(this.log("DEBUG","bidWon",e),this.enqueue(c.BID_WIN,"bidWon",{auctionId:e.auctionId||"",transactionId:e.transactionId||"",adUnitCode:e.adUnitCode||"",bid:{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",...L(e),dealId:e.dealId||"",mediaType:e.mediaType||"banner",latencyMs:Number.isFinite(e.timeToRespond)?e.timeToRespond:0,advertiserDomain:e.meta?.advertiserDomains?.[0]||"",creativeId:e.creativeId||""}}))}handleNoBid(e){this.isDuplicate("noBid",e)||(this.log("DEBUG","noBid",e),this.enqueue(c.NO_BID,"noBid",{auctionId:e.auctionId||"",transactionId:e.transactionId||"",adUnitCode:e.adUnitCode||"",bid:{bidder:e.bidderCode||e.bidder||""}}))}handleAdRenderFailed(e){if(this.isDuplicate("adRenderFailed",e))return;this.log("DEBUG","adRenderFailed",e);let n=e.bid||{};this.enqueue(c.AD_RENDER_FAILED,"adRenderFailed",{auctionId:n.auctionId||e.auctionId||"",transactionId:n.transactionId||e.transactionId||"",adUnitCode:n.adUnitCode||e.adUnitCode||"",bid:{bidder:n.bidderCode||n.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 n=e.bid||{};this.enqueue(c.IMPRESSION,"impression",{auctionId:n.auctionId||e.auctionId||"",transactionId:n.transactionId||e.transactionId||"",adUnitCode:e.adUnitCode||n.adUnitCode||"",bid:{bidder:n.bidderCode||n.bidder||"",cpm:Number.isFinite(n.originalCpm)?n.originalCpm:Number.isFinite(n.cpm)?n.cpm:0,currency:n.originalCurrency??n.currency??"USD",...L(n),dealId:n.dealId||"",mediaType:n.mediaType||"banner",latencyMs:Number.isFinite(n.timeToRespond)?n.timeToRespond:0,advertiserDomain:n.meta?.advertiserDomains?.[0]||"",creativeId:n.creativeId||""}})}isDuplicate(e,n){return this.deduper.isDuplicate(e,n)}enqueue(e,n,i,r){if(!this.isEnabled||!this.shouldSample(e,r))return;fe();let s={eventId:E(),timestampMs:Date.now(),type:e,eventName:n,auctionId:i.auctionId||"",transactionId:i.transactionId||"",adUnitCode:i.adUnitCode||i.elementId||"",namespace:i.ns||i.namespace||""};i.bid&&(s.bid={bidder:i.bid.bidder||"",cpm:Number.isFinite(i.bid.cpm)?i.bid.cpm:0,currency:i.bid.currency||"",width:Number.isFinite(i.bid.width)?i.bid.width:0,height:Number.isFinite(i.bid.height)?i.bid.height:0,dealId:i.bid.dealId||"",mediaType:i.bid.mediaType||"",latencyMs:Number.isFinite(i.bid.latencyMs)?i.bid.latencyMs:0,advertiserDomain:i.bid.advertiserDomain||"",creativeId:i.bid.creativeId||""}),i.viewableDurationMs!==void 0&&(s.viewableDurationMs=Number.isFinite(i.viewableDurationMs)?i.viewableDurationMs:0);let o={...i.metadata};i.error!==void 0&&i.error!==null&&(o.error=typeof i.error=="object"&&i.error.message?String(i.error.message):String(i.error)),i.gpid&&(o.gpid=String(i.gpid)),Object.keys(o).length>0&&(s.metadata=o),this.queue.push(s),this.queue.length>B&&this.queue.splice(0,this.queue.length-B),this.queue.length>=De&&this.flush()}shouldSample(e,n){return e===c.ERROR?(this.errorCount++,this.errorCount>Ae?!1:this.config.errorsEnabled):n==="WARN"?this.config.warningsEnabled:this.config.auctionEnabled}requeue(e){e.length&&(this.queue=e.concat(this.queue),this.queue.length>B&&this.queue.splice(0,this.queue.length-B))}drainBatch(){if(this.queue.length===0||!this.config.endpoint)return null;let e=this.queue,n=typeof window<"u"?window.location.hostname:"",i=s=>({propertyId:this.config.propertyId,pageviewId:this.config.pageviewId,sessionId:this.config.sessionId,pageUrl:this.pageUrl,country:this.config.country,region:this.config.region,deviceType:this.config.deviceType,userId:this.config.userId,domain:n,events:s}),r=x.encode(i(e)).finish();for(;e.length>1&&r.byteLength>Se;)e=e.slice(0,Math.floor(e.length/2)),r=x.encode(i(e)).finish();return this.queue=this.queue.slice(e.length),{url:`${this.config.endpoint}/${this.config.propertyId}`,encoded:r,events:e}}sendFetch(e,n=!1){let i={method:"POST",headers:{"Content-Type":"application/x-protobuf"},body:e.encoded};n&&(i.keepalive=!0),fetch(e.url,i).then(r=>{if(r.ok)this.consecutiveSendFailures=0,this.nextSendAllowedAt=0;else{if(this.log("WARN",`Failed to send batch: HTTP ${r.status}`),r.status>=400&&r.status<500){this.log("WARN",`Dropping batch due to non-retryable client error HTTP ${r.status}`);return}this.handleSendFailure(e.events)}}).catch(r=>{this.log("ERROR","Failed to send batch",r),this.handleSendFailure(e.events)})}handleSendFailure(e){this.consecutiveSendFailures++;let n=Math.min(de*2**(this.consecutiveSendFailures-1),ke);this.nextSendAllowedAt=Date.now()+n,this.consecutiveSendFailures<=Re?this.requeue(e):this.log("WARN",`Dropping ${e.length} events after ${this.consecutiveSendFailures} consecutive send failures`)}flush(){if(Date.now()<this.nextSendAllowedAt)return;let e=this.drainBatch();for(;e&&(this.sendFetch(e,!1),!(Date.now()<this.nextSendAllowedAt));)e=this.drainBatch()}flushBeacon(){let e=this.drainBatch();for(;e;){let n=!1;if(typeof navigator<"u"&&typeof navigator.sendBeacon=="function")try{let i=new Blob([e.encoded],{type:"application/x-protobuf"});n=navigator.sendBeacon(e.url,i)}catch{n=!1}n||this.sendFetch(e,!0),e=this.drainBatch()}}log(e,n,...i){let r={DEBUG:10,INFO:20,WARN:30,ERROR:40};if(r[e]<r[this.config.logLevel])return;let s=`[bidkernel][prebid-analytics][${e}]`;switch(e){case"DEBUG":console.debug(s,n,...i);break;case"INFO":console.info(s,n,...i);break;case"WARN":console.warn(s,n,...i);break;case"ERROR":console.error(s,n,...i);break}}}});var Me=be(()=>{he();var pe="https://by.bidkernel.io/t",Ce=window._bidkernelPbjsGlobal||"pbjs";V(Ce,{endpoint:pe});window.bidkernelPrebidAnalytics={...window.bidkernelPrebidAnalytics,register:(t,e)=>V(t,{endpoint:pe,...e})}});return Me();})();
1
+ "use strict";var bidkernelPrebidAnalyticsBundle=(()=>{var b=(i,e)=>()=>(i&&(e=i(i=0)),e);var Te=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports);function H(){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 w(i,e,t){for(let s=0;s<28;s=s+7){let o=i>>>s,a=!(!(o>>>7)&&e==0),d=(a?o|128:o)&255;if(t.push(d),!a)return}let n=i>>>28&15|(e&7)<<4,r=e>>3!=0;if(t.push((r?n|128:n)&255),!!r){for(let s=3;s<31;s=s+7){let o=e>>>s,a=!!(o>>>7),d=(a?o|128:o)&255;if(t.push(d),!a)return}t.push(e>>>31&1)}}function U(i){let e=i[0]==="-";e&&(i=i.slice(1));let t=1e6,n=0,r=0;function s(o,a){let d=Number(i.slice(o,a));r*=t,n=n*t+d,n>=E&&(r=r+(n/E|0),n=n%E)}return s(-24,-18),s(-18,-12),s(-12,-6),s(-6),e?Y(n,r):C(n,r)}function K(i,e){let t=C(i,e),n=t.hi&2147483648;n&&(t=Y(t.lo,t.hi));let r=N(t.lo,t.hi);return n?"-"+r:r}function N(i,e){if({lo:i,hi:e}=me(i,e),e<=2097151)return String(E*e+i);let t=i&16777215,n=(i>>>24|e<<8)&16777215,r=e>>16&65535,s=t+n*6777216+r*6710656,o=n+r*8147497,a=r*2,d=1e7;return s>=d&&(o+=Math.floor(s/d),s%=d),o>=d&&(a+=Math.floor(o/d),o%=d),a.toString()+z(o)+z(s)}function me(i,e){return{lo:i>>>0,hi:e>>>0}}function C(i,e){return{lo:i|0,hi:e|0}}function Y(i,e){return e=~e,i?i=~i+1:e+=1,C(i,e)}function P(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 j(){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 E,z,_=b(()=>{"use strict";E=4294967296;z=i=>{let e=String(i);return"0000000".slice(e.length)+e}});function ge(){let i=new DataView(new ArrayBuffer(8));if(typeof BigInt=="function"&&typeof i.getBigInt64=="function"&&typeof i.getBigUint64=="function"&&typeof i.setBigInt64=="function"&&typeof i.setBigUint64=="function"&&(!!globalThis.Deno||typeof process!="object"||typeof process.env!="object"||process.env.BUF_BIGINT_DISABLE!=="1")){let t=BigInt("-9223372036854775808"),n=BigInt("9223372036854775807"),r=BigInt("0"),s=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(o){let a=typeof o=="bigint"?o:BigInt(o);if(a>n||a<t)throw new Error(`invalid int64: ${o}`);return a},uParse(o){let a=typeof o=="bigint"?o:BigInt(o);if(a>s||a<r)throw new Error(`invalid uint64: ${o}`);return a},enc(o){return i.setBigInt64(0,this.parse(o),!0),{lo:i.getInt32(0,!0),hi:i.getInt32(4,!0)}},uEnc(o){return i.setBigInt64(0,this.uParse(o),!0),{lo:i.getInt32(0,!0),hi:i.getInt32(4,!0)}},dec(o,a){return i.setInt32(0,o,!0),i.setInt32(4,a,!0),i.getBigInt64(0,!0)},uDec(o,a){return i.setInt32(0,o,!0),i.setInt32(4,a,!0),i.getBigUint64(0,!0)}}}return{zero:"0",supported:!1,parse(t){return typeof t!="string"&&(t=t.toString()),X(t),t},uParse(t){return typeof t!="string"&&(t=t.toString()),Q(t),t},enc(t){return typeof t!="string"&&(t=t.toString()),X(t),U(t)},uEnc(t){return typeof t!="string"&&(t=t.toString()),Q(t),U(t)},dec(t,n){return K(t,n)},uDec(t,n){return N(t,n)}}}function X(i){if(!/^-?[0-9]+$/.test(i))throw new Error("invalid int64: "+i)}function Q(i){if(!/^[0-9]+$/.test(i))throw new Error("invalid uint64: "+i)}var h,Z=b(()=>{"use strict";_();h=ge()});function V(){if(globalThis[M]==null){let i=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[M]={encodeUtf8(t){return i.encode(t)},decodeUtf8(t){return e.decode(t)},checkUtf8(t){try{return encodeURIComponent(t),!0}catch{return!1}}}}return globalThis[M]}var M,O=b(()=>{"use strict";M=Symbol.for("@bufbuild/protobuf/text-encoding")});function F(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>xe||i<Se)throw new Error("invalid int32: "+i)}function J(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>we||i<0)throw new Error("invalid uint32: "+i)}function Re(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>ve||i<Ee))throw new Error("invalid float32: "+i)}var I,ve,Ee,we,xe,Se,T,p,ee=b(()=>{"use strict";_();Z();O();(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"})(I||(I={}));ve=34028234663852886e22,Ee=-34028234663852886e22,we=4294967295,xe=2147483647,Se=-2147483648,T=class{constructor(e=V().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(J(e);e>127;)this.buf.push(e&127|128),e=e>>>7;return this.buf.push(e),this}int32(e){return F(e),P(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){Re(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){J(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){F(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return F(e),e=(e<<1^e>>31)>>>0,P(e,this.buf),this}sfixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=h.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=h.uEnc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=h.enc(e);return w(t.lo,t.hi,this.buf),this}sint64(e){let t=h.enc(e),n=t.hi>>31,r=t.lo<<1^n,s=(t.hi<<1|t.lo>>>31)^n;return w(r,s,this.buf),this}uint64(e){let t=h.uEnc(e);return w(t.lo,t.hi,this.buf),this}},p=class{constructor(e,t=V().decodeUtf8){this.decodeUtf8=t,this.varint64=H,this.uint32=j,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 I.Varint:for(;this.buf[this.pos++]&128;);break;case I.Bit64:this.pos+=4;case I.Bit32:this.pos+=4;break;case I.LengthDelimited:let r=this.uint32();this.pos+=r;break;case I.StartGroup:for(;;){let[s,o]=this.tag();if(o===I.EndGroup){if(t!==void 0&&s!==t)throw new Error("invalid end group tag");break}this.skip(o,s)}break;default:throw new Error("cant skip wire type "+e)}return this.assertBounds(),this.buf.subarray(n,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)}int64(){return h.dec(...this.varint64())}uint64(){return h.uDec(...this.varint64())}sint64(){let[e,t]=this.varint64(),n=-(e&1);return e=(e>>>1|(t&1)<<31)^n,t=t>>>1^n,h.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 h.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return h.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 te=b(()=>{"use strict"});var ie=b(()=>{"use strict"});var ne=b(()=>{"use strict"});var re=b(()=>{"use strict";ee();te();O();ie();ne()});function se(){return{propertyId:"",pageviewId:"",sessionId:"",pageUrl:"",country:"",region:"",deviceType:"",userId:"",domain:"",events:[],browser:"",deviceManufacturer:"",deviceModel:"",city:"",postalCode:""}}function oe(){return{timestampMs:0,type:0,eventName:"",auctionId:"",transactionId:"",adUnitCode:"",bid:void 0,namespace:"",eventId:"",metadata:{},viewableDurationMs:void 0}}function ae(){return{key:"",value:""}}function de(){return{bidder:"",cpm:0,currency:"",width:0,height:0,dealId:"",mediaType:"",latencyMs:0,advertiserDomain:"",creativeId:""}}var u,R,x,L,S,ce=b(()=>{"use strict";re();u={TRACE_EVENT_TYPE_UNSPECIFIED:0,AUCTION_START:1,AUCTION_END:2,BID_REQUEST:3,BID_RESPONSE:4,BID_WIN:5,BID_TIMEOUT:6,IMPRESSION:7,VIEWABLE:8,TIME_IN_VIEW:14,REFRESH:9,ERROR:10,SLOT_DEFINED:11,SLOT_DESTROYED:12,CLICK:13,NO_BID:15,AD_RENDER_FAILED:16,UNRECOGNIZED:-1};R={encode(i,e=new T){if(i.propertyId!==void 0&&i.propertyId!==""&&e.uint32(10).string(i.propertyId),i.pageviewId!==void 0&&i.pageviewId!==""&&e.uint32(18).string(i.pageviewId),i.sessionId!==void 0&&i.sessionId!==""&&e.uint32(26).string(i.sessionId),i.pageUrl!==void 0&&i.pageUrl!==""&&e.uint32(34).string(i.pageUrl),i.country!==void 0&&i.country!==""&&e.uint32(42).string(i.country),i.region!==void 0&&i.region!==""&&e.uint32(50).string(i.region),i.deviceType!==void 0&&i.deviceType!==""&&e.uint32(58).string(i.deviceType),i.userId!==void 0&&i.userId!==""&&e.uint32(66).string(i.userId),i.domain!==void 0&&i.domain!==""&&e.uint32(74).string(i.domain),i.events!==void 0&&i.events.length!==0)for(let t of i.events)x.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 p?i:new p(i),n=e===void 0?t.len:t.pos+e,r=se();for(;t.pos<n;){let s=t.uint32();switch(s>>>3){case 1:{if(s!==10)break;r.propertyId=t.string();continue}case 2:{if(s!==18)break;r.pageviewId=t.string();continue}case 3:{if(s!==26)break;r.sessionId=t.string();continue}case 4:{if(s!==34)break;r.pageUrl=t.string();continue}case 5:{if(s!==42)break;r.country=t.string();continue}case 6:{if(s!==50)break;r.region=t.string();continue}case 7:{if(s!==58)break;r.deviceType=t.string();continue}case 8:{if(s!==66)break;r.userId=t.string();continue}case 9:{if(s!==74)break;r.domain=t.string();continue}case 10:{if(s!==82)break;let o=x.decode(t,t.uint32());o!==void 0&&r.events.push(o);continue}case 11:{if(s!==90)break;r.browser=t.string();continue}case 12:{if(s!==98)break;r.deviceManufacturer=t.string();continue}case 13:{if(s!==106)break;r.deviceModel=t.string();continue}case 14:{if(s!==114)break;r.city=t.string();continue}case 15:{if(s!==122)break;r.postalCode=t.string();continue}}if((s&7)===4||s===0)break;t.skip(s&7)}return r},create(i){return R.fromPartial(i??{})},fromPartial(i){let e=se();return e.propertyId=i.propertyId??"",e.pageviewId=i.pageviewId??"",e.sessionId=i.sessionId??"",e.pageUrl=i.pageUrl??"",e.country=i.country??"",e.region=i.region??"",e.deviceType=i.deviceType??"",e.userId=i.userId??"",e.domain=i.domain??"",e.events=i.events?.map(t=>x.fromPartial(t))||[],e.browser=i.browser??"",e.deviceManufacturer=i.deviceManufacturer??"",e.deviceModel=i.deviceModel??"",e.city=i.city??"",e.postalCode=i.postalCode??"",e}};x={encode(i,e=new T){return i.timestampMs!==void 0&&i.timestampMs!==0&&e.uint32(9).double(i.timestampMs),i.type!==void 0&&i.type!==0&&e.uint32(16).int32(i.type),i.eventName!==void 0&&i.eventName!==""&&e.uint32(26).string(i.eventName),i.auctionId!==void 0&&i.auctionId!==""&&e.uint32(34).string(i.auctionId),i.transactionId!==void 0&&i.transactionId!==""&&e.uint32(42).string(i.transactionId),i.adUnitCode!==void 0&&i.adUnitCode!==""&&e.uint32(50).string(i.adUnitCode),i.bid!==void 0&&S.encode(i.bid,e.uint32(58).fork()).join(),i.namespace!==void 0&&i.namespace!==""&&e.uint32(66).string(i.namespace),i.eventId!==void 0&&i.eventId!==""&&e.uint32(74).string(i.eventId),globalThis.Object.entries(i.metadata||{}).forEach(([t,n])=>{L.encode({key:t,value:n},e.uint32(82).fork()).join()}),i.viewableDurationMs!==void 0&&e.uint32(89).double(i.viewableDurationMs),e},decode(i,e){let t=i instanceof p?i:new p(i),n=e===void 0?t.len:t.pos+e,r=oe();for(;t.pos<n;){let s=t.uint32();switch(s>>>3){case 1:{if(s!==9)break;r.timestampMs=t.double();continue}case 2:{if(s!==16)break;r.type=t.int32();continue}case 3:{if(s!==26)break;r.eventName=t.string();continue}case 4:{if(s!==34)break;r.auctionId=t.string();continue}case 5:{if(s!==42)break;r.transactionId=t.string();continue}case 6:{if(s!==50)break;r.adUnitCode=t.string();continue}case 7:{if(s!==58)break;r.bid=S.decode(t,t.uint32());continue}case 8:{if(s!==66)break;r.namespace=t.string();continue}case 9:{if(s!==74)break;r.eventId=t.string();continue}case 10:{if(s!==82)break;let o=L.decode(t,t.uint32());o.value!==void 0&&(r.metadata[o.key]=o.value);continue}case 11:{if(s!==89)break;r.viewableDurationMs=t.double();continue}}if((s&7)===4||s===0)break;t.skip(s&7)}return r},create(i){return x.fromPartial(i??{})},fromPartial(i){let e=oe();return e.timestampMs=i.timestampMs??0,e.type=i.type??0,e.eventName=i.eventName??"",e.auctionId=i.auctionId??"",e.transactionId=i.transactionId??"",e.adUnitCode=i.adUnitCode??"",e.bid=i.bid!==void 0&&i.bid!==null?S.fromPartial(i.bid):void 0,e.namespace=i.namespace??"",e.eventId=i.eventId??"",e.metadata=globalThis.Object.entries(i.metadata??{}).reduce((t,[n,r])=>(r!==void 0&&(t[n]=globalThis.String(r)),t),{}),e.viewableDurationMs=i.viewableDurationMs??void 0,e}};L={encode(i,e=new T){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 p?i:new p(i),n=e===void 0?t.len:t.pos+e,r=ae();for(;t.pos<n;){let s=t.uint32();switch(s>>>3){case 1:{if(s!==10)break;r.key=t.string();continue}case 2:{if(s!==18)break;r.value=t.string();continue}}if((s&7)===4||s===0)break;t.skip(s&7)}return r},create(i){return L.fromPartial(i??{})},fromPartial(i){let e=ae();return e.key=i.key??"",e.value=i.value??"",e}};S={encode(i,e=new T){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 p?i:new p(i),n=e===void 0?t.len:t.pos+e,r=de();for(;t.pos<n;){let s=t.uint32();switch(s>>>3){case 1:{if(s!==10)break;r.bidder=t.string();continue}case 2:{if(s!==17)break;r.cpm=t.double();continue}case 3:{if(s!==26)break;r.currency=t.string();continue}case 4:{if(s!==32)break;r.width=t.int32();continue}case 5:{if(s!==40)break;r.height=t.int32();continue}case 6:{if(s!==50)break;r.dealId=t.string();continue}case 7:{if(s!==58)break;r.mediaType=t.string();continue}case 8:{if(s!==65)break;r.latencyMs=t.double();continue}case 9:{if(s!==74)break;r.advertiserDomain=t.string();continue}case 10:{if(s!==82)break;r.creativeId=t.string();continue}}if((s&7)===4||s===0)break;t.skip(s&7)}return r},create(i){return S.fromPartial(i??{})},fromPartial(i){let e=de();return e.bidder=i.bidder??"",e.cpm=i.cpm??0,e.currency=i.currency??"",e.width=i.width??0,e.height=i.height??0,e.dealId=i.dealId??"",e.mediaType=i.mediaType??"",e.latencyMs=i.latencyMs??0,e.advertiserDomain=i.advertiserDomain??"",e.creativeId=i.creativeId??"",e}}});function m(){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 he(){let i=Date.now();v=i;try{typeof localStorage<"u"&&localStorage.setItem(B,i.toString())}catch{}}function Pe(){let i=Date.now();try{if(typeof localStorage<"u"){let e=localStorage.getItem(le),t=localStorage.getItem(B),n=t&&parseInt(t,10)||0;if(e&&n&&i-n<=fe)return localStorage.setItem(B,i.toString()),e;let r=m();return localStorage.setItem(le,r),localStorage.setItem(B,i.toString()),r}}catch{}return D&&v&&i-v<=fe?(v=i,D):(D=m(),v=i,D)}function c(i){return String(i??"").replace(/%/g,"%25").replace(/:/g,"%3A")}function _e(i,e){switch(i){case"auctionInit":return`auctionInit:${c(e?.auctionId)}`;case"auctionEnd":return`auctionEnd:${c(e?.auctionId)}`;case"bidRequested":{let t=Array.isArray(e?.bids)?e.bids.map(n=>c(n?.bidId||n?.transactionId||n?.adUnitCode)).join(","):"";return`bidRequested:${c(e?.auctionId)}:${c(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:${c(t.auctionId)}:${c(t.adUnitCode)}:${c(t.bidderCode||t.bidder)}:${c(n)}:${c(r)}`}case"bidTimeout":return"bidTimeout:"+(Array.isArray(e)?e:e?[e]:[]).map(n=>`${c(n?.auctionId)}:${c(n?.bidderCode||n?.bidder)}:${c(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:${c(t.auctionId)}:${c(t.adUnitCode)}:${c(t.bidderCode||t.bidder)}:${c(n)}:${c(r)}`}case"noBid":return`noBid:${c(e?.auctionId)}:${c(e?.adUnitCode)}:${c(e?.bidderCode||e?.bidder)}:${c(e?.bidId||e?.transactionId)}`;case"adRenderFailed":{let t=e?.bid||{};return`adRenderFailed:${c(t.auctionId||e?.auctionId)}:${c(t.adUnitCode||e?.adUnitCode)}:${c(t.bidderCode||t.bidder||e?.bidderCode||e?.bidder)}:${c(e?.reason)}:${c(e?.message)}`}case"adRenderSucceeded":{let t=e?.bid||e||{},n=t.creativeId||t.adId||e?.adId||"",r=t.originalCpm??t.cpm??"";return`adRenderSucceeded:${c(t.auctionId||e?.auctionId)}:${c(t.adUnitCode||e?.adUnitCode)}:${c(t.bidderCode||t.bidder)}:${c(n)}:${c(r)}`}case"setTargeting":return`setTargeting:${Object.keys(e||{}).sort().map(c).join(",")}`;case"auctionDebug":return`auctionDebug:${c(e?.type)}:${c(String(e?.arguments?.[0]??"").slice(0,50))}`;default:return""}}function pe(i){if(!i)return{width:0,height:0};let e=i;for(;Array.isArray(e)&&e.length>0&&Array.isArray(e[0]);)e=e[0];if(Array.isArray(e)&&e.length>=2){let t=Number(e[0]),n=Number(e[1]);return{width:Number.isFinite(t)?t:0,height:Number.isFinite(n)?n:0}}return{width:0,height:0}}function q(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 g(i){if(!i)return null;if(Array.isArray(i)){let e=i.find(t=>t?.provider==="bidkernel")??i.find(t=>t&&typeof t=="object"&&t.provider===void 0);return e?g(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 Me(i){if(!i)return null;if(i._bidkernelAnalyticsConfig){let e=g(i._bidkernelAnalyticsConfig);if(e)return e}if(i.bidkernelPrebidAnalytics){let e=i.bidkernelPrebidAnalytics;if(e.options){let t=g(e.options);if(t)return t}if(e.config){let t=g(e.config);if(t)return t}if(e.propertyId)return g(e)}return null}function G(i="pbjs",e){let t=typeof window<"u"?window:{};t[i]=t[i]||{};let n=t[i],r=o=>{if(t._bidkernelPrebidAnalytics)try{t._bidkernelPrebidAnalytics.disable()}catch(d){console.warn("[bidkernel] Failed to disable previous analytics instance:",d)}let a=new W({pbjsGlobalName:i,...e,...o});return a.enable(),t._bidkernelPrebidAnalytics=a,a},s=()=>{try{n.adapterManager&&typeof n.adapterManager.registerAnalyticsAdapter=="function"&&n.adapterManager.registerAnalyticsAdapter({adapter:{enableAnalytics:a=>{let d=g(a);d&&r(d)},disableAnalytics:()=>{t._bidkernelPrebidAnalytics&&t._bidkernelPrebidAnalytics.disable()}},code:"bidkernel"});let o=Me(t);o&&(o.propertyId||e?.propertyId)&&r(o)}catch(o){console.warn("[bidkernel] Failed to register standard Prebid analytics adapter:",o)}};n.adapterManager&&typeof n.adapterManager.registerAnalyticsAdapter=="function"?s():(n.que=n.que||[],n.que.push(s))}var De,ue,Be,A,ke,Ue,Ne,Ce,le,B,fe,D,v,$,W,be=b(()=>{"use strict";ce();De=20,ue=1e4,Be=50,A=200,ke=300*1e3,Ue=10,Ne=32*1024,Ce={auctionStart:u.AUCTION_START,auctionEnd:u.AUCTION_END,bidRequest:u.BID_REQUEST,bidResponse:u.BID_RESPONSE,bidTimeout:u.BID_TIMEOUT,bidWin:u.BID_WIN,noBid:u.NO_BID,adRenderFailed:u.AD_RENDER_FAILED,click:u.CLICK,impression:u.IMPRESSION,refresh:u.REFRESH,timeInView:u.TIME_IN_VIEW,viewable:u.VIEWABLE},le="_bidkernel_session",B="_bidkernel_session_ts",fe=1800*1e3,D=null,v=0;$=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=_e(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}};W=class i{static activeInstances=new Set;config;queue=[];errorCount=0;flushTimer=null;boundFlushBeacon;boundVisibilityChange;isEnabled=!1;boundPbjsHandlers=[];pageUrl="";deduper=new $;consecutiveSendFailures=0;nextSendAllowedAt=0;replayedEventCount=0;intersectionObserver=null;slotViewabilityRecords=new Map;elementToSlotId=new Map;slotRefreshIndices=new Map;pendingThresholdListeners=new Map;constructor(e){this.config={endpoint:e.endpoint||"",propertyId:e.propertyId||"",pageviewId:e.pageviewId||m(),sessionId:e.sessionId||Pe(),userId:e.userId||"",deviceType:e.deviceType||"desktop",country:e.country||"",region:e.region||"",auctionEnabled:e.auctionEnabled??!0,warningsEnabled:e.warningsEnabled??!0,errorsEnabled:e.errorsEnabled??!0,viewabilityEnabled:e.viewabilityEnabled??!0,logLevel:e.logLevel||"INFO",pbjsGlobalName:e.pbjsGlobalName||"pbjs",attachPbjsListeners:e.attachPbjsListeners??!0},this.boundFlushBeacon=()=>{this.flushAllSlotsTimeInView(),this.flushBeacon()},this.boundVisibilityChange=()=>this.handleVisibilityChange()}enable(){if(!this.isEnabled){if(this.isEnabled=!0,i.activeInstances.add(this),this.config.endpoint||this.log("WARN","Endpoint is empty. Analytics events will not be transmitted."),this.config.viewabilityEnabled&&typeof IntersectionObserver<"u"){this.intersectionObserver=new IntersectionObserver(this.handleIntersection.bind(this),{threshold:[.5]});for(let e of this.slotViewabilityRecords.values())e.element&&this.intersectionObserver.observe(e.element)}if(this.config.attachPbjsListeners){let t=(typeof window<"u"?window:{})[this.config.pbjsGlobalName]||{};if(typeof t.onEvent=="function"){this.log("DEBUG","Attaching event listeners to pbjs");let n=[["auctionInit",this.handleAuctionInit.bind(this)],["auctionEnd",this.handleAuctionEnd.bind(this)],["bidRequested",this.handleBidRequested.bind(this)],["bidResponse",this.handleBidResponse.bind(this)],["bidTimeout",this.handleBidTimeout.bind(this)],["bidWon",this.handleBidWon.bind(this)],["noBid",this.handleNoBid.bind(this)],["adRenderFailed",this.handleAdRenderFailed.bind(this)],["adRenderSucceeded",this.handleAdRenderSucceeded.bind(this)]];for(let[r,s]of n)t.onEvent(r,s),this.boundPbjsHandlers.push({event:r,handler:s})}else this.log("WARN","pbjs.onEvent is not defined. Prebid analytics will not function.");if(typeof t.getEvents=="function")try{let n=t.getEvents();if(Array.isArray(n)){let r=n.slice(this.replayedEventCount);if(this.replayedEventCount=n.length,r.length>0){this.log("DEBUG",`Replaying ${r.length} historical events from pbjs.getEvents()`);let s={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 o of r){if(!o)continue;let a=o.eventType||o.event||o.name,d=o.args!==void 0?o.args:o.data!==void 0?o.data:o,f=s[a];f&&f(d)}}}}catch(n){this.log("WARN","Failed to replay historical events from pbjs.getEvents()",n)}}if(typeof window<"u"){if(!this.pageUrl)try{let e=new URL(window.location.href);this.pageUrl=e.origin+e.pathname}catch{this.pageUrl=window.location.href}window.addEventListener("pagehide",this.boundFlushBeacon),typeof document<"u"&&document.addEventListener("visibilitychange",this.boundVisibilityChange),this.flushTimer=setInterval(()=>this.flush(),ue)}}}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)}if(this.intersectionObserver&&(this.intersectionObserver.disconnect(),this.intersectionObserver=null),this.slotViewabilityRecords.clear(),this.elementToSlotId.clear(),this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=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(u.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 d of i.activeInstances)if(d!==this&&d.elementToSlotId.has(t.target)){d.handleIntersection([t]);break}continue}let r=this.slotViewabilityRecords.get(n);if(!r)continue;let s=t.isIntersecting&&(t.intersectionRatio===void 0||t.intersectionRatio>=.5),o=typeof document>"u"||document.visibilityState==="visible",a=typeof performance<"u"&&performance.now?performance.now():Date.now();if(s){if(!r.inView&&(r.inView=!0,o)){if(r.lastEnteredViewAt=a,!r.viewableFired&&r.dwellTimer===null){let d=r.mediaType==="video"?2e3:1e3;r.dwellStartedAt=a,r.dwellTimer=setTimeout(()=>{this.handleDwellComplete(r)},d)}this.scheduleThresholdTimers(r)}}else{r.inView&&(r.lastEnteredViewAt!==null&&(r.accumulatedTimeInViewMs+=Math.max(0,a-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 d of r.thresholdListeners)d.timer&&(clearTimeout(d.timer),d.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(u.VIEWABLE,"viewable",{auctionId:e.auctionId,transactionId:e.transactionId,adUnitCode:e.adUnitCode,bid:e.bidPayload,metadata:{...e.metadata,refresh_index:String(e.refreshIndex)}})))}scheduleThresholdTimers(e){if(!e.inView||typeof document<"u"&&document.visibilityState==="hidden")return;let t=this.getCurrentTimeInView(e);for(let n of e.thresholdListeners)if(!n.fired)if(t>=n.thresholdMs){n.fired=!0,n.timer&&(clearTimeout(n.timer),n.timer=null);try{n.callback(e.slotId,t)}catch(r){this.log("ERROR","Error in threshold listener callback",r)}}else{n.timer&&clearTimeout(n.timer);let r=n.thresholdMs-t;n.timer=setTimeout(()=>{if(n.timer=null,!n.fired&&e.inView&&(typeof document>"u"||document.visibilityState==="visible")){let s=this.getCurrentTimeInView(e);if(s>=n.thresholdMs){n.fired=!0;try{n.callback(e.slotId,s)}catch(o){this.log("ERROR","Error in threshold listener callback",o)}}}},r)}}checkThresholdListeners(e){let t=this.getCurrentTimeInView(e);for(let n of e.thresholdListeners)if(!n.fired&&t>=n.thresholdMs){n.fired=!0,n.timer&&(clearTimeout(n.timer),n.timer=null);try{n.callback(e.slotId,t)}catch(r){this.log("ERROR","Error in threshold listener callback",r)}}}getCurrentTimeInView(e){let t=e.accumulatedTimeInViewMs;if(e.inView&&e.lastEnteredViewAt!==null){let n=typeof performance<"u"&&performance.now?performance.now():Date.now();t+=Math.max(0,n-e.lastEnteredViewAt)}return t}flushSlotTimeInView(e){let t=this.slotViewabilityRecords.get(e);if(!t)return;if(t.inView&&t.lastEnteredViewAt!==null){let r=typeof performance<"u"&&performance.now?performance.now():Date.now();t.accumulatedTimeInViewMs+=Math.max(0,r-t.lastEnteredViewAt),t.lastEnteredViewAt=null}let n=Math.round(t.accumulatedTimeInViewMs);n>0&&this.enqueue(u.TIME_IN_VIEW,"timeInView",{auctionId:t.auctionId,transactionId:t.transactionId,adUnitCode:t.adUnitCode,viewableDurationMs:n,bid:t.bidPayload,metadata:{...t.metadata,refresh_index:String(t.refreshIndex)}}),t.accumulatedTimeInViewMs=0}flushAllSlotsTimeInView(){for(let e of Array.from(this.slotViewabilityRecords.keys()))this.flushSlotTimeInView(e)}observeSlot(e,t,n){if(!this.config.viewabilityEnabled)return;let r=null;if(typeof e=="string"){if(typeof document<"u"){try{r=document.querySelector(e)||document.getElementById(e)}catch{r=document.getElementById(e)}r||(r=document.getElementById(e))}}else r=e;let s=t||n?.adUnitCode||(r?r.id:"")||m(),o=this.slotViewabilityRecords.get(s);if(o){if(n?.refreshIndex===void 0||n.refreshIndex>o.refreshIndex){this.flushSlotTimeInView(s);let d=n?.refreshIndex!==void 0?n.refreshIndex:(this.slotRefreshIndices.get(s)??o.refreshIndex)+1;this.slotRefreshIndices.set(s,d),n?.emitRefreshEvent!==!1&&this.enqueue(u.REFRESH,"refresh",{auctionId:n?.auctionId||o.auctionId,transactionId:n?.transactionId||o.transactionId,adUnitCode:s,bid:n?.bid??o.bidPayload,metadata:{...n?.metadata,refresh_index:String(d)}}),o.dwellTimer&&(clearTimeout(o.dwellTimer),o.dwellTimer=null,o.dwellStartedAt=null);for(let l of o.thresholdListeners)l.fired=!1,l.timer&&(clearTimeout(l.timer),l.timer=null);o.viewableFired=!1,o.accumulatedTimeInViewMs=0;let f=typeof performance<"u"&&performance.now?performance.now():Date.now();if(o.lastEnteredViewAt=o.inView?f:null,o.refreshIndex=d,o.auctionId=n?.auctionId||o.auctionId,o.transactionId=n?.transactionId||o.transactionId,o.mediaType=n?.mediaType||o.mediaType||"banner",o.bidPayload=n?.bid!==void 0?n.bid:o.bidPayload,o.metadata=n?.metadata??o.metadata,o.inView&&(typeof document>"u"||document.visibilityState==="visible")){let l=o.mediaType==="video"?2e3:1e3;o.dwellStartedAt=f,o.dwellTimer=setTimeout(()=>{this.handleDwellComplete(o)},l),this.scheduleThresholdTimers(o)}}else o.auctionId=n?.auctionId||o.auctionId,o.transactionId=n?.transactionId||o.transactionId,o.mediaType=n?.mediaType||o.mediaType,n?.bid!==void 0&&(o.bidPayload=n.bid),n?.metadata!==void 0&&(o.metadata=n.metadata);r&&(o.element&&o.element!==r&&this.intersectionObserver&&(this.intersectionObserver.unobserve(o.element),this.elementToSlotId.delete(o.element)),o.element=r,this.elementToSlotId.set(r,s),this.intersectionObserver?.observe(r))}else{let a=n?.refreshIndex??this.slotRefreshIndices.get(s)??0;this.slotRefreshIndices.set(s,a);let d=this.pendingThresholdListeners.get(s)||new Set;this.pendingThresholdListeners.delete(s);let f={slotId:s,element:r,adUnitCode:n?.adUnitCode||s,auctionId:n?.auctionId||"",transactionId:n?.transactionId||"",mediaType:n?.mediaType||"banner",bidPayload:n?.bid,metadata:n?.metadata,refreshIndex:a,inView:!1,lastEnteredViewAt:null,accumulatedTimeInViewMs:0,viewableFired:!1,dwellTimer:null,dwellStartedAt:null,thresholdListeners:d};this.slotViewabilityRecords.set(s,f),r&&(this.elementToSlotId.set(r,s),this.intersectionObserver?.observe(r))}}unobserveSlot(e){let t=this.slotViewabilityRecords.get(e);if(t){this.flushSlotTimeInView(e),t.dwellTimer&&(clearTimeout(t.dwellTimer),t.dwellTimer=null,t.dwellStartedAt=null);for(let n of t.thresholdListeners)n.timer&&(clearTimeout(n.timer),n.timer=null);t.thresholdListeners=new Set,t.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.pendingThresholdListeners.delete(e)}onTimeInViewThreshold(e,t,n){let r={thresholdMs:t,callback:n,timer:null,fired:!1},s=this.slotViewabilityRecords.get(e);if(s){s.thresholdListeners.add(r);let o=this.getCurrentTimeInView(s);if(o>=t){r.fired=!0;try{n(e,o)}catch(a){this.log("ERROR","Error in threshold callback",a)}}else if(s.inView&&(typeof document>"u"||document.visibilityState==="visible")){let a=t-o;r.timer=setTimeout(()=>{if(r.timer=null,!r.fired&&s.inView&&(typeof document>"u"||document.visibilityState==="visible")){let d=this.getCurrentTimeInView(s);if(d>=t){r.fired=!0;try{n(e,d)}catch(f){this.log("ERROR","Error in threshold callback",f)}}}},a)}}else this.pendingThresholdListeners.has(e)||this.pendingThresholdListeners.set(e,new Set),this.pendingThresholdListeners.get(e).add(r);return()=>{r.timer&&(clearTimeout(r.timer),r.timer=null),s&&s.thresholdListeners.delete(r);let o=this.pendingThresholdListeners.get(e);o&&o.delete(r)}}getViewabilityState(e){let t=this.slotViewabilityRecords.get(e);if(!t)return;let n=Math.round(this.getCurrentTimeInView(t));return{inView:t.inView,viewable:t.viewableFired,timeInViewMs:n,refreshIndex:t.refreshIndex}}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=Ce[t]??(e==="ERROR"?u.ERROR:u.TRACE_EVENT_TYPE_UNSPECIFIED);this.enqueue(r,t,n,e)}setUserId(e){this.config.userId=e}setSessionId(e){this.config.sessionId=e}navigate(e,t){if(this.disable(),this.slotRefreshIndices.clear(),this.pendingThresholdListeners.clear(),this.config.pageviewId=e||m(),t)try{let n=new URL(t);this.pageUrl=n.origin+n.pathname}catch{this.pageUrl=t}else this.pageUrl="";he(),this.enable()}handleAuctionInit(e){this.isDuplicate("auctionInit",e)||(this.log("DEBUG","auctionInit",e),this.enqueue(u.AUCTION_START,"auctionStart",{auctionId:e.auctionId||"",transactionId:e.transactionId||""}))}handleAuctionEnd(e){this.isDuplicate("auctionEnd",e)||(this.log("DEBUG","auctionEnd",e),this.enqueue(u.AUCTION_END,"auctionEnd",{auctionId:e.auctionId||"",transactionId:e.transactionId||""}))}handleBidRequested(e){if(this.isDuplicate("bidRequested",e))return;this.log("DEBUG","bidRequested",e);let t=e.auctionId||"",n=e.bidderCode||e.bidder||"";Array.isArray(e.bids)&&e.bids.forEach(r=>{let s=Object.keys(r.mediaTypes||{}),o=r.ortb2Imp?.ext?.gpid||r.gpid||e.gpid||"",a=r.transactionId||r.ortb2Imp?.id||e.transactionId||"";if(s.length===0){let d=r.mediaType||"banner",{width:f,height:l}=pe(r.sizes||r.playerSize);this.enqueue(u.BID_REQUEST,"bidRequest",{auctionId:t,transactionId:a,adUnitCode:r.adUnitCode||"",gpid:o,bid:{bidder:n,mediaType:d,width:f,height:l}});return}s.forEach(d=>{let f=null;d==="banner"?f=r.mediaTypes?.banner?.sizes||r.sizes:d==="video"?f=r.mediaTypes?.video?.playerSize||r.mediaTypes?.video?.sizes||r.playerSize:f=r.mediaTypes?.[d]?.sizes;let{width:l,height:y}=pe(f);this.enqueue(u.BID_REQUEST,"bidRequest",{auctionId:t,transactionId:a,adUnitCode:r.adUnitCode||"",gpid:o,bid:{bidder:n,mediaType:d,width:l,height:y}})})})}handleBidResponse(e){this.isDuplicate("bidResponse",e)||(this.log("DEBUG","bidResponse",e),this.enqueue(u.BID_RESPONSE,"bidResponse",{auctionId:e.auctionId||"",transactionId:e.transactionId||"",adUnitCode:e.adUnitCode||"",bid:{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",...q(e),dealId:e.dealId||"",mediaType:e.mediaType||"banner",latencyMs:Number.isFinite(e.timeToRespond)?e.timeToRespond:0,advertiserDomain:e.meta?.advertiserDomains?.[0]||"",creativeId:e.creativeId||""}}))}handleBidTimeout(e){if(this.isDuplicate("bidTimeout",e))return;this.log("DEBUG","bidTimeout",e);let t=Array.isArray(e)?e:e?[e]:[];for(let n of t)this.enqueue(u.BID_TIMEOUT,"bidTimeout",{auctionId:n.auctionId||"",transactionId:n.transactionId||"",adUnitCode:n.adUnitCode||"",bid:{bidder:n.bidderCode||n.bidder||"",latencyMs:Number.isFinite(n.timeout)?n.timeout:0}})}handleBidWon(e){this.isDuplicate("bidWon",e)||(this.log("DEBUG","bidWon",e),this.enqueue(u.BID_WIN,"bidWon",{auctionId:e.auctionId||"",transactionId:e.transactionId||"",adUnitCode:e.adUnitCode||"",bid:{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",...q(e),dealId:e.dealId||"",mediaType:e.mediaType||"banner",latencyMs:Number.isFinite(e.timeToRespond)?e.timeToRespond:0,advertiserDomain:e.meta?.advertiserDomains?.[0]||"",creativeId:e.creativeId||""}}))}handleNoBid(e){this.isDuplicate("noBid",e)||(this.log("DEBUG","noBid",e),this.enqueue(u.NO_BID,"noBid",{auctionId:e.auctionId||"",transactionId:e.transactionId||"",adUnitCode:e.adUnitCode||"",bid:{bidder:e.bidderCode||e.bidder||""}}))}handleAdRenderFailed(e){if(this.isDuplicate("adRenderFailed",e))return;this.log("DEBUG","adRenderFailed",e);let t=e.bid||{};this.enqueue(u.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||"",r=t.auctionId||e.auctionId||"",s=t.transactionId||e.transactionId||"",o=t.mediaType||"banner",a={bidder:t.bidderCode||t.bidder||"",cpm:Number.isFinite(t.originalCpm)?t.originalCpm:Number.isFinite(t.cpm)?t.cpm:0,currency:t.originalCurrency??t.currency??"USD",...q(t),dealId:t.dealId||"",mediaType:o,latencyMs:Number.isFinite(t.timeToRespond)?t.timeToRespond:0,advertiserDomain:t.meta?.advertiserDomains?.[0]||"",creativeId:t.creativeId||""};if(n&&(this.slotViewabilityRecords.has(n)||this.slotRefreshIndices.has(n)&&this.slotRefreshIndices.get(n)>0)){this.flushSlotTimeInView(n);let l=(this.slotRefreshIndices.get(n)??0)+1;this.slotRefreshIndices.set(n,l),this.enqueue(u.REFRESH,"refresh",{auctionId:r,transactionId:s,adUnitCode:n,bid:a,metadata:{refresh_index:String(l)}})}else n&&!this.slotRefreshIndices.has(n)&&this.slotRefreshIndices.set(n,0);let f=n?this.slotRefreshIndices.get(n)??0:0;if(this.enqueue(u.IMPRESSION,"impression",{auctionId:r,transactionId:s,adUnitCode:n,bid:a,metadata:{refresh_index:String(f)}}),this.config.viewabilityEnabled&&typeof document<"u"){let l=null,y=n||e.adId||t.adId;if(y&&(l=document.getElementById(y)),!l&&typeof window<"u"&&window.googletag?.pubads)try{let Ie=window.googletag.pubads().getSlots();for(let k of Ie)if((k.getAdUnitPath?.()===n||k.getSlotElementId?.()===n)&&(l=document.getElementById(k.getSlotElementId()),l))break}catch{}if(!l&&y)try{l=document.querySelector(`[data-ad-slot="${y}"]`)||document.querySelector(`#${y}`)}catch{}l&&this.observeSlot(l,n||y,{adUnitCode:n,auctionId:r,transactionId:s,mediaType:o,bid:a,refreshIndex:f,emitRefreshEvent:!1})}}isDuplicate(e,t){return this.deduper.isDuplicate(e,t)}enqueue(e,t,n,r){if(!this.isEnabled||!this.shouldSample(e,r))return;he();let s={eventId:m(),timestampMs:Date.now(),type:e,eventName:t,auctionId:n.auctionId||"",transactionId:n.transactionId||"",adUnitCode:n.adUnitCode||n.elementId||"",namespace:n.ns||n.namespace||""};n.bid&&(s.bid={bidder:n.bid.bidder||"",cpm:Number.isFinite(n.bid.cpm)?n.bid.cpm:0,currency:n.bid.currency||"",width:Number.isFinite(n.bid.width)?n.bid.width:0,height:Number.isFinite(n.bid.height)?n.bid.height:0,dealId:n.bid.dealId||"",mediaType:n.bid.mediaType||"",latencyMs:Number.isFinite(n.bid.latencyMs)?n.bid.latencyMs:0,advertiserDomain:n.bid.advertiserDomain||"",creativeId:n.bid.creativeId||""}),n.viewableDurationMs!==void 0&&(s.viewableDurationMs=Number.isFinite(n.viewableDurationMs)?n.viewableDurationMs:0);let o={...n.metadata};n.error!==void 0&&n.error!==null&&(o.error=typeof n.error=="object"&&n.error.message?String(n.error.message):String(n.error)),n.gpid&&(o.gpid=String(n.gpid)),n.refreshIndex!==void 0&&o.refresh_index===void 0&&(o.refresh_index=String(n.refreshIndex)),Object.keys(o).length>0&&(s.metadata=o),this.queue.push(s),this.queue.length>A&&this.queue.splice(0,this.queue.length-A),this.queue.length>=De&&this.flush()}shouldSample(e,t){return e===u.ERROR?(this.errorCount++,this.errorCount>Be?!1:this.config.errorsEnabled):t==="WARN"?this.config.warningsEnabled:this.config.auctionEnabled}requeue(e){e.length&&(this.queue=e.concat(this.queue),this.queue.length>A&&this.queue.splice(0,this.queue.length-A))}drainBatch(){if(this.queue.length===0||!this.config.endpoint)return null;let e=this.queue,t=typeof window<"u"?window.location.hostname:"",n=s=>({propertyId:this.config.propertyId,pageviewId:this.config.pageviewId,sessionId:this.config.sessionId,pageUrl:this.pageUrl,country:this.config.country,region:this.config.region,deviceType:this.config.deviceType,userId:this.config.userId,domain:t,events:s}),r=R.encode(n(e)).finish();for(;e.length>1&&r.byteLength>Ne;)e=e.slice(0,Math.floor(e.length/2)),r=R.encode(n(e)).finish();return this.queue=this.queue.slice(e.length),{url:`${this.config.endpoint}/${this.config.propertyId}`,encoded:r,events:e}}sendFetch(e,t=!1){let n={method:"POST",headers:{"Content-Type":"application/x-protobuf"},body:e.encoded};if(t&&(n.keepalive=!0),fetch(e.url,n).then(r=>{if(r.ok)this.consecutiveSendFailures=0,this.nextSendAllowedAt=0;else{if(this.log("WARN",`Failed to send batch: HTTP ${r.status}`),r.status>=400&&r.status<500){this.log("WARN",`Dropping batch due to non-retryable client error HTTP ${r.status}`);return}this.handleSendFailure(e.events)}}).catch(r=>{this.log("ERROR","Failed to send batch",r),this.handleSendFailure(e.events)}),typeof process<"u"&&typeof process._tickCallback=="function")try{process._tickCallback()}catch{}}handleSendFailure(e){this.consecutiveSendFailures++;let t=Math.min(ue*2**(this.consecutiveSendFailures-1),ke);this.nextSendAllowedAt=Date.now()+t,this.consecutiveSendFailures<=Ue?this.requeue(e):this.log("WARN",`Dropping ${e.length} events after ${this.consecutiveSendFailures} consecutive send failures`)}flush(){if(Date.now()<this.nextSendAllowedAt)return;let e=this.drainBatch();for(;e&&(this.sendFetch(e,!1),!(Date.now()<this.nextSendAllowedAt));)e=this.drainBatch()}flushBeacon(){let e=this.drainBatch();for(;e;){let t=!1;if(typeof navigator<"u"&&typeof navigator.sendBeacon=="function")try{let n=new Blob([e.encoded],{type:"application/x-protobuf"});t=navigator.sendBeacon(e.url,n)}catch{t=!1}t||this.sendFetch(e,!0),e=this.drainBatch()}}log(e,t,...n){let r={DEBUG:10,INFO:20,WARN:30,ERROR:40};if(r[e]<r[this.config.logLevel])return;let s=`[bidkernel][prebid-analytics][${e}]`;switch(e){case"DEBUG":console.debug(s,t,...n);break;case"INFO":console.info(s,t,...n);break;case"WARN":console.warn(s,t,...n);break;case"ERROR":console.error(s,t,...n);break}}}});var Oe=Te(()=>{be();var ye="https://by.bidkernel.io/t",Ve=window._bidkernelPbjsGlobal||"pbjs";G(Ve,{endpoint:ye});window.bidkernelPrebidAnalytics={...window.bidkernelPrebidAnalytics,register:(i,e)=>G(i,{endpoint:ye,...e})}});return Oe();})();
package/dist/index.d.mts CHANGED
@@ -10,12 +10,30 @@ interface AnalyticsConfig {
10
10
  auctionEnabled?: boolean;
11
11
  warningsEnabled?: boolean;
12
12
  errorsEnabled?: boolean;
13
+ /** Whether to enable client-side IAB viewability and time-in-view measurement. Defaults to true. */
14
+ viewabilityEnabled?: boolean;
13
15
  logLevel?: "DEBUG" | "INFO" | "WARN" | "ERROR";
14
16
  /** Window global holding the Prebid instance to attach to. Defaults to "pbjs". */
15
17
  pbjsGlobalName?: string;
16
18
  /** Whether to attach pbjs.onEvent listeners. Defaults to true. Set false for full SDK mode. */
17
19
  attachPbjsListeners?: boolean;
18
20
  }
21
+ interface SlotObserveOptions {
22
+ adUnitCode?: string;
23
+ auctionId?: string;
24
+ transactionId?: string;
25
+ mediaType?: string;
26
+ bid?: any;
27
+ metadata?: Record<string, string>;
28
+ refreshIndex?: number;
29
+ emitRefreshEvent?: boolean;
30
+ }
31
+ interface SlotViewabilityState {
32
+ inView: boolean;
33
+ viewable: boolean;
34
+ timeInViewMs: number;
35
+ refreshIndex: number;
36
+ }
19
37
  /**
20
38
  * Canonical duplicate-detection key for a Prebid event. Shared by the adapter
21
39
  * and the diagnostic extension so the two can never drift apart. Covers the
@@ -32,6 +50,7 @@ declare class PrebidEventDeduper {
32
50
  isDuplicate(eventName: string, data: any): boolean;
33
51
  }
34
52
  declare class BidkernelPrebidAnalytics {
53
+ private static activeInstances;
35
54
  private config;
36
55
  private queue;
37
56
  private errorCount;
@@ -45,10 +64,29 @@ declare class BidkernelPrebidAnalytics {
45
64
  private consecutiveSendFailures;
46
65
  private nextSendAllowedAt;
47
66
  private replayedEventCount;
67
+ private intersectionObserver;
68
+ private slotViewabilityRecords;
69
+ private elementToSlotId;
70
+ private slotRefreshIndices;
71
+ private pendingThresholdListeners;
48
72
  constructor(config: AnalyticsConfig);
49
73
  enable(): void;
50
74
  disable(): void;
51
75
  private handleVisibilityChange;
76
+ private handleIntersection;
77
+ private handleDwellComplete;
78
+ private scheduleThresholdTimers;
79
+ private checkThresholdListeners;
80
+ private getCurrentTimeInView;
81
+ private flushSlotTimeInView;
82
+ private flushAllSlotsTimeInView;
83
+ observeSlot(element: HTMLElement | string, slotId?: string, options?: SlotObserveOptions): void;
84
+ unobserveSlot(slotId: string): void;
85
+ destroySlot(slotId: string): void;
86
+ onTimeInViewThreshold(slotId: string, thresholdMs: number, callback: (slotId: string, durationMs: number) => void): () => void;
87
+ getViewabilityState(slotId: string): SlotViewabilityState | undefined;
88
+ getRefreshIndex(slotId: string): number;
89
+ triggerSlotRefresh(slotId: string, options?: SlotObserveOptions): void;
52
90
  trackRawEvent(level: string, eventName: string, data: any): void;
53
91
  setUserId(userId: string): void;
54
92
  setSessionId(sessionId: string): void;
@@ -135,4 +173,4 @@ interface AdsGlobal {
135
173
  */
136
174
  declare function getbidkernel(alias?: string): AdsGlobal;
137
175
 
138
- export { type AdsGlobal, type AnalyticsConfig, BidkernelPrebidAnalytics, PrebidEventDeduper, type SizeMapping, type SlotConfig, type SlotSize, type SlotSizes, getPrebidEventKey, getbidkernel, registerPrebidAnalytics };
176
+ export { type AdsGlobal, type AnalyticsConfig, BidkernelPrebidAnalytics, PrebidEventDeduper, type SizeMapping, type SlotConfig, type SlotObserveOptions, type SlotSize, type SlotSizes, type SlotViewabilityState, getPrebidEventKey, getbidkernel, registerPrebidAnalytics };
package/dist/index.d.ts CHANGED
@@ -10,12 +10,30 @@ interface AnalyticsConfig {
10
10
  auctionEnabled?: boolean;
11
11
  warningsEnabled?: boolean;
12
12
  errorsEnabled?: boolean;
13
+ /** Whether to enable client-side IAB viewability and time-in-view measurement. Defaults to true. */
14
+ viewabilityEnabled?: boolean;
13
15
  logLevel?: "DEBUG" | "INFO" | "WARN" | "ERROR";
14
16
  /** Window global holding the Prebid instance to attach to. Defaults to "pbjs". */
15
17
  pbjsGlobalName?: string;
16
18
  /** Whether to attach pbjs.onEvent listeners. Defaults to true. Set false for full SDK mode. */
17
19
  attachPbjsListeners?: boolean;
18
20
  }
21
+ interface SlotObserveOptions {
22
+ adUnitCode?: string;
23
+ auctionId?: string;
24
+ transactionId?: string;
25
+ mediaType?: string;
26
+ bid?: any;
27
+ metadata?: Record<string, string>;
28
+ refreshIndex?: number;
29
+ emitRefreshEvent?: boolean;
30
+ }
31
+ interface SlotViewabilityState {
32
+ inView: boolean;
33
+ viewable: boolean;
34
+ timeInViewMs: number;
35
+ refreshIndex: number;
36
+ }
19
37
  /**
20
38
  * Canonical duplicate-detection key for a Prebid event. Shared by the adapter
21
39
  * and the diagnostic extension so the two can never drift apart. Covers the
@@ -32,6 +50,7 @@ declare class PrebidEventDeduper {
32
50
  isDuplicate(eventName: string, data: any): boolean;
33
51
  }
34
52
  declare class BidkernelPrebidAnalytics {
53
+ private static activeInstances;
35
54
  private config;
36
55
  private queue;
37
56
  private errorCount;
@@ -45,10 +64,29 @@ declare class BidkernelPrebidAnalytics {
45
64
  private consecutiveSendFailures;
46
65
  private nextSendAllowedAt;
47
66
  private replayedEventCount;
67
+ private intersectionObserver;
68
+ private slotViewabilityRecords;
69
+ private elementToSlotId;
70
+ private slotRefreshIndices;
71
+ private pendingThresholdListeners;
48
72
  constructor(config: AnalyticsConfig);
49
73
  enable(): void;
50
74
  disable(): void;
51
75
  private handleVisibilityChange;
76
+ private handleIntersection;
77
+ private handleDwellComplete;
78
+ private scheduleThresholdTimers;
79
+ private checkThresholdListeners;
80
+ private getCurrentTimeInView;
81
+ private flushSlotTimeInView;
82
+ private flushAllSlotsTimeInView;
83
+ observeSlot(element: HTMLElement | string, slotId?: string, options?: SlotObserveOptions): void;
84
+ unobserveSlot(slotId: string): void;
85
+ destroySlot(slotId: string): void;
86
+ onTimeInViewThreshold(slotId: string, thresholdMs: number, callback: (slotId: string, durationMs: number) => void): () => void;
87
+ getViewabilityState(slotId: string): SlotViewabilityState | undefined;
88
+ getRefreshIndex(slotId: string): number;
89
+ triggerSlotRefresh(slotId: string, options?: SlotObserveOptions): void;
52
90
  trackRawEvent(level: string, eventName: string, data: any): void;
53
91
  setUserId(userId: string): void;
54
92
  setSessionId(sessionId: string): void;
@@ -135,4 +173,4 @@ interface AdsGlobal {
135
173
  */
136
174
  declare function getbidkernel(alias?: string): AdsGlobal;
137
175
 
138
- export { type AdsGlobal, type AnalyticsConfig, BidkernelPrebidAnalytics, PrebidEventDeduper, type SizeMapping, type SlotConfig, type SlotSize, type SlotSizes, getPrebidEventKey, getbidkernel, registerPrebidAnalytics };
176
+ export { type AdsGlobal, type AnalyticsConfig, BidkernelPrebidAnalytics, PrebidEventDeduper, type SizeMapping, type SlotConfig, type SlotObserveOptions, type SlotSize, type SlotSizes, type SlotViewabilityState, getPrebidEventKey, getbidkernel, registerPrebidAnalytics };