(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let t=e=>e!==void 0,n=[0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,59],r=e=>{if(!e)throw Error(`IllegalArgumentException`);let t={_value:[108,98,39,46,7,187,1,66,98,184,33,117,98,149,197,141],_scratch:Array(16)};function r(){let e,r;for(r=0;r<16;r++)t._scratch[r]=0;for(r=0;r<16;r++)for(let i=0;i<16-r;i++)e=t._value[15-r]*n[15-i]+(t._scratch[15-(r+i)]||0),e>255&&(r+i+1<16&&(t._scratch[15-(r+i+1)]+=e>>>8),e-=e>>>8<<8),t._scratch[15-(r+i)]=e;let i=t._scratch;t._scratch=t._value,t._value=i}function i(e){let n;if(typeof e==`string`){let t=e.replace(/\r\n/g,` `),r=[],i=0;for(n=0;n>6|192,r[i++]=e&63|128):(r[i++]=e>>12|224,r[i++]=e>>6&63|128,r[i++]=e&63|128)}e=r}for(n=0;ne+(`00`+t.toString(16)).slice(-2),``)}return i(e),a()},i=(e,...t)=>{if(t.length===0||t.join(``)===``)throw Error(`Failed to create hash`);return r(t.join(``)).substr(0,e)},a=(...e)=>{try{return i(14,...e)}catch{throw Error(`Failed to create an auction Id`)}},o=(...e)=>{try{return i(8,...e)}catch{throw Error(`Failed to create a bid Id`)}},s=()=>r(`${Math.random().toString(36)}${new Date().getTime()}`);function c(e,t){let n=[];if(e.forEach(e=>{try{t(e)}catch(e){n.push(e)}}),n.length!==0){let e=`forEach: Unexpected (${n.length}) errors\n${n.reduce((e,t)=>`${e}\t- ${t.message}\n`,``)}`;throw Error(e)}}var l=class e{constructor(e){this.subscriptions=[],this.children=[],this.processingChain=e?[...e]:[]}subscribe(e,t){this.subscriptions.push({onEvent:e,onError:t})}unsubscribe(e,t){this.subscriptions=this.subscriptions.filter(n=>!(n.onEvent===e&&n.onError===t))}pipe(...t){let n=new e([...this.processingChain,...t]);return this.children.push(n),n}next(e){this.subscriptions.forEach(t=>{try{let n=this.processingChain.reduce((e,t)=>{if(e!==void 0)return t(e)},e);n!==void 0&&t.onEvent(n)}catch(e){t.onError&&t.onError(e)}}),this.children.forEach(t=>t.next(e))}};let u=e=>e,d=e=>t=>{if(e(t))return t},f=e=>[d(([t])=>e.test(t)),u(([,[e,...t]])=>[e,t])],p=e=>e.state===`bidResponse`,m=e=>p(e)?e.bidResponseId:e.bidId,h=[`banner`,`instream`],ee=[`one`,`node`,`analytics`];var g=class extends Error{constructor(e){super(e)}};function _(e,t){if(!Array.isArray(e))throw new g(t??`Expected value to be an array, but received ${typeof e}`)}function te(e,t){_(e,t),e.every(e=>y(e))}function ne(e){return typeof e==`number`&&!isNaN(e)}function re(e){return typeof e==`boolean`}function v(e){return typeof e==`string`}function ie(e,t){if(!ne(e))throw new g(t??`Expected value to be a number, but received ${typeof e}`)}function ae(e,t){if(e!=null&&!ne(e))throw new g(t??`Expected value to be a number, but received ${typeof e}`)}function oe(e,t){if(e!=null&&typeof e!=`string`)throw new g(t??`Expected value to be a string, undefined or null, but received ${typeof e}`)}function se(e,t){if(e!=null&&!re(e))throw new g(t??`Expected value to be a boolean, but received ${typeof e}`)}function y(e,t){if(typeof e!=`string`)throw new g(t??`Expected value to be a string, but received ${typeof e}`)}function ce(e,t){if(e!==void 0)throw new g(t??`Expected value to be undefined, but received ${e}`)}function le(e,t){if(e==null)throw new g(t??`Expected value to be defined, but received ${e}`)}function ue(e,t,n){if(!t.includes(e))throw new g(n??`Expected values to be one of '${t}', but received ${e}`)}function de(e,t){if(!Array.isArray(e)||e.filter(e=>e!==void 0).length===0)throw new g(t??`Expected array to be not empty`)}let fe=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function b(e,t){if(!fe(e))throw new g(t??`Expected value to be record, but received '${typeof e}'`)}let x=(e,t)=>fe(e)&&t in e;function pe(e,t,n){if(!x(e,t))throw new g(n??`Expected object to have key '${t}', but not found`)}function me(e){return e!=null}let he=[],ge=new l;function _e(e){ge.subscribe(e)}function ve(e,t){let n=0;he.push(r=>{n>=t||(n+=1,e(r))})}function ye(e){he.forEach(t=>t({error:e}))}function S(e){ye({context:e.context??{},message:e.message})}let be=/pbstck:debug/.test(window.location.href),xe=window.localStorage?.getItem?window.localStorage.getItem(`pbstck`)!==null:!1,Se=`[pbstck-1bd8f5d]`;function C(){return be||xe}function w(...e){C()&&console.log(Se,...e)}function T(...e){C()&&console.warn(Se,...e)}function Ce(...e){C()&&console.error(Se,...e)}let we=`39216077.6943.8456.1021524.1026508.1030155.2165149.2444258.4708965.5624990.7321515.7687385.17085479.22181265.27416722.46481815.49313688.91083230.127208727.22247219933.22815767462.22815767462,20542308.22181265,20542308.22702991301.22665197336.22022010600.21866864457.21823883819.21794835430.21734370771.21722279357`.split(`.`),Te=e=>{let t={code:e.code,name:Oe(e),path:ke(e)},n=e.pubstack?.adUnitType;return Ee(n)&&(t.type=n),t},Ee=e=>h.includes(e),De=e=>e?.endsWith(`-pbstck`)?`mpv1`:`unknown`,Oe=e=>{if(!e.pubstack?.adUnitName&&e.ortb2Imp)for(let t of we){if(e.ortb2Imp?.ext?.data?.pbadslot?.startsWith(`/${t}/`))return e.ortb2Imp.ext.data.pbadslot.replace(/\/$/,``).split(`/`).pop()||e.code;if(e.ortb2Imp?.ext?.gpid?.startsWith(`/${t}/`))return e.ortb2Imp.ext.gpid.replace(/\/$/,``).split(`/`).pop()||e.code}return e.pubstack?.adUnitName??e.code},ke=e=>{if(e.pubstack?.adUnitPath)return Fe(e.pubstack.adUnitPath);if(e.ortb2Imp){if(e.ortb2Imp.ext.data.pbadslot)return Fe(e.ortb2Imp.ext.data.pbadslot);if(e.ortb2Imp.ext.gpid)return Fe(e.ortb2Imp.ext.gpid)}},Ae=e=>{let t=[];return e.forEach(e=>{Ke(e).bids.forEach(e=>{t.some(t=>t.bidder===e.bidder)||t.push(e)})}),t},je=e=>{let t;return e.forEach(e=>{let n=Ke(e);n.ortb2Imp?t=n.ortb2Imp:JSON.stringify(n.ortb2Imp)!==JSON.stringify(t)&&T(`Two different ortb2imp declaration found for a adUnitCode ${n.code}`,n.ortb2Imp,t)}),t},Me=e=>{let t;return e.forEach(e=>{let n=Ke(e);n.pubstack&&Object.keys(n.pubstack).length!=0?t=n.pubstack:JSON.stringify(n.pubstack)!==JSON.stringify(t)&&T(`Two different pubstack declaration found for a adUnitCode ${n.code}`,n.pubstack,t)}),t},Ne=e=>{let t={};return e.forEach(e=>{let n=Ke(e);n.mediaTypes.native!==void 0&&(t.native=n.mediaTypes.native),n.mediaTypes.video!==void 0&&n.mediaTypes.video.playerSize&&(t.video?t.video.playerSize=[...t.video.playerSize,...n.mediaTypes.video.playerSize]:t.video=n.mediaTypes.video),n.mediaTypes.banner!==void 0&&(t.banner?(t.banner.sizes=[...t.banner.sizes,...n.mediaTypes.banner.sizes],n.mediaTypes.banner.sizeConfig&&(t.banner.sizeConfig=n.mediaTypes.banner.sizeConfig)):t.banner=n.mediaTypes.banner)}),t},Pe=e=>{let t=e=>typeof e==`string`?e:Array.isArray(e)&&e.length===2?`${e[0]}x${e[1]}`:`unknown`,n=e=>{let n=t(e);return n===`unknown`?`video`:`video-${n}`},r=e=>(e.mediaTypes.banner?.sizes===void 0||e.mediaTypes.banner?.sizes.length===0)&&e.mediaTypes.native===void 0&&e.mediaTypes.video===void 0,i=new Set;return r(e)?[]:(e.mediaTypes.banner?.sizes&&(Array.isArray(e.mediaTypes.banner.sizes[0])?e.mediaTypes.banner.sizes.forEach(e=>i.add(t(e))):i.add(t(e.mediaTypes.banner.sizes))),e.mediaTypes.video?.playerSize&&e.mediaTypes.video?.playerSize.forEach(e=>i.add(n(e))),e.mediaTypes.native&&i.add(`native`),Array.from(i))},Fe=e=>e.startsWith(`/`)?e:`/${e}`,Ie=e=>{let t=e=>typeof e==`string`,n=/^(adUnitPath)/;return(e.pubstack?.tags??[]).filter(t).filter(e=>e.length>0&&e.length<256||n.test(e))},Le=e=>e.placementId||e.zoneId||e.siteId||void 0,Re=e=>{let t=Le(e);if(t)return`slot:${t}`},ze=e=>(_(e),e.length>0&&e.every(e=>le(e.bidderRequestId)),e),Be=e=>{let t={hasUserId:`notAvailable`,userIdProviderList:[]};if(e.length===0)return t;let n=!0,r=e[0].bids[0];return e.forEach(e=>{e.bids.forEach(e=>{let i=Object.entries(e.userId||{}).flatMap(([e,t])=>{if(Array.isArray(t)){let n=t.filter(e=>Object.hasOwn(e,`source`)).map(t=>`${e}:${t.source}`);return n.length?n:e}return e}).concat(Object.keys(e.crumbs||{}));if(i.length===0){if(t.userIdProviderList=t.userIdProviderList.concat((e.userIdAsEids||[]).map(e=>e.source)),n&&=typeof r.userIdAsEids==typeof e.userIdAsEids,r.userIdAsEids&&e.userIdAsEids){let t=r.userIdAsEids.map(e=>e.source),i=e.userIdAsEids.map(e=>e.source);n=n&&t.length===i.length&&t.every(e=>i.includes(e))}}else{if(t.userIdProviderList=t.userIdProviderList.concat(i),n&&=typeof r.crumbs==typeof e.crumbs,r.crumbs&&e.crumbs){let t=Object.keys(r.crumbs),i=Object.keys(e.crumbs);n=n&&t.length===i.length&&t.every(e=>i.includes(e))}if(n&&=typeof r.userId==typeof e.userId,r.userId&&e.userId){let t=Object.keys(r.userId),i=Object.keys(e.userId);n=n&&t.length===i.length&&t.every(e=>i.includes(e))}}})}),t.userIdProviderList.length>0&&n?t.hasUserId=`available`:t.userIdProviderList.length>0&&!n&&(t.hasUserId=`notConsistent`),t.userIdProviderList=Array.from(new Set(t.userIdProviderList)),t},Ve=e=>{let t=e;return!(!t||!t.purposeConsents||!t.vendorConsents)},He=e=>{let t=e;return!(!t||!t.purpose||!t.purpose.consents||!t.vendor||!t.vendor.consents)},Ue=e=>{let t={userConsentState:`notAvailable`,userConsentVersion:`notAvailable`};if(e===void 0)return t;let n=!1,r=!1;if(!e.apiVersion||e.apiVersion===1){if(t.userConsentVersion=`tcf-v1`,typeof e.gdprApplies==`boolean`&&!e.gdprApplies)return{...t,userConsentState:`notApplicable`};if(Ve(e.vendorData)){let i=Object.values(e.vendorData.purposeConsents),a=Object.values(e.vendorData.vendorConsents);if(n=i.filter(e=>e).length>0,r=a.filter(e=>e).length>0,i.length===0||a.length===0)return{...t,userConsentState:`notAvailable`}}}else if(e.apiVersion===2){if(t.userConsentVersion=`tcf-v2`,typeof e.gdprApplies==`boolean`&&!e.gdprApplies)return{...t,userConsentState:`notApplicable`};if(He(e.vendorData)){let i=Object.values(e.vendorData.purpose.consents),a=Object.values(e.vendorData.vendor.consents);if(n=i.filter(e=>e).length>0,r=a.filter(e=>e).length>0,i.length===0||a.length===0)return{...t,userConsentState:`notAvailable`}}}else if(e.apiVersion>2)throw Error(`API version is not yet supported: ${e.apiVersion}`);else throw Error(`An issue occured while identifying TCF version: ${e.apiVersion}`);return t.userConsentState=n&&r?`accepted`:`refused`,t},We=e=>{let t=e.map(e=>e.gdprConsent).filter(e=>e!==void 0);return e.length!==t.length&&(t=[]),t},Ge=e=>{let t={userConsentState:`notAvailable`,userConsentVersion:`notAvailable`};try{if(e.length===0)return t;let n=e.every((e,t,n)=>e.apiVersion===n[0].apiVersion),r=e.every((e,t,n)=>e.consentString===n[0].consentString);if(!n||!r)throw Error(`API version and Consent string must be unique within a bid request array`);let i=e[0];return Ue(i)}catch(e){return e.context=e.context||{},e.context.pbjs={source:`pbjs:helpers`},S(e),t}},Ke=e=>JSON.parse(JSON.stringify(e)),qe=e=>{if(!e)return;let t=Array.isArray(e)?e[0]:e;if(typeof t==`object`&&t){let e=t;if(typeof e.adUnitName==`string`)return e.adUnitName}},Je={gracePeriod:400,version:`unknown`,pbjsVariableName:`pbjs`},Ye=new Map;var Xe=class{constructor(e,t=!1){this.onBidResponseStream=new l,this.onAuctionEndStream=new l,this.onBidWonStream=new l,this.onBidWonFromSdkStream=new l,this.pubstackAdUnitNameCache=new Map,e&&(this.pbjsConfig=e),this.admOnboarding=t}getAdServerCurrency(){return this.pbjsConfig?.adServerCurrency}onBidResponse(e){let t=a(e.adUnitCode,e.auctionId),n=o(e.requestId),r=o(n,e.adId);Ye.set(e.adId,n),this.onBidResponseStream.next({adId:e.adId,auctionId:t,dealId:e.dealId||void 0,bidId:n,bidResponseId:r,cpm:e.cpm,currency:e.currency,size:e.size,mediaType:e.mediaType,tags:[],bidderCode:e.bidderCode,customFields:{demandSource:e.demandSource},timeToRespond:e.timeToRespond,adapterCode:e.adapterCode,advertiserDomains:e.advertiserDomains,bidderType:De(e.bidderCode)})}onAuctionEnd(e,n=`prebid`){let r=window[this.pbjsConfig?.pbjsVariableName||`pbjs`]?.aliasRegistry||{};c(e.adUnits.filter(t=>e.adUnitCodes===void 0||e.adUnitCodes.includes(t.code)).reduce((e,t)=>(e.find(e=>t.code===e.code)||e.push(t),e),[]),i=>{let c=Ze(e,i.code),l=c.bids.find(e=>e.bidder===`pubstack_server`||e.bidder===`pubstack`);if(l){let t=`${e.auctionId}:${i.code}`,n=qe(l.params);n&&this.pubstackAdUnitNameCache.set(t,n)}let u=Te(c),d=a(c.code,e.auctionId),f=e.labels||[],p=ze(e.bidderRequests),m=e.bidderRequests.flatMap(n=>{let l=a(i.code,e.auctionId),d=n.gdprConsent,f=n.bidderCode,p=r[f],m=Qe((n.metrics?.getMetrics?.()??{})[`adapter.client.total`])??e.timeout,h=(e.seatNonBids?.find(e=>e.seat===n.bidderCode))?.nonbid.find(e=>e.impid===i.code),ee=n.bids.filter(e=>e.adUnitCode===i.code).map(n=>{let r=o(n.bidId),i=e.bidsReceived.find(e=>e.requestId===n.bidId),a=e.noBids.find(e=>e.bidId===n.bidId),s=e.bidsRejected.find(e=>e.requestId===n.bidId),h={state:`bidTimeout`,timeToRespond:m},ee={};if(i){let e=o(r,i.adId);ee.demandSource=i.demandSource,h={adId:i.adId,bidResponseId:e,cpm:i.cpm,currency:i.currency,size:i.size,mediaType:i.mediaType,bidNetRevenue:i.netRevenue,state:`bidResponse`,timeToRespond:i.timeToRespond??m,dealId:i.dealId||void 0,advertiserDomains:i.advertiserDomains,bidderType:De(i.bidderCode)}}else a?h={state:`noBid`,timeToRespond:m}:s&&(h={state:`noBid`,rejectionReason:s.rejectionReason,timeToRespond:m});return{auctionId:l,bidId:r,gdprConsent:d,bidderCode:f,adapterCode:p,source:n.src,tags:[Re(n.params)].filter(t),customFields:ee,admMapping:{adUnitCode:u.code,adUnitName:u.name,adUnitPath:u.path,bidderCode:p||f,bidderParams:JSON.stringify(n.params),requestedSizes:Pe(c)},...h}});return h&&ee.push({bidId:o(s()),auctionId:l,gdprConsent:d,bidderCode:f,adapterCode:r[f],source:`s2s`,tags:[],customFields:{source:`s2s`},state:h.statuscode===101?`bidTimeout`:`noBid`,timeToRespond:m}),ee}),h={source:n},ee;if(this.admOnboarding){let t=window[this.pbjsConfig.pbjsVariableName],n=t.installedModules,{userSync:r,fledgeForGpt:i,floors:a,paapi:o,schain:s,realTimeData:c}=t.getConfig()||{};ee={adUnitCode:u.code,fledgeForGpt:JSON.stringify(i),floors:JSON.stringify(a),installedModules:JSON.stringify(n),paapi:JSON.stringify(o),realTimeData:JSON.stringify(c),schain:JSON.stringify(s),timeout:e.timeout,userSync:JSON.stringify(r)}}let g={auctionId:d,adUnit:u,refreshIndex:0,sizes:Pe(c),userId:Be(p),pbjsVersion:this.pbjsConfig?.version??Je.version,tags:[...Ie(c)],labels:f,gracePeriod:this.pbjsConfig?.gracePeriod??Je.gracePeriod,duration:e.auctionEnd-e.timestamp,bidRequests:m,timeout:e.timeout,customFields:h,admConfig:ee};this.onAuctionEndStream.next(g)})}onBidWon(e){let t=window[this.pbjsConfig.pbjsVariableName]?.aliasRegistry||{},n=`${e.auctionId}:${e.adUnitCode}`,r=this.pubstackAdUnitNameCache.get(n);this.pubstackAdUnitNameCache.delete(n);let i={...e,pbstckAdapterCode:t[e.bidderCode],bidNetRevenue:e.netRevenue,dealId:e.dealId||void 0,auctionId:a(e.adUnitCode,e.auctionId),tags:[],customFields:{source:`prebid`,demandSource:e.demandSource},pubstackServerAdunitName:r,bidderType:De(e.bidderCode)};this.onBidWonStream.next(i)}onBidWonFromSdk(e){let t={...e,customFields:{source:`sdk`}};this.onBidWonFromSdkStream.next(t)}};function Ze(e,t){let n=e.adUnits.filter(e=>e.code===t),r={code:t,bids:Ae(n),mediaTypes:Ne(n)},i=Me(n);i&&(r.pubstack=i);let a=je(n);return a&&(r.ortb2Imp=a),r}function Qe(e){let t=typeof e==`number`?e:e?.value;return typeof t==`number`&&Number.isFinite(t)?Math.trunc(t):void 0}let $e=(e,t,n)=>{let r=e;r[n]=r[n]||[];let i=r[n];e.pbstck=e.pbstck||{},e.pbstck.sdk=e.pbstck.sdk||{},e.pbstck.sdk[t]=e.pbstck.sdk[t]||{p:[],q:i},e.pbstck.sdk[t].p=e.pbstck.sdk[t].p||[],e.pbstck.sdk[t].q=e.pbstck.sdk[t].q||i,e.pbstck.sdk[t].q!==i&&(e.pbstck.sdk[t].q=e.pbstck.sdk[t].q.concat(i));let a={cmd:(...n)=>{let r=[`cmd`,n];(e.pbstck.sdk[t].q||[]).push(r),(e.pbstck.sdk[t].p||[]).forEach(e=>e(r))}};return e.Pubstack=a,a},et=e=>{let t=[];return JSON.parse(JSON.stringify(e,(e,n)=>{if(typeof n==`object`&&n){if(t.includes(n))return;t.push(n)}return n}))},tt={AUCTION_INIT:`auctionInit`,AUCTION_END:`auctionEnd`,BID_TIMEOUT:`bidTimeout`,BID_REQUESTED:`bidRequested`,BID_RESPONSE:`bidResponse`,BID_WON:`bidWon`,NO_BID:`noBid`},nt=new l;function rt(e){nt.subscribe(e)}function it(e){let t=window.pbstck.scopeId,n=window.pbstck.tagId,r={...e,source:`collector`,type:`log`,tagId:n,scopeId:t};nt.next(r)}function at(e,t,n=`prebid`){return{on(r,i){w(`[pbjsIntegration] pbjs.dispatcher (${n}) ${r}`,i),n===`sdk`&&it({id:`sdk-usage`,level:`info`,message:`sdk usage`,eventName:r}),r===tt.AUCTION_END&&t.onAuctionEnd(e.toAuctionEnd(i),n),r===tt.BID_RESPONSE&&t.onBidResponse(e.toBidResponse(i)),r===tt.BID_WON&&n===`prebid`&&t.onBidWon(e.toBidWon(i)),r===tt.BID_WON&&n===`sdk`&&t.onBidWonFromSdk(e.toBidWonFromSdk(i))}}}function ot(e){let t;if(e!==void 0){if(ne(e))t=e;else if(v(e)){let n=Number(e);isNaN(n)||(t=n)}}return t===void 0?t:Math.trunc(t)}function st(e){try{return te(e),e}catch{return}}function ct(e){try{return b(e),e}catch{return{}}}function lt(e){try{return oe(e),e}catch(e){w(`Error on validator but not throwing since not mandatory`,e.message);return}}function ut(){let e=e=>{if(!x(e,`ortb2Imp`))return;let t=e.ortb2Imp;if(!x(t,`ext`))return;let n=t.ext;if(!x(n,`data`)&&!x(n,`gpid`))return;let r=n.data,i,a;if(x(r,`pbadslot`)&&v(r.pbadslot)&&(i=r.pbadslot),x(n,`gpid`)&&v(n.gpid)&&(a=n.gpid),!(!i&&!a))return{ext:{data:{pbadslot:i},gpid:a}}},t=e=>{b(e,`Auction event's adUnits bidders should all be objects`),y(e.bidder,`Auction event's adUnits bidders should all have a key "bidder" as a string`);let t=e.params??{};return b(t,`Auction event's adUnits bidders should all have a key "params" as an object`),{bidder:e.bidder,params:t}},n=n=>{b(n,`Auction event's adUnits should all be objects`),y(n.code,`Auction event's adUnits should all have a key "code" as a string`),_(n.bids,`Auction event's adUnits should all have a key "bids" as an array`);let r=n.bids.map(e=>{try{return t(e)}catch(e){T(`[pbjsIntegration] Discarding bidder from ${n.code}`,e);return}}).filter(e=>e!==void 0),i={};if(n.mediaTypes){if(b(n.mediaTypes,`Auction event's adUnits should all have a key "mediaTypes" as an object`),n.mediaTypes.banner){b(n.mediaTypes.banner,`Auction event's adUnits mediaTypes can all have a key "banner" that should be an object`);let e=n.mediaTypes.banner.sizes??[];_(e,`Auction event's adUnits mediaTypes banner should all have a key "sizes" that should be an array`),i.banner={sizes:e.filter(e=>Array.isArray(e)&&e.length===2).map(e=>{try{return _(e),[parseInt(e[0]),parseInt(e[1])]}catch{return[0,0]}}),sizeConfig:n.mediaTypes.banner.sizeConfig}}n.mediaTypes.native&&(i.native={sizes:`native`}),n.mediaTypes.video&&(b(n.mediaTypes.video,`Auction event's adUnits mediaTypes can all have a key "video" that should be an object`),n.mediaTypes.video.playerSize&&(_(n.mediaTypes.video.playerSize,`Auction event's adUnits mediaTypes video should all have a key "playerSize" that should be an array`),i.video={playerSize:(n.mediaTypes.video.playerSize??[]).filter(e=>Array.isArray(e)&&e.length===2)}))}let a={bids:r,code:n.code,mediaTypes:i},o=n.pubstack;o!==void 0&&(b(o),a.pubstack=o);let s=e(n);return s&&(a.ortb2Imp=s),a},r=e=>{b(e,`Auction event's bidderRequests should all be objects`),y(e.bidderRequestId,`Auction event's bidderRequests should all have a key "bidderRequestId" as a string`),y(e.bidderCode,`Auction event's bidderRequests should all have a key "bidderCode" as a string`),_(e.bids,`Auction event's bidderRequests should all have a key "bids" as an array`);let t=e.bids.map(t=>{try{return i(t,`Auction event's bidderRequests`)}catch(t){T(`[pbjsIntegration] Discarding bid request from ${e.bidderRequestId}`,t);return}}).filter(e=>e!==void 0),n={bidderRequestId:e.bidderRequestId,bids:t,bidderCode:e.bidderCode};return e.metrics&&(n.metrics=e.metrics),e.gdprConsent&&(n.gdprConsent=e.gdprConsent),n},i=(e,t)=>{b(e,t+`'s bids should all be objects`),y(e.adUnitCode,t+` bids should all have a key "adUnitCode" as a string`),y(e.bidId,t+` bids should all have a key "bidId" as a string`),y(e.bidder,t+` bids should all have a key "bidder" as a string`);let n=e.params??{};b(n,t+` bids can all have a key "params" that should be an object`);let r=e.userId??{};b(r,t+` bids can all have a key "userId" that should be an object`);let i=e.userIdAsEids??[];_(i,t+` bids can all have a key "userIdAsEids" that should be an array`);let a=i.map(e=>(b(e,t+` bids can all have a key "userIdAsEids" that should be an array of objects`),y(e.source,t+` bids can all have a key "userIdAsEids" that should be an array of objects with a "source" key as a string`),{source:e.source})),o=e.crumbs??{};return b(o,t+` bids can all have a key "crumbs" that should be an object`),oe(e.src),{adUnitCode:e.adUnitCode,bidId:e.bidId,bidder:e.bidder,params:n,userId:r,userIdAsEids:a,crumbs:o,src:e.src}};return{toBidRejected(e){return b(e,`BidRejected event should be an object`),y(e.requestId,`BidRequested event should have a "requestId" key as a string`),y(e.rejectionReason,`BidRejected event should have a "rejectionReason" key as a string`),{requestId:e.requestId,rejectionReason:e.rejectionReason}},toSeatNonBid:function(e){return b(e,`SeatNonBid event should be an object`),y(e.seat,`SeatNonBid event should have a "seat" key as a string`),_(e.nonbid,`SeatNonBid event should have a "seat" key as a string`),e.nonbid.map(t=>{try{return b(t,`Nonbid should be an object`),y(t.impid,`Nonbid should have a "impid" key as a string`),ie(t.statuscode,`Nonbid should have a "statuscode" key as a number`),{impid:t.impid,statuscode:t.statuscode}}catch(t){T(`[pbjsIntegration] Discarding Nonbid from auction event ${e.auctionId}`,t);return}}).filter(e=>e!==void 0),{seat:e.seat,nonbid:e.nonbid}},toAuctionEnd:function(e){let t,i,a=[];b(e,`Auction event should be an object`),y(e.auctionId,`Auction event should have a "auctionId" key as a string`),_(e.adUnits,`Auction event should have a "adUnits" key as a non-empty array`),de(e.adUnits,`Auction event should have a "adUnits" key as a non-empty array`),e.labels!==void 0&&(_(e.labels,`Auction event can have a "labels" key that should be an array`),i=e.labels),_(e.bidderRequests,`Auction event should have a "bidderRequests" key as a non-empty array`),de(e.bidderRequests,`Auction event should have a "bidderRequests" key as a non-empty array`);let o=ot(e.timeout);e.timeout&&!o&&T(`[pbjsIntegration] unable to read timeout from auction event ${e.auctionId}`);let s=e.adUnits.map(t=>{try{return n(t)}catch(t){T(`[pbjsIntegration] Discarding adUnit from auction event ${e.auctionId}`,t);return}}).filter(e=>e!==void 0),c=e.bidderRequests.map(t=>{try{return r(t)}catch(t){T(`[pbjsIntegration] Discarding bidderRequest from auction event ${e.auctionId}`,t);return}}).filter(e=>e!==void 0);_(e.bidsReceived,`Auction event should have a "bidsReceived" key as a non-empty array`);let l=e.bidsReceived.map(t=>{try{return this.toBidResponse(t)}catch(t){T(`[pbjsIntegration] Discarding bidReceived from auction event ${e.auctionId}`,t);return}}).filter(e=>e!==void 0);_(e.adUnitCodes,`Auction event should have a "adUnitCodes" key as a non-empty array`),de(e.adUnitCodes,`Auction event should have a "adUnitCodes" key as a non-empty array`);try{_(e.bidsRejected,`Auction event should have a "bidsRejected" key as an array`),a=e.bidsRejected.map(t=>{try{return this.toBidRejected(t)}catch(t){T(`[pbjsIntegration] Discarding bidRejected from auction event ${e.auctionId}`,t);return}}).filter(e=>e!==void 0)}catch(e){w(`Error on validator but not throwing since not mandatory`,e.message)}_(e.noBids,`Auction event should have a "noBids" key as an array`);let u=e.noBids.map(t=>{try{return this.toNoBid(t)}catch(t){T(`[pbjsIntegration] Discarding noBid from auction event ${e.auctionId}`,t);return}}).filter(e=>e!==void 0);try{_(e.seatNonBids,`Auction event should have a "noBids" key as an array`),t=e.seatNonBids.map(t=>{try{return this.toSeatNonBid(t)}catch(t){T(`[pbjsIntegration] Discarding SeatNonBids from auction event ${e.auctionId}`,t);return}}).filter(e=>e!==void 0)}catch(e){w(`Error on validator but not throwing since not mandatory`,e.message)}return ue(e.auctionStatus,[`completed`,`inProgress`,`started`]),ie(e.auctionEnd),ie(e.timestamp),{auctionId:e.auctionId,bidderRequests:c,adUnits:s,labels:i,timeout:o,auctionEnd:e.auctionEnd,auctionStatus:e.auctionStatus,noBids:u,adUnitCodes:e.adUnitCodes,bidsRejected:a,bidsReceived:l,timestamp:e.timestamp,winningBids:[],seatNonBids:t}},toAuction:function(e){let t;b(e,`Auction event should be an object`),y(e.auctionId,`Auction event should have a "auctionId" key as a string`),_(e.adUnits,`Auction event should have a "adUnits" key as a non-empty array`),de(e.adUnits,`Auction event should have a "adUnits" key as a non-empty array`),e.labels!==void 0&&(_(e.labels,`Auction event can have a "labels" key that should be an array`),t=e.labels),_(e.bidderRequests,`Auction event should have a "bidderRequests" key as a non-empty array`),de(e.bidderRequests,`Auction event should have a "bidderRequests" key as a non-empty array`);let i=ot(e.timeout);e.timeout&&!i&&T(`[pbjsIntegration] unable to read timeout from auction event ${e.auctionId}`);let a=e.adUnits.map(t=>{try{return n(t)}catch(t){T(`[pbjsIntegration] Discarding adUnit from auction event ${e.auctionId}`,t);return}}).filter(e=>e!==void 0),o=e.bidderRequests.map(t=>{try{return r(t)}catch(t){T(`[pbjsIntegration] Discarding bidderRequest from auction event ${e.auctionId}`,t);return}}).filter(e=>e!==void 0);return{auctionId:e.auctionId,bidderRequests:o,adUnits:a,labels:t,timeout:i}},toBidRequested(e){b(e,`BidRequested event should be an object`),y(e.auctionId,`BidRequested event should have a "auctionId" key as a string`),_(e.bids,`BidRequested event should have a "bids" key as an array`);let t=e.bids.map(t=>{try{return i(t,`BidRequested event`)}catch(t){T(`[pbjsIntegration] Discarding bid request from bid requested event ${e.auctionId}`,t);return}}).filter(e=>e!==void 0),n={auctionId:e.auctionId,bids:t};return e.gdprConsent&&(n.gdprConsent=e.gdprConsent),n},toBidResponse(e){b(e,`BidResponse event should be an object`),y(e.auctionId,`BidRequested event should have a "auctionId" key as a string`),y(e.adUnitCode,`BidRequested event should have a "adUnitCode" key as a string`),y(e.adId,`BidRequested event should have a "adId" key as a string`),y(e.requestId,`BidRequested event should have a "requestId" key as a string`);let t=v(e.cpm)?Number.parseFloat(e.cpm):e.cpm,n,r=lt(e.dealId);ie(t,`BidRequested event should have a "cpm" key as a number`);let i=e.size;typeof i!=`string`&&(i=e.width&&e.height?`${e.width}x${e.height}`:`unknown`),y(e.mediaType,`BidRequested event should have a "mediaType" key as a string`),y(i,`BidRequested event should have a "size" key as a string`);let a;v(e.currency)&&(a=e.currency),y(e.bidderCode,`BidResponse event should have a "bidderCode" key as a string`),ae(e.timeToRespond),se(e.netRevenue);let o=ct(e.meta),s=ct(e.mediasquare),c=st(o.advertiserDomains),l=v(o.demandSource)?o.demandSource:v(s.bidder)?s.bidder:v(o.s2s_biddercode)?o.s2s_biddercode:void 0;try{y(e.adapterCode,`BidWon event should have a "bidderCode" key as a string`),n=e.adapterCode}catch(e){w(`Error on validator but not throwing since not mandatory`,e.message)}return{adId:e.adId,adUnitCode:e.adUnitCode,auctionId:e.auctionId,cpm:t,currency:a,requestId:e.requestId,size:i,bidderCode:e.bidderCode,mediaType:e.mediaType??`banner`,timeToRespond:e.timeToRespond,adapterCode:n,netRevenue:e.netRevenue,dealId:r,advertiserDomains:c,demandSource:l}},toBidTimeout(e){_(e,`BidTimeout event should be an array`);let t=[];return e.forEach(e=>{try{b(e,`BidTimeout events should all be objects`),y(e.adUnitCode,`BidTimeout events should all have a key "adUnitCode" as a string`),y(e.auctionId,`BidTimeout events should all have a key "auctionId" as a string`),y(e.bidId,`BidTimeout events should all have a key "bidId" as a string`),t.push({adUnitCode:e.adUnitCode,auctionId:e.auctionId,bidId:e.bidId})}catch(t){w(`Discarding bid timeout event because `,t.message,e)}}),t},toNoBid(e){return b(e,`NoBid event should be an object`),y(e.auctionId,`NoBid event should have a "auctionId" key as a string`),y(e.bidId,`NoBid event should have a "bidId" key as a string`),y(e.adUnitCode,`NoBid event should have a "adUnitCode" key as a string`),{bidId:e.bidId,adUnitCode:e.adUnitCode,auctionId:e.auctionId}},toBidWon(e){b(e,`BidWon event should be an object`),y(e.adId,`BidWon event should have a "adId" key as a string`),y(e.requestId,`BidWon event should have a "requestId" key as a string`);let t,n,r,i,a,o,s=lt(e.dealId);v(e.currency)&&(o=e.currency);let c=v(e.cpm)?Number.parseFloat(e.cpm):e.cpm;ie(c,`BidRequested event should have a "cpm" key as a number`),y(e.mediaType,`BidRequested event should have a "mediaType" key as a string`),y(e.size,`BidWon event should have a "size" key as a string`),a=e.size,y(e.auctionId,`BidWon event should have a "auctionId" key as a string`),t=e.auctionId,y(e.adUnitCode,`BidWon event should have a "adUnitCode" key as a string`),n=e.adUnitCode;try{y(e.bidderCode,`BidWon event should have a "bidderCode" key as a string`),r=e.bidderCode}catch(t){w(`Error on validator but not throwing since not mandatory for monitoring (only for refresh)`,t.message),v(e.bidder)&&(r=e.bidder)}try{y(e.adapterCode,`BidWon event should have a "bidderCode" key as a string`),i=e.adapterCode}catch(e){w(`Error on validator but not throwing since not mandatory`,e.message)}se(e.netRevenue),oe(e.source);let l=ct(e.meta),u=ct(e.mediasquare),d=st(l.advertiserDomains),f=v(l.demandSource)?l.demandSource:v(u.bidder)?u.bidder:v(l.s2s_biddercode)?l.s2s_biddercode:void 0;return{adId:e.adId,adUnitCode:n,auctionId:t,bidderCode:r,adapterCode:i,size:a,requestId:e.requestId,currency:o,cpm:c,mediaType:e.mediaType??`banner`,dealId:s,netRevenue:e.netRevenue,source:e.source,advertiserDomains:d,demandSource:f}},toBidWonFromSdk(e){return b(e,`BidWon event should be an object`),y(e.adId,`BidWon event should have a "adId" key as a string`),{adId:e.adId}}}}let dt=(e,t)=>{let n=ut(),r=new Xe(void 0),i=at(n,r,`sdk`);t.bindIntegration(r),e.subscribe(([e,[t]])=>{try{i.on(e,t)}catch(e){e.context=e.context||{},e.context.pbjs={source:`sdk:pbjs`},S(e)}})};function ft(e,t,n){let r=new l,i=[];$e(e,n.tagId,n.globalQueue);let a=e[n.globalQueue],o=t=>{ce(Object.values(e.pbstck.sdk).find(t=>t!==e.pbstck.sdk[n.tagId]&&t.q===a),`Concurrency on '${n.globalQueue}' globalQueue (more than 1 destination configured)`),r.next([t[0],et(Object.values(t[1]))])};return r.subscribe((...e)=>i.push(e)),dt(r.pipe(...f(/cmd/)).pipe(...f(/pbjs|prebid/)),t),{debug:()=>({events:i}),dispatchEvents:()=>{e.pbstck.sdk[n.tagId].q.forEach(o),e.pbstck.sdk[n.tagId].p.push(o)}}}let pt=async()=>{try{return navigator&&navigator.cookieDeprecationLabel&&navigator.cookieDeprecationLabel.getValue&&await navigator.cookieDeprecationLabel.getValue()||void 0}catch(e){w(`Error while getting cookie depreciation label`,e)}},mt=(e,t)=>{if(!e||!t)throw Error(`IllegalArgumentException`);return`${e}_${t}`};var ht=`2.0.10`,gt=500,_t=`user-agent`,vt=``,yt=`?`,E={FUNCTION:`function`,OBJECT:`object`,STRING:`string`,UNDEFINED:`undefined`},D=`browser`,O=`cpu`,k=`device`,A=`engine`,j=`os`,bt=`result`,M=`name`,N=`type`,P=`vendor`,F=`version`,I=`architecture`,xt=`major`,L=`model`,St=`console`,R=`mobile`,z=`tablet`,B=`smarttv`,V=`wearable`,Ct=`xr`,wt=`embedded`,Tt=`fetcher`,H=`inapp`,Et=`brands`,U=`formFactors`,Dt=`fullVersionList`,Ot=`platform`,kt=`platformVersion`,At=`bitness`,W=`sec-ch-ua`,jt=W+`-full-version-list`,Mt=W+`-arch`,Nt=W+`-`+At,Pt=W+`-form-factors`,Ft=W+`-`+R,It=W+`-`+L,Lt=W+`-`+Ot,Rt=Lt+`-version`,zt=[Et,Dt,R,L,Ot,kt,I,U,At],Bt=`Amazon`,Vt=`Apple`,Ht=`ASUS`,Ut=`BlackBerry`,Wt=`Google`,Gt=`Huawei`,Kt=`Lenovo`,qt=`Honor`,Jt=`LG`,Yt=`Microsoft`,Xt=`Motorola`,Zt=`Nvidia`,Qt=`OnePlus`,$t=`OPPO`,en=`Samsung`,tn=`Sharp`,nn=`Sony`,rn=`Xiaomi`,an=`Zebra`,on=`Chrome`,sn=`Chromium`,G=`Chromecast`,cn=`Edge`,ln=`Firefox`,un=`Opera`,dn=`Facebook`,fn=`Sogou`,pn=`Mobile `,mn=` Browser`,hn=`Windows`,K=typeof window!==E.UNDEFINED&&window.navigator?window.navigator:void 0,gn=K&&K.userAgentData?K.userAgentData:void 0,_n=function(e,t){var n={},r=t;if(!bn(t))for(var i in r={},t)for(var a in t[i])r[a]=t[i][a].concat(r[a]?r[a]:[]);for(var o in e)n[o]=r[o]&&r[o].length%2==0?r[o].concat(e[o]):e[o];return n},vn=function(e){for(var t={},n=0;n0){for(var n in e)if(q(t)==q(e[n]))return!0;return!1}return xn(e)?q(t)==q(e):!1},bn=function(e,t){for(var n in e)return/^(browser|cpu|device|engine|os)$/.test(n)||(t?bn(e[n]):!1)},xn=function(e){return typeof e===E.STRING},Sn=function(e){if(e){for(var t=[],n=wn(e).split(`,`),r=0;r-1){var i=En(n[r]).split(`;v=`);t[r]={brand:i[0],version:i[1]}}else t[r]=En(n[r]);return t}},q=function(e){return xn(e)?e.toLowerCase():e},Cn=function(e){return xn(e)?Tn(/[^\d\.]/g,e).split(`.`)[0]:void 0},wn=function(e){return xn(e)?En(Tn(/\\?\"/g,e),gt):void 0},J=function(e){for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];typeof n==E.OBJECT&&n.length==2?this[n[0]]=n[1]:this[n]=void 0}return this},Tn=function(e,t){return xn(t)?t.replace(e,vt):t},En=function(e,t){return e=Tn(/^\s\s*/,String(e)),typeof t===E.UNDEFINED?e:e.substring(0,t)},Dn=function(e,t){if(!(!e||!t))for(var n=0,r,i,a,o,s,c;n0?o.length===2?typeof o[1]==E.FUNCTION?this[o[0]]=o[1].call(this,c):this[o[0]]=o[1]:o.length>=3&&(typeof o[1]===E.FUNCTION&&!(o[1].exec&&o[1].test)?o.length>3?this[o[0]]=c?o[1].apply(this,o.slice(2)):void 0:this[o[0]]=c?o[1].call(this,c,o[2]):void 0:o.length==3?this[o[0]]=c?c.replace(o[1],o[2]):void 0:o.length==4?this[o[0]]=c?o[3].call(this,c.replace(o[1],o[2])):void 0:o.length>4&&(this[o[0]]=c?o[3].apply(this,[c.replace(o[1],o[2])].concat(o.slice(4))):void 0)):this[o]=c||void 0;n+=2}},On=function(e,t){return t.test.test(e)?t.ifTrue:t.ifFalse},Y=function(e,t){for(var n in t)if(typeof t[n]===E.OBJECT&&t[n].length>0){for(var r=0;r2&&this.set(L,`iPad`).set(N,z);break;case j:!this.get(M)&&gn&&gn[Ot]&&this.set(M,gn[Ot]);break;case bt:var e=this.data,t=function(t){return e[t].getItem().detectFeature().get()};this.set(D,t(D)).set(O,t(O)).set(k,t(k)).set(A,t(A)).set(j,t(j))}return this},X.prototype.parseUA=function(){switch(this.itemType!=bt&&Dn.call(this.data,this.ua,this.rgxMap),this.itemType){case D:this.set(xt,Cn(this.get(F)));break;case j:if(this.get(M)==`iOS`&&this.get(F)&&/^1[89][^\d]/.exec(this.get(F))){var e=/\) Version\/((\d+)[\d\.]*)/.exec(this.ua);e&&parseInt(e[2],10)>=26&&this.set(F,e[1])}break}return this},X.prototype.parseCH=function(){var e=this.uaCH,t=this.rgxMap;switch(this.itemType){case D:case A:var n=e[Dt]||e[Et],r;if(n)for(var i=0;i=13?`11`:`10`),this.set(M,d).set(F,f)}this.get(M)==hn&&e[L]==`Xbox`&&this.set(M,`Xbox`).set(F,void 0);break;case bt:var p=this.data,m=function(t){return p[t].getItem().setCH(e).parseCH().get()};this.set(D,m(D)).set(O,m(O)).set(k,m(k)).set(A,m(A)).set(j,m(j))}return this};function Z(e,t,n){if(typeof e===E.OBJECT?(bn(e,!0)?(typeof t===E.OBJECT&&(n=t),t=e):(n=e,t=void 0),e=void 0):typeof e===E.STRING&&!bn(t,!0)&&(n=t,t=void 0),n)if(typeof n.append===E.FUNCTION){var r={};n.forEach(function(e,t){r[String(t).toLowerCase()]=e}),n=r}else{var i={};for(var a in n)n.hasOwnProperty(a)&&(i[String(a).toLowerCase()]=n[a]);n=i}if(!(this instanceof Z))return new Z(e,t,n).getResult();var o=typeof e===E.STRING?e:n&&n[_t]?n[_t]:K&&K.userAgent?K.userAgent:vt,s=new Fn(n,!0),c=Mn,l=function(e){return e==bt?function(){return new X(e,o,c,s).set(`ua`,o).set(D,this.getBrowser()).set(O,this.getCPU()).set(k,this.getDevice()).set(A,this.getEngine()).set(j,this.getOS()).get()}:function(){return new X(e,o,c[e],s).parseUA().get()}};return J.call(this,[[`getBrowser`,l(D)],[`getCPU`,l(O)],[`getDevice`,l(k)],[`getEngine`,l(A)],[`getOS`,l(j)],[`getResult`,l(bt)],[`getUA`,function(){return o}],[`setUA`,function(e){return xn(e)&&(o=En(e,gt)),this}],[`useExtension`,function(e){return e&&(c=_n(c,e)),this}]]).setUA(o).useExtension(t),this}Z.VERSION=ht,Z.BROWSER=vn([M,F,xt,N]),Z.CPU=vn([I]),Z.DEVICE=vn([L,P,N,St,R,B,z,V,wt]),Z.ENGINE=Z.OS=vn([M,F]);var In=class{constructor(){this.onAdStream=new l}onAd(e){let t=`/${e.formatId}`,n=e.formatId,r={bidderCode:`smart-rtb+`,cpm:e.cpm,size:e.size,adUnitName:n,adUnitPathSuffix:t,formatId:e.formatId,customFields:{}};this.onAdStream.next(r)}};function Ln(e){if(e.includes(`pubstackRefresh`)){let t=e.find(e=>e.startsWith(`pubstackRefreshRank`));if(t!==void 0&&t.includes(`:`)){let e=parseInt(t.split(`:`)[1])||0;return e>0?e:0}}return 0}function Rn(e){if(!(typeof e==`object`&&e&&`getSlotIdMap`in e&&typeof e.getSlotIdMap==`function`))throw Error(`Missing property getSlotIdMap on googletag`)}function zn(e,t){let n=Hn(e),r=e.split(`?`)[0].startsWith(`/`)?e.split(`?`)[0]:`/${e.split(`?`)[0]}`,i=Gn(t);return r===(i.startsWith(`/`)?i:`/${i}`)&&(n===void 0||t.getTargeting(n.key)[0]===n.value)}let Bn=(e,t)=>{let n=e.path;if(t===void 0||n===void 0)return;let r=t.pubads().getSlots();if(r===void 0)return;let i=r.filter(e=>zn(n,e));switch(i.length){case 0:return;case 1:return i[0];default:if(n.indexOf(`?`)!==-1)return w(`[pubstackGoogleTag] retrieve first slot matching the dimension`,n),i[0];{let r=t.pubads();try{Rn(r);let t=r.getSlotIdMap();return w(`[pubstackGoogleTag] get all slot map`,t),t[Object.keys(t).filter(e=>e.startsWith(n))[Vn(e)]]}catch(e){w(`[pubstackGoogleTag] ${e}`);return}}}};function Vn(e){return Array.from(document.querySelectorAll(`div[id*='${e.name}']`)).map(e=>e.id).findIndex(t=>t===e.code)}function Hn(e){let t=e.split(`?`)[1];if(t!==void 0){let e=t.split(`=`);return{key:e[0],value:e[1]}}}let Un=e=>Wn(e.googletag),Wn=e=>{let t=e;if(t!==void 0&&t.apiReady&&t.cmd!==void 0&&t.pubads!==void 0&&typeof t.pubads==`function`&&typeof t.pubads().refresh==`function`)return t};function Gn(e){return e.getAdUnitPath().replace(`//`,`/`)}let Kn=e=>{let t=Un(window);w(`[pubstackFindElementById] adUnit `,e);let n=Bn(e,t);return w(`[pubstackFindElementById] slot `,n),n?document.getElementById(n.getSlotElementId()):qn(e.code)},qn=e=>{let t=document.getElementById(e);return t===null?document.querySelector(`iframe[id*='${e}']`):t};function Jn(e){let t=document.getElementsByTagName(`meta`);return Array.from(t).filter(t=>t.name.includes(`${e}:`))}function Yn(e,t){return e.replace(`${t}:`,``)}let Xn=(e,t)=>{let n=new Set;return e.tags.forEach(e=>n.add(e)),t.tags.forEach(e=>n.add(e)),n},Zn=(e,t)=>e.filter(e=>e.bidderCode!==t);var Qn=class{constructor(e){this.coreAuctionStream=new l,this.coreImpressionStream=new l,this.state=e}subscribe(e){this.coreAuctionStream.subscribe(e.onAuction),this.coreImpressionStream.subscribe(e.onImpression)}pushNewImpression(e){let t=this.state.getAuction(e.auctionId),n=this.state.findLastAuctionId(t.adUnit)??``,r=this.state.findBidsByAuctionId(t.auctionId).filter(e=>e.state===`bidResponse`).map(e=>e).sort((e,t)=>t.cpm-e.cpm),i=(r[0]?.cpm??0)-(r[1]?.cpm??0);return this.state.storeCoreBidResponses.set(e.bidId,e),this.impressionFormatAndForward(t,e,i,n)}pushNewAuction(e){e.bidRequests=Zn(e.bidRequests,`adThink`),e.bidRequests.length!==0&&this.coreAuctionStream.next(e)}checkMeasurability(e){return`IntersectionObserver`in window&&`IntersectionObserverEntry`in window&&`intersectionRatio`in window.IntersectionObserverEntry.prototype&&`isIntersecting`in window.IntersectionObserverEntry.prototype&&!!Kn(e)}impressionSasFormatAndForward(e,t){let n={bidId:`smart-`+s(),auctionId:`smart-`+s(),lastAuctionId:`smart-`+s(),adUnit:t,bidderCode:e.bidderCode,cpm:e.cpm,currency:e.currency,refresh:!1,size:e.size,userConsentState:`notAvailable`,userConsentVersion:`notAvailable`,hasUserId:`notAvailable`,userIdProviderList:[],pbjsVersion:`smart-ad-server`,tags:new Set,viewabilityMeasurable:!1,cpmUplift:0,pubstackRefresh:!1,pubstackRefreshRank:0,customFields:e.customFields};this.coreImpressionStream.next(n)}impressionFormatAndForward(e,t,n,r){let i=this.state.findBidsByAuctionId(e.auctionId),a=this.state.getAuction(r),o=We(i),s=this.checkMeasurability(e.adUnit),{userConsentState:c,userConsentVersion:l}=Ge(o),u={bidId:t.bidResponseId,auctionId:e.auctionId,lastAuctionId:r,adUnit:e.adUnit,bidderCode:t.bidderCode,cpm:t.cpm,currency:t.currency,refresh:!1,size:t.size,userConsentState:c,userConsentVersion:l,hasUserId:e.hasUserId,userIdProviderList:e.userIdProviderList,pbjsVersion:e.pbjsVersion,tags:Xn(e,t),viewabilityMeasurable:s,cpmUplift:n,adUnitType:e.adUnit.type,bidderType:t.bidderType,siteEnv:`web`,dealId:t.dealId,advertiserDomains:t.advertiserDomains,pubstackRefresh:a.pubstackRefresh,pubstackRefreshRank:a.pubstackRefreshRank,customFields:t.customFields,bidNetRevenue:t.bidNetRevenue,source:t.source,adapterCode:t.adapterCode,pubstackServerAdunitName:t.pubstackServerAdunitName};this.coreImpressionStream.next(u)}},$n=class{constructor(){this.storeAuctions=new Map,this.storeCoreBidResponses=new Map,this.mappingAdUnitNameAuctions=new Map,this.mappingAdUnitCodeLastAuctions=new Map}setAuction(e){this.storeAuctions.set(e.auctionId,e);let t=this.mappingAdUnitNameAuctions.get(e.adUnit.name)??[];t.find(t=>t===e.auctionId)||(t.push(e.auctionId),this.mappingAdUnitNameAuctions.set(e.adUnit.name,t)),this.mappingAdUnitCodeLastAuctions.set(e.adUnit.code,e.auctionId)}getAuction(e){let t=this.storeAuctions.get(e);return le(t,`auction not found, @auctionId=${e}`),t}findBidsByAuctionId(e){return this.storeAuctions.get(e)?.bidRequests||[]}findLastAuctionId(e){return this.mappingAdUnitCodeLastAuctions.get(e.code)}findAuctionByAdUnitPath(e){return Array.from(this.storeAuctions.values()).find(t=>t.adUnit.path?.endsWith(e))}},er=class{constructor(){this.state=new $n,this.forwarder=new Qn(this.state),this.fallbackCurrency=void 0}bindIntegration(e){e instanceof Xe&&(e.onBidResponseStream.subscribe(e=>this.bidResponse(e),S),e.onAuctionEndStream.subscribe(e=>this.auctionDone(e),S),e.onBidWonStream.subscribe(e=>this.impression(e),S),e.onBidWonFromSdkStream.subscribe(e=>this.impressionFromSdk(e),S),this.fallbackCurrency=e.getAdServerCurrency()),e instanceof In&&e.onAdStream.subscribe(e=>this.impressionSas(e),S)}helperToBidResponse(e,t){let n={...e};n.state=`bidResponse`,t.tags.forEach(e=>n.tags.add(e));let r=t.size;return t.mediaType===`native`&&(r=`native`),t.mediaType===`video`&&(r=`video-${r}`),n.size=r,n.cpm=t.cpm,n.currency=t.currency??this.fallbackCurrency,n.bidResponseId=t.bidResponseId,n.bidderCode=t.bidderCode,n.bidderType=t.bidderType,n}bidResponse(e){w(`[pubstackCoreController] onBidResponse`,e),e.bidderCode=e.adapterCode===`nexx360`?`nexx360`:e.bidderCode;let t={auctionId:e.auctionId,state:`bidResponse`,tags:new Set(e.tags),customFields:e.customFields};try{let n=this.state.getAuction(e.auctionId);if(n){let r=n.bidRequests.find(t=>t.bidId===e.bidId);r&&(n.bidRequests=n.bidRequests.filter(t=>t.bidId!==e.bidId),n.bidRequests.push({...r,...this.helperToBidResponse(t,e),tags:r.tags}))}}catch{}}helperAuctionBidToBidResponse(e){let t={...e,tags:new Set};if(e.state===`bidResponse`){let n=e.size;e.mediaType===`native`&&(n=`native`),e.mediaType===`video`&&(n=`video-${n}`),t.size=n,t.cpm=e.cpm,t.currency=e.currency??this.fallbackCurrency,t.bidResponseId=e.bidResponseId,t.timeToRespond=e.timeToRespond,t.dealId=e.dealId,t.advertiserDomains=e.advertiserDomains,t.bidNetRevenue=e.bidNetRevenue,t.admMapping=e.admMapping}return e.tags.forEach(e=>t.tags.add(e)),t}bidWonToCoreBidResponse(e){let t=o(e.requestId),n=e.size;return e.mediaType===`native`&&(n=`native`),e.mediaType===`video`&&(n=`video-${n}`),{adId:e.adId,bidId:t,bidResponseId:o(t,e.adId),bidderCode:e.adapterCode===`nexx360`?`nexx360`:e.bidderCode??``,adapterCode:e.pbstckAdapterCode,cpm:e.cpm,size:n,state:`bidResponse`,auctionId:e.auctionId,tags:new Set(e.tags),currency:e.currency??this.fallbackCurrency,customFields:e.customFields,dealId:e.dealId,advertiserDomains:e.advertiserDomains,bidNetRevenue:e.bidNetRevenue,source:e.source,pubstackServerAdunitName:e.pubstackServerAdunitName,bidderType:e.bidderType}}auctionDone(e){w(`[pubstackCoreController] onAuctionDone`,e.auctionId);try{let t=(e.bidRequests||[]).map(this.helperAuctionBidToBidResponse),{userConsentState:n,userConsentVersion:r}=Ge(We(t)),i={auctionId:e.auctionId,adUnit:e.adUnit,tags:new Set(e.tags),sizes:new Set(e.sizes),hasUserId:e.userId.hasUserId,userIdProviderList:e.userId.userIdProviderList,refreshIndex:e.refreshIndex,pbjsVersion:e.pbjsVersion,refresh:!1,pubstackRefresh:e.labels.includes(`pubstackRefresh`),pubstackRefreshRank:Ln(e.labels),userConsentState:n,userConsentVersion:r,bidRequests:t,customFields:e.customFields,duration:e.duration,timeout:e.timeout,state:`RUNNING`,admConfig:e.admConfig};this.state.setAuction(i);let a=()=>{let t=this.state.getAuction(e.auctionId);if(t.state===`FINISHED`){w(`[pubstackCoreController] auction is already finished`,t);return}this.forwarder.pushNewAuction(t),t.state=`FINISHED`,this.state.setAuction(t)};e.gracePeriod===void 0?a():setTimeout(()=>a(),e.gracePeriod)}catch{w(`[pubstackCoreController] error: cannot set auction as done because auction is not running`)}}findBidResponseDuplicate(e){let t=this.state.storeCoreBidResponses.get(e.bidId),n=!!t&&t.bidResponseId===e.bidResponseId&&t.bidderCode===e.bidderCode;return n&&w(`[pubstackCoreController] duplicate bid response found`,e),n}_impression(e){if(this.state.getAuction(e.auctionId).state===`FINISHED`)this.findBidResponseDuplicate(e)||this.forwarder.pushNewImpression(e);else{let t=n=>{n.auctionId===e.auctionId&&(this.findBidResponseDuplicate(e)||this.forwarder.pushNewImpression(e),this.forwarder.coreAuctionStream.unsubscribe(t))};this.forwarder.coreAuctionStream.subscribe(t)}}impression(e){w(`[pubstackCoreController] onImpression`,e);try{let t=this.bidWonToCoreBidResponse(e);this._impression(t)}catch(e){w(`[pubstackCoreController] error: cannot create impression`,e)}}impressionFromSdk(e){w(`[pubstackCoreController] onImpression`,e);try{let t=Array.from(this.state.storeAuctions.values()).find(t=>t.bidRequests.filter(e=>e.state===`bidResponse`).find(t=>t.adId===e.adId));if(t){let n=t.bidRequests.filter(e=>e.state===`bidResponse`).find(t=>t.adId===e.adId);n.customFields={...n.customFields,...e.customFields},this._impression(n)}}catch(e){w(`[pubstackCoreController] error: cannot create impression`,e)}}impressionSas(e){w(`[pubstackCoreController] onImpressionSas`,e);try{let t=this.state.findAuctionByAdUnitPath(e.adUnitPathSuffix);le(t,`onSasNewBidResponse: cannot retrieve related auction, @adUnitName=${e.adUnitName}, @adUnitPath=${e.adUnitPathSuffix}`),e.currency=this.fallbackCurrency,this.forwarder.impressionSasFormatAndForward(e,t.adUnit)}catch(e){w(`[pubstackCoreController] error: cannot create impression`,e)}}subscribe(e){this.forwarder.subscribe(e)}debug(){let e=[];return this.forwarder.subscribe({onAuction:t=>e.push(t),onImpression:t=>e.push(t)}),{auctions:this.state,auctionsDone:void 0,adUnits:void 0,events:e}}};let tr=(e,t)=>Object.entries(t).every(([t,n])=>typeof n==`object`&&typeof e[t]==`object`?tr(e[t],n):typeof e[t]==typeof n),nr=(e,t)=>{if(t)for(let n=0;n<1e3;n+=1)try{let r=e([],{},[n]);try{if(tr(r,t))return r}catch{}}catch{}};function rr(e,t){return e[t.globalName]||(e[t.globalName]={}),e[t.globalName].que||(e[t.globalName].que=[]),e[t.globalName].que}function ir(e,t,n,r){let i=e[r.globalName];n.bindIntegration(t);let a=at(ut(),t),o;if(me(i.getEvents))w(`[pbjsIntegration] retrieve pbjs events using getEvents on public API`),o=i.getEvents;else{w(`[pbjsIntegration] retrieve pbjs events using chunk`);let t=e[`${r.globalName}Chunk`];if(t===void 0)throw Error(`[pbjsIntegration] unable to find pbjs chunk`);let n=nr(t,{on:Function,getEvents:Function});if(n===void 0)throw Error(`[pbjsIntegration] unable to use event handler on adapter`);o=n.getEvents}return Object.values(tt).forEach(e=>{i.onEvent(e,t=>{try{a.on(e,t)}catch(n){Ce(`[pbjsIntegration] Error on event `+e+`: `+n.message,t),ye({context:{...n.context??{},adapter:{version:i.version,source:`pbjs:on`}},message:n.message})}})}),o().forEach(({eventType:e,args:t})=>{try{a.on(e,t)}catch(n){Ce(`[pbjsIntegration] Error on event `+e+`: `+n.message,t),ye({context:{...n.context??{},adapter:{version:i.version,source:`pbjs:replayed`}},message:n.message})}}),t}let ar={CALL:`call`,AD_CALLBACK:`pbstck:ad`};function or(e,t){return{on(n,r,i){w(`sas.dispatcher`,n,r),n===ar.AD_CALLBACK&&t.onAd(e.toAd(r,i))}}}let sr=()=>({toAd(e,t){b(e),le(t,`toAd: id is undefined`),le(e.formatId,`toAd: formatId is undefined`),y(t),pe(e,`formatId`);let n=typeof e.size==`string`?e.size:`unknown`;return{cpm:ne(e.cpm)?e.cpm:0,size:n,formatId:ne(e.formatId)?e.formatId.toString():e.formatId}}});function cr(e,t){return e[t.globalName]||(e[t.globalName]={}),e[t.globalName].cmd||(e[t.globalName].cmd=[]),e[t.globalName].cmd}let lr=new WeakSet;function ur(e,t,n){let r=e[n.globalName];if(r===void 0||!r.__smartLoaded)return{status:2};let i=sr(),a=new In,o=or(i,a);t.bindIntegration(a);let s=[];if(lr.has(r))return{status:0};lr.add(r);let c=Object.values(ar);return c.forEach(e=>{r.events.on(e,(t,n)=>{let r=et(t);s.push({eventName:e,data:r,id:n});try{o.on(e,r,n)}catch(e){e.context=e.context||{},e.context.adapter={source:`sas:on`},S(e)}})}),r.events.history().filter(({eventName:e})=>c.includes(e)).map(et).forEach(({eventName:e,data:t,id:n})=>{let r=et(t);s.push({eventName:e,data:r,id:n});try{o.on(e,t,n)}catch(e){e.context=e.context||{},e.context.adapter={source:`sas:replayed`},S(e)}}),{status:0,instance:{debug:()=>({events:s})}}}function dr(e,t){return typeof t==`object`&&t instanceof Set?Array.from(t):t}function fr(e,t){return(e===`tags`||e===`sizes`)&&Array.isArray(t)?new Set(t):t}var pr=class{constructor(e){this.coreEvents=[],this.errors=[],e.forwarder.coreAuctionStream.subscribe(e=>this.addEvent(e)),e.forwarder.coreImpressionStream.subscribe(e=>this.addEvent(e))}addEvent(e){this.coreEvents.push(e)}addError(e){this.errors.push(e)}getEvents(){return this.coreEvents.map(e=>JSON.parse(JSON.stringify(e,dr),fr))}getErrors(){return this.errors}};let mr=e=>{let t=e?.host??`unknown`;return t.startsWith(`www.`)?t.substring(4):t},hr=e=>{let t;return t=e&&e.protocol&&e.host&&e.pathname?`${e.protocol}//${e.host}${e.pathname}`:`unknown`,t};var gr=class{constructor(e,t,n){this.url=e,this.context=n,this.sender=t}buildUrl(e){return`${this.url}?sId=${this.context.scopeId.substring(0,8)}&tId=${this.context.tagId}&c=${e}&ctr=${this.context.country}`}send(e){let t=e.map(e=>_r(e,this.context));this.sender(this.buildUrl(t.length),t)}};let _r=(e,t)=>({...e,...t,domain:mr(window.location),href:hr(window.location)});function vr(e){let t=`pbstck`,n=`pbstck_context`,r=[...Jn(t),...Jn(n)],i=r.find(e=>Yn(e.name,t)===`pbstck_ab_test`);if(i)return i.content;{let t=r.find(e=>Yn(e.name,n)===`pbstck_ab_test`)?.content;return t&&!e.includes(t)&&(t=void 0),t}}function yr(){let e=`pbstck`,t=new Map;Jn(e).forEach(n=>{let r=Yn(n.name,e);t.has(r)&&T(`Custom dim ${r} is present many times`),t.size<20?t.set(r,n.content):T(`Skipping custom dim ${r} with ${n.content}: limit of 20 keys exceeded`)});let n=Object.assign({},...Array.from(t.entries()).map(([e,t])=>({[e]:t})));return t.size>0&&w(`Custom dim found :`,n),n}let br={pubstackManaged:!1,pubstackRefresh:!1,pubstackRefreshRank:0,refresh:!1,sizes:[],tags:[],customFields:{},userIdProviderList:[]};function xr(e,t){if(!(e in br))return!1;let n=br[e];return n===!1||n===0?t===n:Array.isArray(n)?Array.isArray(t)&&t.length===0:typeof n==`object`&&n?typeof t==`object`&&!!t&&!Array.isArray(t)&&Object.keys(t).length===0:!1}function Sr(e){if(Array.isArray(e))return e.map(e=>Sr(e));if(typeof e==`object`&&e){let t={};for(let[n,r]of Object.entries(e))xr(n,r)||(t[n]=Sr(r));return t}return e}var Q=class e{static{this.defaults={buffer:150}}constructor(t,n,r,i,a){this.items=[],this.url=t,this.buffer=a?.buffer??e.defaults.buffer,this.sender=n,this.context=r,this.abTestValues=i}buildUrl(){let e=this.context.customFields[`kleanads-version`],t=document.querySelector(`meta[name="pbstck:config-version"]`)?.content,n=this.items.reduce((e,t)=>e+ +!!t.pubstackRefresh,0),r=e?`&v=${e}&s=${t}`:``,i=n>0?`&rc=${n}`:``;return`${this.url}?tId=${this.context.tagId}&c=${this.items.length}${r}${i}`}batchThenSend(e,t=!0){let n=t?Cr(e,this.context,this.abTestValues):e;if(this.items.push(Sr(n)),this.buffer===0)return this.flush();this.items.length===1&&setTimeout(()=>this.flush(),this.buffer)}batchThenSendAdmMapping(e){if(this.items.push({...e,scope:this.context.scopeId,tagId:this.context.tagId,device:this.context.device,pbstckVersion:this.context.pbstckVersion}),this.buffer===0)return this.flush();this.items.length===1&&setTimeout(()=>this.flush(),this.buffer)}flush(e=!0){this.items.length!==0&&(this.sender(e?this.buildUrl():this.url,[...this.items]),this.reset())}reset(){this.items=[]}};let Cr=(e,t,n)=>{let r=`utm_source`,i=`utm_medium`,{customFields:a}=e,{customFields:o}=t,s=yr(),c=navigator.connection?.effectiveType,l={...a,...o,...s,windowWidth:window.innerWidth.toString(),windowHeight:window.innerHeight.toString()},u=new URLSearchParams(window.location.search);return u.get(r)&&(l[r]=u.get(r)),u.get(i)&&(l[i]=u.get(i)),{...e,...t,customFields:l,abTestPopulation:vr(n??[]),domain:mr(window.location),href:hr(window.location),networkConnectionEffectiveType:c,pageId:window.__pbstck_page_id||`unknown`,kleanAdsStackVersion:l[`config-version`],kleanAdsStackId:l[`kleanads-stack-id`]}},wr=s(),Tr=(e,{source:t,adUnitType:n,bidderType:r})=>e!==`one`||t!==`client`?{}:r===`mpv1`?n===`instream`?{adUnitType:n,bidderType:r}:{bidderType:r}:n===`instream`?{adUnitType:n,bidderType:`unknown`}:{};var Er=class{constructor(e,t,n,r,i=!1,a,o){this.admOnboarding=i,this.product=o;let s=e.slice(0,-7),c=e.slice(0,-7);this.admMappingGateway=new Q(`${c}/adm-mapping`,$,t),this.admConfigGateway=new Q(`${c}/adm-config`,$,t),this.viewabilityGateway=new Q(`${e}/viewability`,$,t,a),this.auctionGateway=new Q(`${e}/auction`,$,t,a),this.impressionGateway=new Q(`${e}/impression`,$,t,a),this.errorGateway=new Q(`${e}/error`,$,t,a),this.traceGateway=new Q(`${s}/trace`,$,t,void 0,{buffer:5e3}),this.measuredImpressionGateway=new Q(`${e}/measured`,$,t,a),this.measuredImpressionBeaconGateway=new gr(`${e}/measured`,Dr,t),this.pageGateway=new Q(`${e}/page`,$,t,a),this.bindController(n,r)}bindController(e,t){e.forwarder.coreAuctionStream.subscribe(e=>this.formatAndForwardAuction(e)),e.forwarder.coreImpressionStream.subscribe(e=>{this.formatAndForwardImpression(e)}),t!==void 0&&(t.viewabilityStream.subscribe(e=>{this.formatAndForwardViewability(e)}),t.viewedStream.subscribe(e=>{this.formatAndForwardMeasuredImpression(e)}),t.onUnload(e=>this.formatAndForwardMeasuredImpressionForBeacon(e)))}formatAndForwardAuction(e){let t=[];e.bidRequests.forEach(e=>{t.push({bidId:m(e),bidderCode:e.bidderCode,state:e.state,source:e.source,tags:e.tags.size===0?void 0:Array.from(e.tags),cpm:p(e)?e.cpm:void 0,currency:p(e)?e.currency:void 0,size:p(e)?e.size:void 0,customFields:e.customFields,timeToRespond:e.timeToRespond,rejectionReason:e.rejectionReason,dealId:p(e)?e.dealId:void 0,advertiserDomains:p(e)?e.advertiserDomains:void 0,bidNetRevenue:p(e)?e.bidNetRevenue:void 0,adapterCode:e.adapterCode})});let n=e.userConsentState===void 0?`notAvailable`:e.userConsentState,r=e.userConsentVersion===void 0?`notAvailable`:e.userConsentVersion,i={auctionId:e.auctionId,adUnit:e.adUnit.name,adUnitPath:e.adUnit.path,sizes:Array.from(e.sizes),tags:e.tags.size===0?void 0:Array.from(e.tags),refresh:e.refresh,userConsentState:n,userConsentVersion:r,hasUserId:e.hasUserId,userIdProviderList:e.userIdProviderList,pbjsVersion:e.pbjsVersion,bidRequests:t,pubstackManaged:!1,pubstackRefresh:e.pubstackRefresh,pubstackRefreshRank:e.pubstackRefreshRank,customFields:e.customFields,duration:e.duration,timeout:e.timeout};this.auctionGateway.batchThenSend(i),this.admOnboarding&&(e.bidRequests.filter(e=>e.admMapping).forEach(e=>this.admMappingGateway.batchThenSendAdmMapping(e.admMapping)),this.admConfigGateway.batchThenSendAdmMapping(e.admConfig))}formatAndForwardImpression(e){let t={bidId:e.bidId,auctionId:e.auctionId,lastAuctionId:e.lastAuctionId,adUnit:e.adUnit.name,adUnitPath:e.adUnit.path,bidderCode:e.bidderCode,cpm:e.cpm,currency:e.currency,refresh:e.refresh,size:e.size,userConsentState:e.userConsentState,userConsentVersion:e.userConsentVersion,hasUserId:e.hasUserId,userIdProviderList:e.userIdProviderList,pbjsVersion:e.pbjsVersion,cpmUplift:e.cpmUplift,dealId:e.dealId,advertiserDomains:e.advertiserDomains,tags:Array.from(e.tags),viewabilityMeasurable:e.viewabilityMeasurable,pubstackManaged:!1,pubstackRefresh:e.pubstackRefresh,pubstackRefreshRank:e.pubstackRefreshRank,customFields:e.customFields,bidNetRevenue:e.bidNetRevenue,source:e.source,adapterCode:e.adapterCode,pubstackServerAdunitName:e.pubstackServerAdunitName,siteEnv:e.siteEnv,product:e.siteEnv?this.product:void 0,...Tr(this.product,e)};this.impressionGateway.batchThenSend(t)}formatAndForwardViewability(e){let t={bidId:e.bidId,auctionId:e.auctionId,lastAuctionId:e.lastAuctionId,adUnit:e.adUnit.name,adUnitPath:e.adUnit.path,bidderCode:e.bidderCode,pbjsVersion:e.pbjsVersion,cpm:e.cpm,currency:e.currency,size:e.size,refresh:e.refresh,htmlElementId:e.htmlElementId,mrcViewable:!0,pubstackManaged:!1,pubstackRefresh:e.pubstackRefresh,pubstackRefreshRank:e.pubstackRefreshRank,pubstackServerAdunitName:e.pubstackServerAdunitName};this.viewabilityGateway.batchThenSend(t)}formatAndForwardMeasuredImpression(e){let t={bidId:e.bidId,auctionId:e.auctionId,lastAuctionId:e.lastAuctionId,adUnit:e.adUnit.name,adUnitPath:e.adUnit.path,bidderCode:e.bidderCode,cpm:e.cpm,currency:e.currency,refresh:e.refresh,size:e.size,pbjsVersion:e.pbjsVersion,viewedTime:e.viewedTime,pubstackManaged:!1,pubstackRefresh:e.pubstackRefresh,pubstackRefreshRank:e.pubstackRefreshRank,pubstackServerAdunitName:e.pubstackServerAdunitName};this.measuredImpressionGateway.batchThenSend(t)}formatAndForwardMeasuredImpressionForBeacon(e){let t=e.map(e=>({bidId:e.bidId,auctionId:e.auctionId,lastAuctionId:e.lastAuctionId,adUnit:e.adUnit.name,adUnitPath:e.adUnit.path,bidderCode:e.bidderCode,cpm:e.cpm,currency:e.currency,refresh:e.refresh,size:e.size,pbjsVersion:e.pbjsVersion,viewedTime:e.viewedTime,pubstackManaged:!1,pubstackRefresh:e.pubstackRefresh,pubstackRefreshRank:e.pubstackRefreshRank,pubstackServerAdunitName:e.pubstackServerAdunitName}));this.measuredImpressionBeaconGateway.send(t)}sendError(e){this.errorGateway.batchThenSend(e)}sendLog(e){this.traceGateway.batchThenSend(e,!1)}sendToDatadog(e){if(e.error===void 0||e.error===``)return;let t=e.error,n=e.context??{};b(n),y(t);let r={pageId:wr,status:`error`,domain:mr(window.location),href:hr(window.location),...n,message:t},i=new XMLHttpRequest;i.open(`POST`,`https://browser-http-intake.logs.datadoghq.com/v1/input/pub551f730416e5317842afc2792691e95c?ddsource=browser&ddtags=version:1.3.2`,!0),i.setRequestHeader(`Content-Type`,`text/plain`),i.send(JSON.stringify(r))}};let $=(e,t)=>{let n=JSON.stringify(t);if(w(`post`,e,t),typeof CompressionStream<`u`&&!C()){let t=new Blob([n]).stream().pipeThrough(new CompressionStream(`gzip`));new Response(t).blob().then(t=>{let n=new URL(e);n.searchParams.set(`gz`,`1`),fetch(n,{method:`POST`,headers:{"Content-Type":`text/plain`},body:t})})}else fetch(e,{method:`POST`,headers:{"Content-Type":`text/plain`},body:n})},Dr=(e,t)=>{let n=JSON.stringify(t);navigator.sendBeacon(e,n),w(`beacon`,e,t)};var Or=class{constructor(e){this.adUnit=e}visibilityRatioFromIntersection(e){let t=kr(this.adUnit,this.adUnit);if(this.adUnit===t)return e.intersectionRatio;let n=t.getBoundingClientRect();return e.intersectionRect.height/n.height}};let kr=(e,t)=>(Ar(e)e instanceof HTMLElement).forEach(t=>{e=kr(e,t)}),e),Ar=e=>e.getBoundingClientRect?e.getBoundingClientRect().height:0;var jr=class e{constructor(){this.state=`new`,this.elapsedTime=0,this.timeTargets=[]}static{this.pacing=100}start(){return this.state===`stopped`&&(this.elapsedTime=0),this.state===`started`?this.elapsed():(this.state=`started`,this.timeoutId=setTimeout(()=>this.update(),e.pacing),this.elapsedTime)}pause(){if(this.state===`paused`||this.state===`stopped`)return this.elapsedTime;let e=this.update();return this.state=`paused`,e}stop(){if(this.state===`stopped`)return this.elapsedTime;let e=this.update();return this.state=`stopped`,e}elapsed(){return this.state===`started`&&this.update(),this.elapsedTime}timeTargetReached(e){return new Promise(t=>{this.timeTargets.push([e,t])})}update(){let t=e.pacing;if(this.state===`started`){this.elapsedTime+=t;for(let e=this.timeTargets.length;e--;){let[n,r]=this.timeTargets[e];this.elapsedTime>=n?(r(n),this.timeTargets.splice(e,1)):t=Math.min(t,n-this.elapsedTime)}}return this.state!==`stopped`&&(this.timeoutId&&clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>this.update(),t)),this.elapsedTime}},Mr=class{constructor(e,t,n,r,i){this.creative=r,this.timer=new jr,this.inViewPercentage=e,this.cumulative=n,this.timer.timeTargetReached(t).then(()=>{i()})}pauseTimer(){this.timer.pause()}startTimer(){this.timer.start()}stopTimer(){this.timer.stop()}getElapsed(){return this.timer.elapsed()}isViewable(){return this.inView}intersectionChange(e){this.creative.visibilityRatioFromIntersection(e)>=this.inViewPercentage?this.inView||=(this.timer.start(),!0):this.inView&&=(this.cumulative?this.timer.pause():this.timer.stop(),!1)}getTimerState(){return this.timer.state}};let Nr={root:null,rootMargin:`0px`,threshold:[0,.3,.5,1]};var Pr=class{constructor(e,t,n){this.windowActive=!0,this.pbstckWindow=n,this.visibilityState=n.document.visibilityState,this.trackedOnFocusChange=this.onFocusChange.bind(this),n.addEventListener(`focus`,this.trackedOnFocusChange),n.addEventListener(`blur`,this.trackedOnFocusChange),this.trackedOnVisibilityChange=this.onVisibilityChange.bind(this),n.addEventListener(`visibilitychange`,this.trackedOnVisibilityChange);let r=this.getObserverThresholds(t);this.observer=new IntersectionObserver(e=>this.intersectionObserverCallback(e),r),this.observer.observe(e);let i=new Or(e);this.computer=new Mr(t.minPercentageInView,t.minTimeInView,t.cumulativeTimer,i,()=>t.completionCallback(e.id)),(this.visibilityState===`hidden`||!this.windowActive)&&this.stop()}getObserverThresholds(e){return e.minPercentageInView===.3?{...Nr,threshold:[.3,.5,.75,1]}:{...Nr,threshold:[.5,.75,1]}}onVisibilityChange(){this.visibilityState=this.visibilityState===`visible`?`hidden`:`visible`,this.checkWindowActive()}onFocusChange(e){this.windowActive=e.type===`focusin`||e.type===`focus`,this.checkWindowActive()}checkWindowActive(){this.visibilityState===`visible`&&this.windowActive?this.start():this.pause()}destroy(){this.stop(),this.observer?.disconnect(),this.pbstckWindow.removeEventListener(`visibilitychange`,this.trackedOnVisibilityChange),this.pbstckWindow.removeEventListener(`focus`,this.trackedOnFocusChange),this.pbstckWindow.removeEventListener(`blur`,this.trackedOnFocusChange),this.computer=null,this.observer=null}getElapsed(){return this.computer===null?0:this.computer.getElapsed()}pause(){this.computer?.pauseTimer()}start(){this.computer?.startTimer()}stop(){this.computer?.stopTimer()}intersectionObserverCallback(e){e.forEach(e=>{this.computer?.intersectionChange(e)})}getTimerState(){return this.computer?.getTimerState()}};let Fr={viewableTime:1e3,largeAdunitSize:242e3,largeAdunitTreshold:.3,standardAdunitTreshold:.5};var Ir=class{constructor(e,t){this.viewabilityState=new Map,this.viewedTimeState=new Map,this.elementIdToCode=new Map,this.viewabilityStream=new l,this.viewedStream=new l,w(`[pubstackViewability] Create ViewabilityController with config`,Fr),this.pbstckWindow=t,this.pbstckWindow.addEventListener(`pagehide`,()=>this.unloadMeasuredImpressions()),e.forwarder.coreImpressionStream.subscribe(e=>{w(`[pubstackViewability] Receive impression`,e.bidderCode,e.adUnit.code),this.track(e)}),e.forwarder.coreAuctionStream.subscribe(e=>{w(`[pubstackViewability] Receive auctionend`,e.adUnit.code),this.endMeasure(e.adUnit.code)})}onUnload(e){this.unloadCallback=e}endMeasure(e){w(`[pubstackViewability] receive event to stop measure`);let t=this.viewedTimeState.get(e);t===void 0?w(`[pubstackViewability] event received but no tracker to stop, skipping`):(t.viewabilitytracker.stop(),this.onMeasurable(e))}track(e){if(!e.viewabilityMeasurable){w(`[pubstackViewability] Cannot track impression for adUnit `,e.adUnit);return}let t=Kn(e.adUnit);if(t===null){S(Error(`[pubstackViewability] Unexpected null HTML Element on viewable impression for adUnit ${e.adUnit.name}`));return}this.trackViewability(e,t),this.trackMeasure(e,t)}async trackMeasure(e,t){let n=this.viewedTimeState.get(e.adUnit.code)?.viewabilitytracker;this.elementIdToCode.set(t.id,e.adUnit.code),n!==void 0&&(w(`[pubstackViewability] replacing existing measurability tracker on ${t.id}`),n.stop(),this.onMeasurable(e.adUnit.code)),w(`[pubstackViewability] tracking code ${e.adUnit.code} with rule MRC for measurability`),n=new Pr(t,{minPercentageInView:this.minPercentageInView(t,Fr),minTimeInView:180*1e3,cumulativeTimer:!0,completionCallback:e=>{let t=this.elementIdToCode.get(e);t===void 0?w(`[pubstackViewability] unable to find matching adunitcode for element ${e}`):this.onMeasurable(t)}},this.pbstckWindow),this.viewedTimeState.set(e.adUnit.code,{impression:e,viewabilitytracker:n})}async trackViewability(e,t){let n=this.viewabilityState.get(t.id)?.viewabilitytracker;n!==void 0&&(w(`[pubstackViewability] replacing existing tracker on ${t.id}`),n.destroy(),this.viewabilityState.delete(t.id)),w(`[pubstackViewability] tracking element ${t.id} with rule MRC for monitoring`),n=new Pr(t,{minPercentageInView:this.minPercentageInView(t,Fr),minTimeInView:Fr.viewableTime,cumulativeTimer:!1,completionCallback:e=>this.onViewable(e)},this.pbstckWindow),this.viewabilityState.set(t.id,{impression:e,viewabilitytracker:n})}minPercentageInView(e,t){let n=window.getComputedStyle(e);return Number(n.getPropertyValue(`width`).replace(/px/,``))*Number(n.getPropertyValue(`height`).replace(/px/,``))>t.largeAdunitSize?t.largeAdunitTreshold:t.standardAdunitTreshold}unloadMeasuredImpressions(){if(w(`[pubstackViewability] page unloaded, forwarding impressions measured`),this.unloadCallback!==void 0){let e=[];Array.from(this.viewedTimeState.values()).forEach(t=>{if(t.viewabilitytracker!==void 0){t.viewabilitytracker.stop();let n=Math.floor(t.viewabilitytracker.getElapsed()/1e3);n>0&&e.push({bidId:t.impression.bidId,auctionId:t.impression.auctionId,lastAuctionId:t.impression.lastAuctionId,adUnit:t.impression.adUnit,bidderCode:t.impression.bidderCode,pbjsVersion:t.impression.pbjsVersion,cpm:t.impression.cpm,currency:t.impression.currency,refresh:t.impression.refresh,size:t.impression.size,viewedTime:n,pubstackRefresh:t.impression.pubstackRefresh,pubstackRefreshRank:t.impression.pubstackRefreshRank,pubstackServerAdunitName:t.impression.pubstackServerAdunitName})}}),e.length>0&&this.unloadCallback(e)}}onMeasurable(e){w(`[pubstackViewability] Measurability Event on AdUnit code ${e}`);let t=this.viewedTimeState.get(e);if(t===void 0){S(Error(`[pubstackViewability] Impression not found for AdUnit code ${e}`));return}if(this.viewedTimeState.delete(e),Math.floor(t.viewabilitytracker.getElapsed()/1e3)>0){let e=t.impression,n={bidId:e.bidId,auctionId:e.auctionId,lastAuctionId:e.lastAuctionId,adUnit:e.adUnit,bidderCode:e.bidderCode,pbjsVersion:e.pbjsVersion,cpm:e.cpm,currency:e.currency,refresh:e.refresh,size:e.size,viewedTime:Math.floor(t.viewabilitytracker.getElapsed()/1e3),pubstackRefresh:e.pubstackRefresh,pubstackRefreshRank:e.pubstackRefreshRank,pubstackServerAdunitName:e.pubstackServerAdunitName};w(`[pubstackViewability] Forwarding measured impression on code ${e.adUnit.code}`),this.viewedStream.next(n)}t.viewabilitytracker.destroy()}onViewable(e){w(`[pubstackViewability] Viewability Event on element ${e}`);let t=this.viewabilityState.get(e);if(t===void 0){S(Error(`[pubstackViewability] Impression not found for ElementId ${e}`));return}this.viewabilityState.set(e,t);let n=t.impression,r={bidId:n.bidId,auctionId:n.auctionId,lastAuctionId:n.lastAuctionId,adUnit:n.adUnit,bidderCode:n.bidderCode,pbjsVersion:n.pbjsVersion,cpm:n.cpm,currency:n.currency,refresh:n.refresh,size:n.size,htmlElementId:e,pubstackRefresh:n.pubstackRefresh,pubstackRefreshRank:n.pubstackRefreshRank,pubstackServerAdunitName:n.pubstackServerAdunitName};w(`[pubstackViewability] Forwarding viewable impression ${r.htmlElementId}`),this.viewabilityStream.next(r)}};let Lr=()=>{let e=navigator.userAgent;return/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(e)?`tablet`:/Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test(e)?`mobile`:`desktop`},Rr=()=>window.innerWidth<768?`mobile`:`desktop`;function zr(e,t){e[t]=!0}function Br(e,t){return e[t]}function Vr(e,t,n){e.pbstck=e.pbstck||{lock:{}},e.pbstck.lock=e.pbstck.lock||{},e.pbstck.scopeId=n.scopeId,e.pbstck.tagId=n.tagId;let r={},i=`${n.tagId}@${t.gateway}@collector`;if(Br(e.pbstck.lock,i))return;zr(e.pbstck.lock,i);let a=new er;r.core=a;let o;t.viewabilityEnabled&&(o=new Ir(a,e),r.viewability=o);let s=new Er(t.gateway,n,a,o,t.admOnboarding,t.abTestValues,t.product);r.intake=s,ve(e=>s.sendError(e),1),rt(e=>{t.logsEnabled.includes(e.id)&&s.sendLog(e)}),_e(e=>s.sendToDatadog(e));let c=new Promise((n,i)=>{if(t.pbjsVariableName){w(`Prebid dropin mode`,t.pbjsVariableName);let o={debug:C(),globalName:t.pbjsVariableName};rr(e,o).push(async()=>{let s=e[o.globalName],c=Number(s.getConfig(`timeoutBuffer`))??400,l=s.getConfig(`currency`)?.adServerCurrency,u;v(l)&&(u=l);let d=new Xe({version:s.version,gracePeriod:c,adServerCurrency:u,pbjsVariableName:o.globalName},t.admOnboarding);r.prebid=d;try{r.prebid=ir(e,d,a,o),n()}catch(e){Ce(`Unable to load pbjs integration due to`,e),i();return}})}}),l=[],u;if(t.smartEnabled||t.debug){let t={debug:C(),globalName:`sas`};l=cr(e,t),l.push(()=>{u=ur(e,a,t).instance})}let d=ft(e,a,{tagId:n.tagId,globalQueue:t.sdk.globalQueue});if(d.dispatchEvents(),t.debug||C()){a.subscribe({onAuction:e=>w(`controller.onAuction`,e),onImpression:e=>w(`controller.onImpression`,e)});let n=new pr(a);r.debug=n,ve(e=>n.addError(e),1e3),e.pbstck.debug=e.pbstck.debug||{},e.pbstck.debug[i]={getEvents:()=>n.getEvents(),getErrors:()=>n.getErrors(),sdk:d?.debug()??void 0},(t.smartEnabled||t.debug)&&l.push(()=>{u&&(e.pbstck.debug[i].sas=u.debug())})}return Promise.resolve().finally(),e.pbstck.controllers=e.pbstck.controllers||{},e.pbstck.controllers[`${t.gateway}@collector`]=r,c.then(()=>{e.dispatchEvent(new Event(mt(`${t.gateway}@collector`,`pubstackMonitoringReady`)))}),a}function Hr(e){let t={gateway:e.endpoint?.gateway,sdk:{globalQueue:`pbstckQ`},debug:e.debug===!0,viewabilityEnabled:e.viewabilityEnabled,smartEnabled:e.smartEnabled??!1,refreshConfigurationUrl:e.refreshConfigurationUrl??``,pbjsVariableName:e.pbjsVariableName||`pbjs`,abTestValues:e.abTestValues,logsEnabled:e.logsEnabled||[],admOnboarding:e.admOnboarding,product:ee.includes(e.product)?e.product:void 0};if(t.gateway===void 0)return;let n=new Z(navigator.userAgent),r=n.getOS(),i=n.getBrowser(),a={tagId:e.tagId,scopeId:e.scopeId,country:e.country,device:Lr(),browserName:i.name,browserVersion:i.major,osName:r.name,osVersion:r.version,pbstckVersion:`1bd8f5d`,customFields:yr()};a.customFields.kleanadsDefaultDevice=Rr(),pt().then(e=>{e&&(a.customFields.cdep=e)}),!(!a.tagId||!a.scopeId)&&Vr(window,t,a)}e.bootPubstack=Vr,e.pubstackAutoconfig=Hr})(this.collector=this.collector||{});