@bidkernel/analytics 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analytics.global.js +1 -1
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +135 -9
- package/dist/index.mjs +135 -9
- package/package.json +1 -1
package/dist/analytics.global.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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();})();
|
|
1
|
+
"use strict";var bidkernelPrebidAnalyticsBundle=(()=>{var y=(i,e)=>()=>(i&&(e=i(i=0)),e);var ge=(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 C(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?X(n,r):_(n,r)}function Y(i,e){let t=_(i,e),n=t.hi&2147483648;n&&(t=X(t.lo,t.hi));let r=N(t.lo,t.hi);return n?"-"+r:r}function N(i,e){if({lo:i,hi:e}=ve(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 ve(i,e){return{lo:i>>>0,hi:e>>>0}}function _(i,e){return{lo:i|0,hi:e|0}}function X(i,e){return e=~e,i?i=~i+1:e+=1,_(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,M=y(()=>{"use strict";E=4294967296;z=i=>{let e=String(i);return"0000000".slice(e.length)+e}});function Ee(){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()),Q(t),t},uParse(t){return typeof t!="string"&&(t=t.toString()),Z(t),t},enc(t){return typeof t!="string"&&(t=t.toString()),Q(t),C(t)},uEnc(t){return typeof t!="string"&&(t=t.toString()),Z(t),C(t)},dec(t,n){return Y(t,n)},uDec(t,n){return N(t,n)}}}function Q(i){if(!/^-?[0-9]+$/.test(i))throw new Error("invalid int64: "+i)}function Z(i){if(!/^[0-9]+$/.test(i))throw new Error("invalid uint64: "+i)}var h,J=y(()=>{"use strict";M();h=Ee()});function F(){if(globalThis[V]==null){let i=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[V]={encodeUtf8(t){return i.encode(t)},decodeUtf8(t){return e.decode(t)},checkUtf8(t){try{return encodeURIComponent(t),!0}catch{return!1}}}}return globalThis[V]}var V,O=y(()=>{"use strict";V=Symbol.for("@bufbuild/protobuf/text-encoding")});function L(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>Re||i<Ae)throw new Error("invalid int32: "+i)}function ee(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>xe||i<0)throw new Error("invalid uint32: "+i)}function Be(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>we||i<Se))throw new Error("invalid float32: "+i)}var I,we,Se,xe,Re,Ae,T,p,te=y(()=>{"use strict";M();J();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={}));we=34028234663852886e22,Se=-34028234663852886e22,xe=4294967295,Re=2147483647,Ae=-2147483648,T=class{constructor(e=F().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(ee(e);e>127;)this.buf.push(e&127|128),e=e>>>7;return this.buf.push(e),this}int32(e){return L(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){Be(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){ee(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){L(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return L(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=F().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 ie=y(()=>{"use strict"});var ne=y(()=>{"use strict"});var re=y(()=>{"use strict"});var se=y(()=>{"use strict";te();ie();O();ne();re()});function oe(){return{propertyId:"",pageviewId:"",sessionId:"",pageUrl:"",country:"",region:"",deviceType:"",userId:"",domain:"",events:[],browser:"",deviceManufacturer:"",deviceModel:"",city:"",postalCode:""}}function ae(){return{timestampMs:0,type:0,eventName:"",auctionId:"",transactionId:"",adUnitCode:"",bid:void 0,namespace:"",eventId:"",metadata:{},viewableDurationMs:void 0}}function de(){return{key:"",value:""}}function ce(){return{bidder:"",cpm:0,currency:"",width:0,height:0,dealId:"",mediaType:"",latencyMs:0,advertiserDomain:"",creativeId:""}}var c,R,S,q,x,ue=y(()=>{"use strict";se();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};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)S.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=oe();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=S.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=oe();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=>S.fromPartial(t))||[],e.browser=i.browser??"",e.deviceManufacturer=i.deviceManufacturer??"",e.deviceModel=i.deviceModel??"",e.city=i.city??"",e.postalCode=i.postalCode??"",e}};S={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&&x.encode(i.bid,e.uint32(58).fork()).join(),i.namespace!==void 0&&i.namespace!==""&&e.uint32(66).string(i.namespace),i.eventId!==void 0&&i.eventId!==""&&e.uint32(74).string(i.eventId),globalThis.Object.entries(i.metadata||{}).forEach(([t,n])=>{q.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=ae();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=x.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=q.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 S.fromPartial(i??{})},fromPartial(i){let e=ae();return e.timestampMs=i.timestampMs??0,e.type=i.type??0,e.eventName=i.eventName??"",e.auctionId=i.auctionId??"",e.transactionId=i.transactionId??"",e.adUnitCode=i.adUnitCode??"",e.bid=i.bid!==void 0&&i.bid!==null?x.fromPartial(i.bid):void 0,e.namespace=i.namespace??"",e.eventId=i.eventId??"",e.metadata=globalThis.Object.entries(i.metadata??{}).reduce((t,[n,r])=>(r!==void 0&&(t[n]=globalThis.String(r)),t),{}),e.viewableDurationMs=i.viewableDurationMs??void 0,e}};q={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=de();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 q.fromPartial(i??{})},fromPartial(i){let e=de();return e.key=i.key??"",e.value=i.value??"",e}};x={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=ce();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 x.fromPartial(i??{})},fromPartial(i){let e=ce();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 Le(i){let e="";for(let n=0;n<i.length;n+=8192)e+=String.fromCharCode(...i.subarray(n,n+8192));return btoa(e)}function qe(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 ye(){let i=Date.now();v=i;try{typeof localStorage<"u"&&localStorage.setItem(k,i.toString())}catch{}}function $e(){let i=Date.now();try{if(typeof localStorage<"u"){let e=localStorage.getItem(he),t=localStorage.getItem(k),n=t&&parseInt(t,10)||0;if(e&&n&&i-n<=pe)return localStorage.setItem(k,i.toString()),e;let r=m();return localStorage.setItem(he,r),localStorage.setItem(k,i.toString()),r}}catch{}return D&&v&&i-v<=pe?(v=i,D):(D=m(),v=i,D)}function u(i){return String(i??"").replace(/%/g,"%25").replace(/:/g,"%3A")}function We(i,e){switch(i){case"auctionInit":return`auctionInit:${u(e?.auctionId)}`;case"auctionEnd":return`auctionEnd:${u(e?.auctionId)}`;case"bidRequested":{let t=Array.isArray(e?.bids)?e.bids.map(n=>u(n?.bidId||n?.transactionId||n?.adUnitCode)).join(","):"";return`bidRequested:${u(e?.auctionId)}:${u(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:${u(t.auctionId)}:${u(t.adUnitCode)}:${u(t.bidderCode||t.bidder)}:${u(n)}:${u(r)}`}case"bidTimeout":return"bidTimeout:"+(Array.isArray(e)?e:e?[e]:[]).map(n=>`${u(n?.auctionId)}:${u(n?.bidderCode||n?.bidder)}:${u(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:${u(t.auctionId)}:${u(t.adUnitCode)}:${u(t.bidderCode||t.bidder)}:${u(n)}:${u(r)}`}case"noBid":return`noBid:${u(e?.auctionId)}:${u(e?.adUnitCode)}:${u(e?.bidderCode||e?.bidder)}:${u(e?.bidId||e?.transactionId)}`;case"adRenderFailed":{let t=e?.bid||{};return`adRenderFailed:${u(t.auctionId||e?.auctionId)}:${u(t.adUnitCode||e?.adUnitCode)}:${u(t.bidderCode||t.bidder||e?.bidderCode||e?.bidder)}:${u(e?.reason)}:${u(e?.message)}`}case"adRenderSucceeded":{let t=e?.bid||e||{},n=t.creativeId||t.adId||e?.adId||"",r=t.originalCpm??t.cpm??"";return`adRenderSucceeded:${u(t.auctionId||e?.auctionId)}:${u(t.adUnitCode||e?.adUnitCode)}:${u(t.bidderCode||t.bidder)}:${u(n)}:${u(r)}`}case"setTargeting":return`setTargeting:${Object.keys(e||{}).sort().map(u).join(",")}`;case"auctionDebug":return`auctionDebug:${u(e?.type)}:${u(String(e?.arguments?.[0]??"").slice(0,50))}`;default:return""}}function be(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 $(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 Ge(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 K(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 G({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=Ge(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 ke,le,Ue,A,Ce,Ne,_e,fe,B,Pe,Me,Ve,Fe,Oe,he,k,pe,D,v,W,G,Ie=y(()=>{"use strict";ue();ke=20,le=1e4,Ue=50,A=200,Ce=300*1e3,Ne=10,_e=32*1024,fe="text/plain",B="_bidkernel_pending_",Pe=20,Me=7200*1e3,Ve=1e4,Fe={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},Oe=new Set([c.IMPRESSION,c.BID_WIN,c.CLICK]),he="_bidkernel_session",k="_bidkernel_session_ts",pe=1800*1e3,D=null,v=0;W=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=We(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}};G=class i{static activeInstances=new Set;config;queue=[];errorCount=0;flushTimer=null;boundFlushBeacon;boundVisibilityChange;isEnabled=!1;boundPbjsHandlers=[];pageUrl="";deduper=new W;consecutiveSendFailures=0;nextSendAllowedAt=0;replayedEventCount=0;immediateFlushScheduled=!1;persistedBatchKeys=[];persistedCleanupTimer=null;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||$e(),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(),le),this.resendPersistedBatches()}}}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),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(c.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(c.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(c.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(c.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=Fe[t]??(e==="ERROR"?c.ERROR:c.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="";ye(),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 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}=be(r.sizes||r.playerSize);this.enqueue(c.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:b}=be(f);this.enqueue(c.BID_REQUEST,"bidRequest",{auctionId:t,transactionId:a,adUnitCode:r.adUnitCode||"",gpid:o,bid:{bidder:n,mediaType:d,width:l,height:b}})})})}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",...$(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(c.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(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",...$(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 t=e.bid||{};this.enqueue(c.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",...$(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(c.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(c.IMPRESSION,"impression",{auctionId:r,transactionId:s,adUnitCode:n,bid:a,metadata:{refresh_index:String(f)}}),this.config.viewabilityEnabled&&typeof document<"u"){let l=null,b=n||e.adId||t.adId;if(b&&(l=document.getElementById(b)),!l&&typeof window<"u"&&window.googletag?.pubads)try{let me=window.googletag.pubads().getSlots();for(let U of me)if((U.getAdUnitPath?.()===n||U.getSlotElementId?.()===n)&&(l=document.getElementById(U.getSlotElementId()),l))break}catch{}if(!l&&b)try{l=document.querySelector(`[data-ad-slot="${b}"]`)||document.querySelector(`#${b}`)}catch{}l&&this.observeSlot(l,n||b,{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;ye();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>=ke?this.flush():Oe.has(e)&&!this.immediateFlushScheduled&&(this.immediateFlushScheduled=!0,setTimeout(()=>{this.immediateFlushScheduled=!1,this.flush()},0))}shouldSample(e,t){return e===c.ERROR?(this.errorCount++,this.errorCount>Ue?!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>_e;)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,n){let r={method:"POST",headers:{"Content-Type":fe},body:e.encoded};t&&(r.keepalive=!0),fetch(e.url,r).then(o=>{if(o.ok)this.consecutiveSendFailures=0,this.nextSendAllowedAt=0,n&&n();else{if(this.log("WARN",`Failed to send batch: HTTP ${o.status}`),o.status>=400&&o.status<500&&o.status!==429&&o.status!==408){this.log("WARN",`Dropping batch due to non-retryable client error HTTP ${o.status}`);return}this.handleSendFailure(e.events)}}).catch(o=>{this.log("ERROR","Failed to send batch",o),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(le*2**(this.consecutiveSendFailures-1),Ce);this.nextSendAllowedAt=Date.now()+t,this.consecutiveSendFailures<=Ne?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:fe});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()}persistBatch(e){try{if(typeof localStorage>"u")return null;let t=0;for(let r=0;r<localStorage.length;r++){let s=localStorage.key(r);s&&s.startsWith(B)&&t++}if(t>=Pe)return null;let n=`${B}${Date.now()}_${Math.floor(Math.random()*1e6)}`;return localStorage.setItem(n,Le(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[...this.persistedBatchKeys])this.removePersistedBatch(e)},Ve))}resendPersistedBatches(){try{if(typeof localStorage>"u"||!this.config.endpoint)return;let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n&&n.startsWith(B)&&e.push(n)}for(let t of e){let n=null;try{n=localStorage.getItem(t),localStorage.removeItem(t)}catch{continue}if(!n)continue;let r=parseInt(t.slice(B.length),10);if(!Number.isFinite(r)||Date.now()-r>Me)continue;let s;try{s=qe(n)}catch{continue}s.byteLength!==0&&(this.log("DEBUG",`Resending persisted exit batch (${s.byteLength} bytes)`),this.sendFetch({url:`${this.config.endpoint}/${this.config.propertyId}`,encoded:s,events:[]}))}}catch{}}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 ze=ge(()=>{Ie();var Te="https://by.bidkernel.io/t",Ke=window._bidkernelPbjsGlobal||"pbjs";K(Ke,{endpoint:Te});window.bidkernelPrebidAnalytics={...window.bidkernelPrebidAnalytics,register:(i,e)=>K(i,{endpoint:Te,...e})}});return ze();})();
|
package/dist/index.d.mts
CHANGED
|
@@ -64,6 +64,9 @@ declare class BidkernelPrebidAnalytics {
|
|
|
64
64
|
private consecutiveSendFailures;
|
|
65
65
|
private nextSendAllowedAt;
|
|
66
66
|
private replayedEventCount;
|
|
67
|
+
private immediateFlushScheduled;
|
|
68
|
+
private persistedBatchKeys;
|
|
69
|
+
private persistedCleanupTimer;
|
|
67
70
|
private intersectionObserver;
|
|
68
71
|
private slotViewabilityRecords;
|
|
69
72
|
private elementToSlotId;
|
|
@@ -109,6 +112,10 @@ declare class BidkernelPrebidAnalytics {
|
|
|
109
112
|
private handleSendFailure;
|
|
110
113
|
private flush;
|
|
111
114
|
private flushBeacon;
|
|
115
|
+
private persistBatch;
|
|
116
|
+
private removePersistedBatch;
|
|
117
|
+
private schedulePersistedCleanup;
|
|
118
|
+
private resendPersistedBatches;
|
|
112
119
|
private log;
|
|
113
120
|
}
|
|
114
121
|
declare function registerPrebidAnalytics(pbjsGlobalName?: string, defaults?: Partial<AnalyticsConfig>): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -64,6 +64,9 @@ declare class BidkernelPrebidAnalytics {
|
|
|
64
64
|
private consecutiveSendFailures;
|
|
65
65
|
private nextSendAllowedAt;
|
|
66
66
|
private replayedEventCount;
|
|
67
|
+
private immediateFlushScheduled;
|
|
68
|
+
private persistedBatchKeys;
|
|
69
|
+
private persistedCleanupTimer;
|
|
67
70
|
private intersectionObserver;
|
|
68
71
|
private slotViewabilityRecords;
|
|
69
72
|
private elementToSlotId;
|
|
@@ -109,6 +112,10 @@ declare class BidkernelPrebidAnalytics {
|
|
|
109
112
|
private handleSendFailure;
|
|
110
113
|
private flush;
|
|
111
114
|
private flushBeacon;
|
|
115
|
+
private persistBatch;
|
|
116
|
+
private removePersistedBatch;
|
|
117
|
+
private schedulePersistedCleanup;
|
|
118
|
+
private resendPersistedBatches;
|
|
112
119
|
private log;
|
|
113
120
|
}
|
|
114
121
|
declare function registerPrebidAnalytics(pbjsGlobalName?: string, defaults?: Partial<AnalyticsConfig>): void;
|
package/dist/index.js
CHANGED
|
@@ -658,6 +658,11 @@ var MAX_QUEUE_SIZE = 200;
|
|
|
658
658
|
var MAX_SEND_BACKOFF_MS = 5 * 60 * 1e3;
|
|
659
659
|
var MAX_CONSECUTIVE_SEND_FAILURES = 10;
|
|
660
660
|
var MAX_PAYLOAD_BYTES = 32 * 1024;
|
|
661
|
+
var SAFE_CONTENT_TYPE = "text/plain";
|
|
662
|
+
var PENDING_BATCH_KEY_PREFIX = "_bidkernel_pending_";
|
|
663
|
+
var MAX_PENDING_BATCHES = 20;
|
|
664
|
+
var PENDING_BATCH_MAX_AGE_MS = 2 * 60 * 60 * 1e3;
|
|
665
|
+
var PENDING_BATCH_CLEANUP_DELAY_MS = 1e4;
|
|
661
666
|
var EVENT_NAME_TO_TYPE = {
|
|
662
667
|
auctionStart: TraceEventType.AUCTION_START,
|
|
663
668
|
auctionEnd: TraceEventType.AUCTION_END,
|
|
@@ -673,6 +678,11 @@ var EVENT_NAME_TO_TYPE = {
|
|
|
673
678
|
timeInView: TraceEventType.TIME_IN_VIEW,
|
|
674
679
|
viewable: TraceEventType.VIEWABLE
|
|
675
680
|
};
|
|
681
|
+
var IMMEDIATE_FLUSH_TYPES = /* @__PURE__ */ new Set([
|
|
682
|
+
TraceEventType.IMPRESSION,
|
|
683
|
+
TraceEventType.BID_WIN,
|
|
684
|
+
TraceEventType.CLICK
|
|
685
|
+
]);
|
|
676
686
|
var SESSION_KEY = "_bidkernel_session";
|
|
677
687
|
var SESSION_TS_KEY = "_bidkernel_session_ts";
|
|
678
688
|
var THIRTY_MINUTES_MS = 30 * 60 * 1e3;
|
|
@@ -688,6 +698,22 @@ function generateUUID() {
|
|
|
688
698
|
return v.toString(16);
|
|
689
699
|
});
|
|
690
700
|
}
|
|
701
|
+
function bytesToBase64(bytes) {
|
|
702
|
+
let binary = "";
|
|
703
|
+
const chunk = 8192;
|
|
704
|
+
for (let i = 0; i < bytes.length; i += chunk) {
|
|
705
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
|
|
706
|
+
}
|
|
707
|
+
return btoa(binary);
|
|
708
|
+
}
|
|
709
|
+
function base64ToBytes(b64) {
|
|
710
|
+
const binary = atob(b64);
|
|
711
|
+
const bytes = new Uint8Array(binary.length);
|
|
712
|
+
for (let i = 0; i < binary.length; i++) {
|
|
713
|
+
bytes[i] = binary.charCodeAt(i);
|
|
714
|
+
}
|
|
715
|
+
return bytes;
|
|
716
|
+
}
|
|
691
717
|
function extendSession() {
|
|
692
718
|
const now = Date.now();
|
|
693
719
|
inMemorySessionTs = now;
|
|
@@ -852,6 +878,12 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
852
878
|
consecutiveSendFailures = 0;
|
|
853
879
|
nextSendAllowedAt = 0;
|
|
854
880
|
replayedEventCount = 0;
|
|
881
|
+
immediateFlushScheduled = false;
|
|
882
|
+
// localStorage keys of exit batches this instance persisted, so a page that
|
|
883
|
+
// survives its own pagehide/hidden (bfcache restore, tab re-focus) can
|
|
884
|
+
// remove them instead of leaving them for a duplicate resend.
|
|
885
|
+
persistedBatchKeys = [];
|
|
886
|
+
persistedCleanupTimer = null;
|
|
855
887
|
// Viewability & refresh tracking
|
|
856
888
|
intersectionObserver = null;
|
|
857
889
|
slotViewabilityRecords = /* @__PURE__ */ new Map();
|
|
@@ -976,6 +1008,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
976
1008
|
document.addEventListener("visibilitychange", this.boundVisibilityChange);
|
|
977
1009
|
}
|
|
978
1010
|
this.flushTimer = setInterval(() => this.flush(), FLUSH_INTERVAL_MS);
|
|
1011
|
+
this.resendPersistedBatches();
|
|
979
1012
|
}
|
|
980
1013
|
}
|
|
981
1014
|
disable() {
|
|
@@ -1006,6 +1039,10 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1006
1039
|
clearInterval(this.flushTimer);
|
|
1007
1040
|
this.flushTimer = null;
|
|
1008
1041
|
}
|
|
1042
|
+
if (this.persistedCleanupTimer) {
|
|
1043
|
+
clearTimeout(this.persistedCleanupTimer);
|
|
1044
|
+
this.persistedCleanupTimer = null;
|
|
1045
|
+
}
|
|
1009
1046
|
if (typeof window !== "undefined") {
|
|
1010
1047
|
window.removeEventListener("pagehide", this.boundFlushBeacon);
|
|
1011
1048
|
if (typeof document !== "undefined") {
|
|
@@ -1784,6 +1821,12 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1784
1821
|
}
|
|
1785
1822
|
if (this.queue.length >= BATCH_SIZE) {
|
|
1786
1823
|
this.flush();
|
|
1824
|
+
} else if (IMMEDIATE_FLUSH_TYPES.has(type) && !this.immediateFlushScheduled) {
|
|
1825
|
+
this.immediateFlushScheduled = true;
|
|
1826
|
+
setTimeout(() => {
|
|
1827
|
+
this.immediateFlushScheduled = false;
|
|
1828
|
+
this.flush();
|
|
1829
|
+
}, 0);
|
|
1787
1830
|
}
|
|
1788
1831
|
}
|
|
1789
1832
|
shouldSample(type, level) {
|
|
@@ -1840,10 +1883,11 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1840
1883
|
events
|
|
1841
1884
|
};
|
|
1842
1885
|
}
|
|
1843
|
-
sendFetch(payload, useKeepalive = false) {
|
|
1886
|
+
sendFetch(payload, useKeepalive = false, onDelivered) {
|
|
1844
1887
|
const fetchOpts = {
|
|
1845
1888
|
method: "POST",
|
|
1846
|
-
|
|
1889
|
+
// Safelisted content type: no CORS preflight (see SAFE_CONTENT_TYPE).
|
|
1890
|
+
headers: { "Content-Type": SAFE_CONTENT_TYPE },
|
|
1847
1891
|
body: payload.encoded
|
|
1848
1892
|
};
|
|
1849
1893
|
if (useKeepalive) {
|
|
@@ -1852,7 +1896,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1852
1896
|
fetch(payload.url, fetchOpts).then((res) => {
|
|
1853
1897
|
if (!res.ok) {
|
|
1854
1898
|
this.log("WARN", `Failed to send batch: HTTP ${res.status}`);
|
|
1855
|
-
if (res.status >= 400 && res.status < 500) {
|
|
1899
|
+
if (res.status >= 400 && res.status < 500 && res.status !== 429 && res.status !== 408) {
|
|
1856
1900
|
this.log("WARN", `Dropping batch due to non-retryable client error HTTP ${res.status}`);
|
|
1857
1901
|
return;
|
|
1858
1902
|
}
|
|
@@ -1860,14 +1904,16 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1860
1904
|
} else {
|
|
1861
1905
|
this.consecutiveSendFailures = 0;
|
|
1862
1906
|
this.nextSendAllowedAt = 0;
|
|
1907
|
+
if (onDelivered) onDelivered();
|
|
1863
1908
|
}
|
|
1864
1909
|
}).catch((err) => {
|
|
1865
1910
|
this.log("ERROR", "Failed to send batch", err);
|
|
1866
1911
|
this.handleSendFailure(payload.events);
|
|
1867
1912
|
});
|
|
1868
|
-
|
|
1913
|
+
const proc = typeof globalThis !== "undefined" ? globalThis.process : void 0;
|
|
1914
|
+
if (proc && typeof proc._tickCallback === "function") {
|
|
1869
1915
|
try {
|
|
1870
|
-
|
|
1916
|
+
proc._tickCallback();
|
|
1871
1917
|
} catch {
|
|
1872
1918
|
}
|
|
1873
1919
|
}
|
|
@@ -1903,19 +1949,99 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1903
1949
|
let sent = false;
|
|
1904
1950
|
if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
|
|
1905
1951
|
try {
|
|
1906
|
-
const blob = new Blob([payload.encoded], {
|
|
1907
|
-
type: "application/x-protobuf"
|
|
1908
|
-
});
|
|
1952
|
+
const blob = new Blob([payload.encoded], { type: SAFE_CONTENT_TYPE });
|
|
1909
1953
|
sent = navigator.sendBeacon(payload.url, blob);
|
|
1910
1954
|
} catch {
|
|
1911
1955
|
sent = false;
|
|
1912
1956
|
}
|
|
1913
1957
|
}
|
|
1914
1958
|
if (!sent) {
|
|
1915
|
-
this.
|
|
1959
|
+
const persistKey = this.persistBatch(payload.encoded);
|
|
1960
|
+
this.sendFetch(payload, true, () => this.removePersistedBatch(persistKey));
|
|
1916
1961
|
}
|
|
1917
1962
|
payload = this.drainBatch();
|
|
1918
1963
|
}
|
|
1964
|
+
this.schedulePersistedCleanup();
|
|
1965
|
+
}
|
|
1966
|
+
// --- Exit-batch persistence -----------------------------------------------
|
|
1967
|
+
persistBatch(encoded) {
|
|
1968
|
+
try {
|
|
1969
|
+
if (typeof localStorage === "undefined") return null;
|
|
1970
|
+
let pendingCount = 0;
|
|
1971
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
1972
|
+
const k = localStorage.key(i);
|
|
1973
|
+
if (k && k.startsWith(PENDING_BATCH_KEY_PREFIX)) pendingCount++;
|
|
1974
|
+
}
|
|
1975
|
+
if (pendingCount >= MAX_PENDING_BATCHES) return null;
|
|
1976
|
+
const key = `${PENDING_BATCH_KEY_PREFIX}${Date.now()}_${Math.floor(Math.random() * 1e6)}`;
|
|
1977
|
+
localStorage.setItem(key, bytesToBase64(encoded));
|
|
1978
|
+
this.persistedBatchKeys.push(key);
|
|
1979
|
+
return key;
|
|
1980
|
+
} catch {
|
|
1981
|
+
return null;
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
removePersistedBatch(key) {
|
|
1985
|
+
if (!key) return;
|
|
1986
|
+
try {
|
|
1987
|
+
if (typeof localStorage !== "undefined") localStorage.removeItem(key);
|
|
1988
|
+
} catch {
|
|
1989
|
+
}
|
|
1990
|
+
const idx = this.persistedBatchKeys.indexOf(key);
|
|
1991
|
+
if (idx !== -1) this.persistedBatchKeys.splice(idx, 1);
|
|
1992
|
+
}
|
|
1993
|
+
// A page that is still running PENDING_BATCH_CLEANUP_DELAY_MS after an exit
|
|
1994
|
+
// flush was never torn down, so its beacons have long since gone out; drop
|
|
1995
|
+
// the persisted copies rather than letting a later pageview resend them.
|
|
1996
|
+
schedulePersistedCleanup() {
|
|
1997
|
+
if (this.persistedBatchKeys.length === 0) return;
|
|
1998
|
+
if (this.persistedCleanupTimer) clearTimeout(this.persistedCleanupTimer);
|
|
1999
|
+
this.persistedCleanupTimer = setTimeout(() => {
|
|
2000
|
+
this.persistedCleanupTimer = null;
|
|
2001
|
+
for (const key of [...this.persistedBatchKeys]) {
|
|
2002
|
+
this.removePersistedBatch(key);
|
|
2003
|
+
}
|
|
2004
|
+
}, PENDING_BATCH_CLEANUP_DELAY_MS);
|
|
2005
|
+
}
|
|
2006
|
+
// Resend batches a previous pageview persisted at exit but could not
|
|
2007
|
+
// confirm. Keys are claimed (removed) before sending so concurrent tabs
|
|
2008
|
+
// don't double-send; the batch bytes carry their original pageview, session,
|
|
2009
|
+
// and event timestamps, so late rows attribute correctly.
|
|
2010
|
+
resendPersistedBatches() {
|
|
2011
|
+
try {
|
|
2012
|
+
if (typeof localStorage === "undefined" || !this.config.endpoint) return;
|
|
2013
|
+
const keys = [];
|
|
2014
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
2015
|
+
const k = localStorage.key(i);
|
|
2016
|
+
if (k && k.startsWith(PENDING_BATCH_KEY_PREFIX)) keys.push(k);
|
|
2017
|
+
}
|
|
2018
|
+
for (const key of keys) {
|
|
2019
|
+
let value = null;
|
|
2020
|
+
try {
|
|
2021
|
+
value = localStorage.getItem(key);
|
|
2022
|
+
localStorage.removeItem(key);
|
|
2023
|
+
} catch {
|
|
2024
|
+
continue;
|
|
2025
|
+
}
|
|
2026
|
+
if (!value) continue;
|
|
2027
|
+
const ts = parseInt(key.slice(PENDING_BATCH_KEY_PREFIX.length), 10);
|
|
2028
|
+
if (!Number.isFinite(ts) || Date.now() - ts > PENDING_BATCH_MAX_AGE_MS) continue;
|
|
2029
|
+
let encoded;
|
|
2030
|
+
try {
|
|
2031
|
+
encoded = base64ToBytes(value);
|
|
2032
|
+
} catch {
|
|
2033
|
+
continue;
|
|
2034
|
+
}
|
|
2035
|
+
if (encoded.byteLength === 0) continue;
|
|
2036
|
+
this.log("DEBUG", `Resending persisted exit batch (${encoded.byteLength} bytes)`);
|
|
2037
|
+
this.sendFetch({
|
|
2038
|
+
url: `${this.config.endpoint}/${this.config.propertyId}`,
|
|
2039
|
+
encoded,
|
|
2040
|
+
events: []
|
|
2041
|
+
});
|
|
2042
|
+
}
|
|
2043
|
+
} catch {
|
|
2044
|
+
}
|
|
1919
2045
|
}
|
|
1920
2046
|
log(level, msg, ...args) {
|
|
1921
2047
|
const levels = { DEBUG: 10, INFO: 20, WARN: 30, ERROR: 40 };
|
package/dist/index.mjs
CHANGED
|
@@ -628,6 +628,11 @@ var MAX_QUEUE_SIZE = 200;
|
|
|
628
628
|
var MAX_SEND_BACKOFF_MS = 5 * 60 * 1e3;
|
|
629
629
|
var MAX_CONSECUTIVE_SEND_FAILURES = 10;
|
|
630
630
|
var MAX_PAYLOAD_BYTES = 32 * 1024;
|
|
631
|
+
var SAFE_CONTENT_TYPE = "text/plain";
|
|
632
|
+
var PENDING_BATCH_KEY_PREFIX = "_bidkernel_pending_";
|
|
633
|
+
var MAX_PENDING_BATCHES = 20;
|
|
634
|
+
var PENDING_BATCH_MAX_AGE_MS = 2 * 60 * 60 * 1e3;
|
|
635
|
+
var PENDING_BATCH_CLEANUP_DELAY_MS = 1e4;
|
|
631
636
|
var EVENT_NAME_TO_TYPE = {
|
|
632
637
|
auctionStart: TraceEventType.AUCTION_START,
|
|
633
638
|
auctionEnd: TraceEventType.AUCTION_END,
|
|
@@ -643,6 +648,11 @@ var EVENT_NAME_TO_TYPE = {
|
|
|
643
648
|
timeInView: TraceEventType.TIME_IN_VIEW,
|
|
644
649
|
viewable: TraceEventType.VIEWABLE
|
|
645
650
|
};
|
|
651
|
+
var IMMEDIATE_FLUSH_TYPES = /* @__PURE__ */ new Set([
|
|
652
|
+
TraceEventType.IMPRESSION,
|
|
653
|
+
TraceEventType.BID_WIN,
|
|
654
|
+
TraceEventType.CLICK
|
|
655
|
+
]);
|
|
646
656
|
var SESSION_KEY = "_bidkernel_session";
|
|
647
657
|
var SESSION_TS_KEY = "_bidkernel_session_ts";
|
|
648
658
|
var THIRTY_MINUTES_MS = 30 * 60 * 1e3;
|
|
@@ -658,6 +668,22 @@ function generateUUID() {
|
|
|
658
668
|
return v.toString(16);
|
|
659
669
|
});
|
|
660
670
|
}
|
|
671
|
+
function bytesToBase64(bytes) {
|
|
672
|
+
let binary = "";
|
|
673
|
+
const chunk = 8192;
|
|
674
|
+
for (let i = 0; i < bytes.length; i += chunk) {
|
|
675
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
|
|
676
|
+
}
|
|
677
|
+
return btoa(binary);
|
|
678
|
+
}
|
|
679
|
+
function base64ToBytes(b64) {
|
|
680
|
+
const binary = atob(b64);
|
|
681
|
+
const bytes = new Uint8Array(binary.length);
|
|
682
|
+
for (let i = 0; i < binary.length; i++) {
|
|
683
|
+
bytes[i] = binary.charCodeAt(i);
|
|
684
|
+
}
|
|
685
|
+
return bytes;
|
|
686
|
+
}
|
|
661
687
|
function extendSession() {
|
|
662
688
|
const now = Date.now();
|
|
663
689
|
inMemorySessionTs = now;
|
|
@@ -822,6 +848,12 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
822
848
|
consecutiveSendFailures = 0;
|
|
823
849
|
nextSendAllowedAt = 0;
|
|
824
850
|
replayedEventCount = 0;
|
|
851
|
+
immediateFlushScheduled = false;
|
|
852
|
+
// localStorage keys of exit batches this instance persisted, so a page that
|
|
853
|
+
// survives its own pagehide/hidden (bfcache restore, tab re-focus) can
|
|
854
|
+
// remove them instead of leaving them for a duplicate resend.
|
|
855
|
+
persistedBatchKeys = [];
|
|
856
|
+
persistedCleanupTimer = null;
|
|
825
857
|
// Viewability & refresh tracking
|
|
826
858
|
intersectionObserver = null;
|
|
827
859
|
slotViewabilityRecords = /* @__PURE__ */ new Map();
|
|
@@ -946,6 +978,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
946
978
|
document.addEventListener("visibilitychange", this.boundVisibilityChange);
|
|
947
979
|
}
|
|
948
980
|
this.flushTimer = setInterval(() => this.flush(), FLUSH_INTERVAL_MS);
|
|
981
|
+
this.resendPersistedBatches();
|
|
949
982
|
}
|
|
950
983
|
}
|
|
951
984
|
disable() {
|
|
@@ -976,6 +1009,10 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
976
1009
|
clearInterval(this.flushTimer);
|
|
977
1010
|
this.flushTimer = null;
|
|
978
1011
|
}
|
|
1012
|
+
if (this.persistedCleanupTimer) {
|
|
1013
|
+
clearTimeout(this.persistedCleanupTimer);
|
|
1014
|
+
this.persistedCleanupTimer = null;
|
|
1015
|
+
}
|
|
979
1016
|
if (typeof window !== "undefined") {
|
|
980
1017
|
window.removeEventListener("pagehide", this.boundFlushBeacon);
|
|
981
1018
|
if (typeof document !== "undefined") {
|
|
@@ -1754,6 +1791,12 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1754
1791
|
}
|
|
1755
1792
|
if (this.queue.length >= BATCH_SIZE) {
|
|
1756
1793
|
this.flush();
|
|
1794
|
+
} else if (IMMEDIATE_FLUSH_TYPES.has(type) && !this.immediateFlushScheduled) {
|
|
1795
|
+
this.immediateFlushScheduled = true;
|
|
1796
|
+
setTimeout(() => {
|
|
1797
|
+
this.immediateFlushScheduled = false;
|
|
1798
|
+
this.flush();
|
|
1799
|
+
}, 0);
|
|
1757
1800
|
}
|
|
1758
1801
|
}
|
|
1759
1802
|
shouldSample(type, level) {
|
|
@@ -1810,10 +1853,11 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1810
1853
|
events
|
|
1811
1854
|
};
|
|
1812
1855
|
}
|
|
1813
|
-
sendFetch(payload, useKeepalive = false) {
|
|
1856
|
+
sendFetch(payload, useKeepalive = false, onDelivered) {
|
|
1814
1857
|
const fetchOpts = {
|
|
1815
1858
|
method: "POST",
|
|
1816
|
-
|
|
1859
|
+
// Safelisted content type: no CORS preflight (see SAFE_CONTENT_TYPE).
|
|
1860
|
+
headers: { "Content-Type": SAFE_CONTENT_TYPE },
|
|
1817
1861
|
body: payload.encoded
|
|
1818
1862
|
};
|
|
1819
1863
|
if (useKeepalive) {
|
|
@@ -1822,7 +1866,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1822
1866
|
fetch(payload.url, fetchOpts).then((res) => {
|
|
1823
1867
|
if (!res.ok) {
|
|
1824
1868
|
this.log("WARN", `Failed to send batch: HTTP ${res.status}`);
|
|
1825
|
-
if (res.status >= 400 && res.status < 500) {
|
|
1869
|
+
if (res.status >= 400 && res.status < 500 && res.status !== 429 && res.status !== 408) {
|
|
1826
1870
|
this.log("WARN", `Dropping batch due to non-retryable client error HTTP ${res.status}`);
|
|
1827
1871
|
return;
|
|
1828
1872
|
}
|
|
@@ -1830,14 +1874,16 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1830
1874
|
} else {
|
|
1831
1875
|
this.consecutiveSendFailures = 0;
|
|
1832
1876
|
this.nextSendAllowedAt = 0;
|
|
1877
|
+
if (onDelivered) onDelivered();
|
|
1833
1878
|
}
|
|
1834
1879
|
}).catch((err) => {
|
|
1835
1880
|
this.log("ERROR", "Failed to send batch", err);
|
|
1836
1881
|
this.handleSendFailure(payload.events);
|
|
1837
1882
|
});
|
|
1838
|
-
|
|
1883
|
+
const proc = typeof globalThis !== "undefined" ? globalThis.process : void 0;
|
|
1884
|
+
if (proc && typeof proc._tickCallback === "function") {
|
|
1839
1885
|
try {
|
|
1840
|
-
|
|
1886
|
+
proc._tickCallback();
|
|
1841
1887
|
} catch {
|
|
1842
1888
|
}
|
|
1843
1889
|
}
|
|
@@ -1873,19 +1919,99 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1873
1919
|
let sent = false;
|
|
1874
1920
|
if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
|
|
1875
1921
|
try {
|
|
1876
|
-
const blob = new Blob([payload.encoded], {
|
|
1877
|
-
type: "application/x-protobuf"
|
|
1878
|
-
});
|
|
1922
|
+
const blob = new Blob([payload.encoded], { type: SAFE_CONTENT_TYPE });
|
|
1879
1923
|
sent = navigator.sendBeacon(payload.url, blob);
|
|
1880
1924
|
} catch {
|
|
1881
1925
|
sent = false;
|
|
1882
1926
|
}
|
|
1883
1927
|
}
|
|
1884
1928
|
if (!sent) {
|
|
1885
|
-
this.
|
|
1929
|
+
const persistKey = this.persistBatch(payload.encoded);
|
|
1930
|
+
this.sendFetch(payload, true, () => this.removePersistedBatch(persistKey));
|
|
1886
1931
|
}
|
|
1887
1932
|
payload = this.drainBatch();
|
|
1888
1933
|
}
|
|
1934
|
+
this.schedulePersistedCleanup();
|
|
1935
|
+
}
|
|
1936
|
+
// --- Exit-batch persistence -----------------------------------------------
|
|
1937
|
+
persistBatch(encoded) {
|
|
1938
|
+
try {
|
|
1939
|
+
if (typeof localStorage === "undefined") return null;
|
|
1940
|
+
let pendingCount = 0;
|
|
1941
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
1942
|
+
const k = localStorage.key(i);
|
|
1943
|
+
if (k && k.startsWith(PENDING_BATCH_KEY_PREFIX)) pendingCount++;
|
|
1944
|
+
}
|
|
1945
|
+
if (pendingCount >= MAX_PENDING_BATCHES) return null;
|
|
1946
|
+
const key = `${PENDING_BATCH_KEY_PREFIX}${Date.now()}_${Math.floor(Math.random() * 1e6)}`;
|
|
1947
|
+
localStorage.setItem(key, bytesToBase64(encoded));
|
|
1948
|
+
this.persistedBatchKeys.push(key);
|
|
1949
|
+
return key;
|
|
1950
|
+
} catch {
|
|
1951
|
+
return null;
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
removePersistedBatch(key) {
|
|
1955
|
+
if (!key) return;
|
|
1956
|
+
try {
|
|
1957
|
+
if (typeof localStorage !== "undefined") localStorage.removeItem(key);
|
|
1958
|
+
} catch {
|
|
1959
|
+
}
|
|
1960
|
+
const idx = this.persistedBatchKeys.indexOf(key);
|
|
1961
|
+
if (idx !== -1) this.persistedBatchKeys.splice(idx, 1);
|
|
1962
|
+
}
|
|
1963
|
+
// A page that is still running PENDING_BATCH_CLEANUP_DELAY_MS after an exit
|
|
1964
|
+
// flush was never torn down, so its beacons have long since gone out; drop
|
|
1965
|
+
// the persisted copies rather than letting a later pageview resend them.
|
|
1966
|
+
schedulePersistedCleanup() {
|
|
1967
|
+
if (this.persistedBatchKeys.length === 0) return;
|
|
1968
|
+
if (this.persistedCleanupTimer) clearTimeout(this.persistedCleanupTimer);
|
|
1969
|
+
this.persistedCleanupTimer = setTimeout(() => {
|
|
1970
|
+
this.persistedCleanupTimer = null;
|
|
1971
|
+
for (const key of [...this.persistedBatchKeys]) {
|
|
1972
|
+
this.removePersistedBatch(key);
|
|
1973
|
+
}
|
|
1974
|
+
}, PENDING_BATCH_CLEANUP_DELAY_MS);
|
|
1975
|
+
}
|
|
1976
|
+
// Resend batches a previous pageview persisted at exit but could not
|
|
1977
|
+
// confirm. Keys are claimed (removed) before sending so concurrent tabs
|
|
1978
|
+
// don't double-send; the batch bytes carry their original pageview, session,
|
|
1979
|
+
// and event timestamps, so late rows attribute correctly.
|
|
1980
|
+
resendPersistedBatches() {
|
|
1981
|
+
try {
|
|
1982
|
+
if (typeof localStorage === "undefined" || !this.config.endpoint) return;
|
|
1983
|
+
const keys = [];
|
|
1984
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
1985
|
+
const k = localStorage.key(i);
|
|
1986
|
+
if (k && k.startsWith(PENDING_BATCH_KEY_PREFIX)) keys.push(k);
|
|
1987
|
+
}
|
|
1988
|
+
for (const key of keys) {
|
|
1989
|
+
let value = null;
|
|
1990
|
+
try {
|
|
1991
|
+
value = localStorage.getItem(key);
|
|
1992
|
+
localStorage.removeItem(key);
|
|
1993
|
+
} catch {
|
|
1994
|
+
continue;
|
|
1995
|
+
}
|
|
1996
|
+
if (!value) continue;
|
|
1997
|
+
const ts = parseInt(key.slice(PENDING_BATCH_KEY_PREFIX.length), 10);
|
|
1998
|
+
if (!Number.isFinite(ts) || Date.now() - ts > PENDING_BATCH_MAX_AGE_MS) continue;
|
|
1999
|
+
let encoded;
|
|
2000
|
+
try {
|
|
2001
|
+
encoded = base64ToBytes(value);
|
|
2002
|
+
} catch {
|
|
2003
|
+
continue;
|
|
2004
|
+
}
|
|
2005
|
+
if (encoded.byteLength === 0) continue;
|
|
2006
|
+
this.log("DEBUG", `Resending persisted exit batch (${encoded.byteLength} bytes)`);
|
|
2007
|
+
this.sendFetch({
|
|
2008
|
+
url: `${this.config.endpoint}/${this.config.propertyId}`,
|
|
2009
|
+
encoded,
|
|
2010
|
+
events: []
|
|
2011
|
+
});
|
|
2012
|
+
}
|
|
2013
|
+
} catch {
|
|
2014
|
+
}
|
|
1889
2015
|
}
|
|
1890
2016
|
log(level, msg, ...args) {
|
|
1891
2017
|
const levels = { DEBUG: 10, INFO: 20, WARN: 30, ERROR: 40 };
|
package/package.json
CHANGED