goopubtag
Version:
React library for Google Publisher tag
2 lines (1 loc) • 15.9 kB
JavaScript
;var k=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var ie=(e,n)=>{for(var i in n)k(e,i,{get:n[i],enumerable:!0})},re=(e,n,i,p)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of oe(n))!ne.call(e,a)&&a!==i&&k(e,a,{get:()=>n[a],enumerable:!(p=te(n,a))||p.enumerable});return e};var se=e=>re(k({},"__esModule",{value:!0}),e);var Fe={};ie(Fe,{GPTProvider:()=>j,GPTSlot:()=>$,GUIDELINES:()=>Q,useGPT:()=>Z});module.exports=se(Fe);var b=require("react");var r=require("react/jsx-runtime"),C=()=>(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:56,height:56,viewBox:"0 0 270.933 270.933",children:[(0,r.jsx)("title",{children:"Dev icon"}),(0,r.jsxs)("defs",{children:[(0,r.jsxs)("filter",{id:"b",width:1.795,height:1.354,x:-.493,y:-.214,style:{},children:[(0,r.jsx)("feFlood",{floodColor:"#000",floodOpacity:.243,result:"flood"}),(0,r.jsx)("feComposite",{in:"flood",in2:"SourceGraphic",operator:"in",result:"composite1"}),(0,r.jsx)("feGaussianBlur",{in:"composite1",result:"blur",stdDeviation:10}),(0,r.jsx)("feOffset",{dx:-15.109,dy:-12.617,result:"offset"}),(0,r.jsx)("feComposite",{in:"SourceGraphic",in2:"offset",result:"composite2"})]}),(0,r.jsxs)("filter",{id:"a",width:1.819,height:1.335,x:-.516,y:-.195,style:{},children:[(0,r.jsx)("feFlood",{floodColor:"#000",floodOpacity:.243,result:"flood"}),(0,r.jsx)("feComposite",{in:"flood",in2:"SourceGraphic",operator:"in",result:"composite1"}),(0,r.jsx)("feGaussianBlur",{in:"composite1",result:"blur",stdDeviation:10}),(0,r.jsx)("feOffset",{dx:-16.978,dy:-9.502,result:"offset"}),(0,r.jsx)("feComposite",{in:"SourceGraphic",in2:"offset",result:"composite2"})]})]}),(0,r.jsxs)("g",{style:{display:"inline"},children:[(0,r.jsxs)("g",{style:{display:"inline",opacity:1},transform:"rotate(-20.363 177.66 214.553)",children:[(0,r.jsx)("rect",{width:79.375,height:132.292,x:87.28,y:70.478,rx:13.79,ry:11.742,style:{opacity:1,fill:"#4249d0",fillOpacity:1,stroke:"#604d29",strokeWidth:0}}),(0,r.jsx)("path",{d:"M126.36 31.374c-3.717.064-7.878 2.154-12.028 8.231l-.007.01-6.626 9.71-19.38 28.398 38.648.055 38.647.056-19.267-28.455-6.612-9.764s-5.758-8.372-13.375-8.241zm.864 16.092a9.803 10.294 0 0 1 2.28.348 9.803 10.294 0 0 1 6.932 12.606 9.803 10.294 0 0 1-12.005 7.28 9.803 10.294 0 0 1-6.932-12.606l9.468 2.662-9.468-2.663a9.803 10.294 0 0 1 8.955-7.616 9.803 10.294 0 0 1 .77-.01z",style:{opacity:1,fill:"#4249d0",fillOpacity:1,stroke:"#64a1bd",strokeWidth:0,strokeLinejoin:"round",strokeDasharray:"none",strokeOpacity:1}})]}),(0,r.jsx)("text",{xmlSpace:"preserve",x:184.785,y:-27.732,style:{fontStyle:"normal",fontVariant:"normal",fontWeight:400,fontStretch:"normal",fontSize:"25.4px",fontFamily:""",display:"inline",opacity:1,fill:"#141c9f",fillOpacity:.768627,stroke:"#64a1bd",strokeWidth:0,strokeLinejoin:"round",strokeDasharray:"none",strokeOpacity:1},transform:"rotate(68.298)",children:(0,r.jsx)("tspan",{x:184.785,y:-27.732,style:{fontStyle:"normal",fontVariant:"normal",fontWeight:400,fontStretch:"normal",fontFamily:""",fill:"#141c9f",fillOpacity:.768627,strokeWidth:0},children:"TAG"})}),(0,r.jsxs)("g",{style:{display:"inline",opacity:.9,filter:"url(#a)"},transform:"rotate(-60.67 129.82 122.094)",children:[(0,r.jsx)("rect",{width:79.375,height:132.292,x:95.779,y:69.321,rx:13.79,ry:11.742,style:{opacity:1,fill:"#22278b",fillOpacity:1,stroke:"#604d29",strokeWidth:0}}),(0,r.jsx)("path",{d:"M134.86 30.216c-3.718.064-7.879 2.154-12.029 8.232l-.007.01-6.625 9.709-19.38 28.398 38.647.055 38.648.056-19.268-28.455-6.612-9.764s-5.758-8.372-13.374-8.24zm.863 16.093a9.803 10.294 0 0 1 2.28.347 9.803 10.294 0 0 1 6.932 12.607 9.803 10.294 0 0 1-12.005 7.28 9.803 10.294 0 0 1-6.932-12.607l9.469 2.663-9.469-2.664a9.803 10.294 0 0 1 8.955-7.615 9.803 10.294 0 0 1 .77-.011z",style:{opacity:1,fill:"#22278b",fillOpacity:1,stroke:"#64a1bd",strokeWidth:0,strokeLinejoin:"round",strokeDasharray:"none",strokeOpacity:1}})]}),(0,r.jsx)("text",{xmlSpace:"preserve",x:182.305,y:46.888,style:{fontStyle:"normal",fontVariant:"normal",fontWeight:400,fontStretch:"normal",fontSize:"25.4px",fontFamily:""",display:"inline",opacity:1,fill:"#0c0e57",fillOpacity:.768627,stroke:"#64a1bd",strokeWidth:0,strokeLinejoin:"round",strokeDasharray:"none",strokeOpacity:1},transform:"rotate(30.23)",children:(0,r.jsx)("tspan",{x:182.305,y:46.888,style:{fontStyle:"normal",fontVariant:"normal",fontWeight:400,fontStretch:"normal",fontFamily:""",fill:"#0c0e57",fillOpacity:.768627,strokeWidth:0},children:"PUB"})}),(0,r.jsxs)("g",{style:{display:"inline",opacity:.85,filter:"url(#b)"},transform:"rotate(-97.4 118.082 97.204)",children:[(0,r.jsx)("rect",{width:79.375,height:132.292,x:95.779,y:69.321,rx:13.79,ry:11.742,style:{opacity:.9,fill:"#2d36e5",fillOpacity:1,stroke:"#604d29",strokeWidth:0}}),(0,r.jsx)("path",{d:"M134.86 30.216c-3.718.064-7.879 2.154-12.029 8.232l-.007.01-6.625 9.709-19.38 28.398 38.647.055 38.648.056-19.268-28.455-6.612-9.764s-5.758-8.372-13.374-8.24zm.863 16.093a9.803 10.294 0 0 1 2.28.347 9.803 10.294 0 0 1 6.932 12.607 9.803 10.294 0 0 1-12.005 7.28 9.803 10.294 0 0 1-6.932-12.607l9.469 2.663-9.469-2.664a9.803 10.294 0 0 1 8.955-7.615 9.803 10.294 0 0 1 .77-.011z",style:{opacity:.9,fill:"#2d36e5",fillOpacity:1,stroke:"#64a1bd",strokeWidth:0,strokeLinejoin:"round",strokeDasharray:"none",strokeOpacity:1}})]}),(0,r.jsx)("text",{xmlSpace:"preserve",x:135.099,y:97.69,style:{fontStyle:"normal",fontVariant:"normal",fontWeight:400,fontStretch:"normal",fontSize:"25.4px",fontFamily:""",display:"inline",opacity:1,fill:"#121581",fillOpacity:.768627,stroke:"#64a1bd",strokeWidth:0,strokeLinejoin:"round",strokeDasharray:"none",strokeOpacity:1},transform:"rotate(-5.23)",children:(0,r.jsx)("tspan",{x:135.099,y:97.69,style:{fontStyle:"normal",fontVariant:"normal",fontWeight:400,fontStretch:"normal",fontFamily:""",fill:"#121581",fillOpacity:.768627,strokeWidth:0},children:"GOO"})}),(0,r.jsx)("ellipse",{cx:75.247,cy:83.959,fill:"none",rx:9.858,ry:9.195,style:{opacity:1,fill:"#141c9f",fillOpacity:0,stroke:"#161b94",strokeWidth:4.61478,strokeLinejoin:"round",strokeDasharray:"none",strokeOpacity:.94902}})]})]});var L=require("react/jsx-runtime"),U=()=>(0,L.jsx)("div",{style:{position:"fixed",bottom:"8px",right:"8px",width:"56px",height:"56px",padding:"4px 4px 0px 4px",display:"flex",justifyContent:"center",alignItems:"center",borderRadius:"12px",border:"1px dotted rebeccapurple",backgroundColor:"#66339933",zIndex:"9999"},"data-testid":"gpt-dev-icon",children:(0,L.jsx)("button",{type:"button",onClick:()=>{window.googletag?.openConsole()},style:{all:"unset",color:"white",textAlign:"center",cursor:"pointer"},children:(0,L.jsx)(C,{})})});var c=require("react");var D={STANDARD:"https://securepubads.g.doubleclick.net/tag/js/gpt.js",LIMITED_ADS:"https://pagead2.googlesyndication.com/tag/js/gpt.js"};var ae=e=>e?D.LIMITED_ADS:D.STANDARD,V=e=>{let{limitedAds:n}=e,i=document.createElement("script");return i.src=ae(n),i.async=!0,i.type="text/javascript",i};var h=(e,n)=>{let i=new CustomEvent(e,{bubbles:!0,detail:n});document.dispatchEvent(i)},O=(e,n)=>{document.addEventListener(e,i=>{n(i.detail)})},G=(e,n)=>{document.removeEventListener(e,i=>{n(i.detail)})};var de=()=>{window.googletag=window.googletag||{},window.googletag.cmd=window.googletag.cmd||[]},le=e=>{window.googletag?.cmd.push(e)},ge=()=>{window.googletag?.pubads().collapseEmptyDivs()},pe=()=>{window.googletag?.pubads().collapseEmptyDivs(!0)},q=()=>window.googletag?.enums.OutOfPageFormat.TOP_ANCHOR||null,N=()=>window.googletag?.enums.OutOfPageFormat.BOTTOM_ANCHOR||null,z=()=>window.googletag?.enums.OutOfPageFormat.LEFT_SIDE_RAIL||null,M=()=>window.googletag?.enums.OutOfPageFormat.RIGHT_SIDE_RAIL||null,B=()=>window.googletag?.enums.OutOfPageFormat.REWARDED||null,ce=e=>{switch(e.type){case"anchor":return e.settings.position==="top"?q():e.settings.position==="bottom"?N():null;case"rewarded":return B();case"rail":return e.settings.position==="left"?z():e.settings.position==="right"?M():null;default:return null}},ue=(e,n)=>window.googletag?.defineOutOfPageSlot(e,n)||null,fe=e=>{if(e&&e!=="default")switch(e){case"collapse":{ge();break}case"expand":{pe();break}default:break}},ve=(e,n)=>{window.googletag?.pubads().setTargeting(e,n)},Se=e=>{e?window.googletag?.pubads().clearTargeting(e):window.googletag?.pubads().clearTargeting()},me=e=>{e.addService(window.googletag?.pubads())},ye=(e,n)=>`/${e}/${n}`,Ee=e=>{window.googletag?.pubads().setPrivacySettings(e)},we=e=>{e?window.googletag?.pubads().refresh(e):window.googletag?.pubads().refresh()},Pe=(e,n,i)=>window.googletag?.defineSlot(e,n,i)?.addService(window.googletag?.pubads())||null,Te=()=>window.googletag?.sizeMapping(),be=e=>{window.googletag?.pubads().addEventListener("rewardedSlotReady",e)},Re=e=>{window.googletag?.pubads().addEventListener("rewardedSlotClosed",e)},he=e=>{window.googletag?.pubads().addEventListener("rewardedSlotGranted",e)},Oe=e=>{window.googletag?.pubads().removeEventListener("rewardedSlotReady",e)},Ge=e=>{window.googletag?.pubads().removeEventListener("rewardedSlotClosed",e)},Le=e=>{window.googletag?.pubads().removeEventListener("rewardedSlotGranted",e)},Ae=e=>{window.googletag?.pubads().addEventListener("slotOnload",e)},xe=e=>{window.googletag?.pubads().addEventListener("slotRequested",e)},_e=e=>{window.googletag?.pubads().addEventListener("impressionViewable",e)},Ie=e=>{window.googletag?.pubads().addEventListener("slotRenderEnded",e)},ke=e=>{window.googletag?.pubads().removeEventListener("slotOnload",e)},De=e=>{window.googletag?.pubads().removeEventListener("slotRequested",e)},Ce=e=>{window.googletag?.pubads().removeEventListener("impressionViewable",e)},Ue=e=>{window.googletag?.pubads().removeEventListener("slotRenderEnded",e)},W=()=>{window.googletag?.enableServices()},Ve=e=>{W(),window?.googletag?.display(e)},qe=e=>{W(),window?.googletag?.display(e)},Ne=()=>{window.googletag?.pubads().enableSingleRequest()},ze=e=>{typeof e=="boolean"?window.googletag?.pubads().enableLazyLoad():window.googletag?.pubads().enableLazyLoad(e)},t={init:de,push:le,getAdUnitPath:ye,getTopAnchor:q,getBottomAnchor:N,getLeftSideRail:z,getRightSideRail:M,getRewarded:B,getOutOfPageSlotId:ce,getMapping:Te,createSlot:Pe,createOutOfPageSlot:ue,handleFallback:fe,handleRewardedSlotReady:be,handleRewardedSlotClosed:Re,handleRewardedSlotGranted:he,removeRewardedSlotReady:Oe,removeRewardedSlotClosed:Ge,removeRewardedSlotGranted:Le,handleSlotLoad:Ae,handleSlotRequested:xe,handleSlotIsViewable:_e,handleSlotRenderEnded:Ie,removeSlotLoad:ke,removeSlotRequested:De,removeSlotIsViewable:Ce,removeSlotRenderEnded:Ue,setTargeting:ve,setPrivacySettings:Ee,clearTargeting:Se,refresh:we,addService:me,enableService:Ve,enableOutOfPageService:qe,enableSingleRequest:Ne,enableLazyLoad:ze};var F=e=>{let[n,i]=(0,c.useState)([]),[p,a]=(0,c.useState)([]),{networkId:y,limitedAds:v=!1,fallback:S="default",targetingArguments:s,outOfPage:o}=e,u=(0,c.useCallback)(l=>a(g=>[...g,l]),[]),f=(0,c.useCallback)(l=>i(g=>[...g,l]),[]),w=(0,c.useCallback)(l=>{h("slot_load",l)},[]),E=(0,c.useCallback)(l=>{h("slot_requested",l)},[]),P=(0,c.useCallback)(l=>{h("impression_viewable",l)},[]),T=(0,c.useCallback)(l=>{h("slot_render_ended",l)},[]);return(0,c.useEffect)(()=>{let l=V({limitedAds:v});document.getElementsByTagName("head")[0].appendChild(l)},[v]),(0,c.useEffect)(()=>(p.find(g=>g.slotId===o?.type)||(t.init(),t.push(()=>{if(o){let g=t.createOutOfPageSlot(t.getAdUnitPath(y,o.adUnit),t.getOutOfPageSlotId(o));if(g){if(o.targetingArguments)for(let I of Object.keys(o.targetingArguments))g.setTargeting(I,o.targetingArguments[I]);o.onSlotLoad&&t.handleSlotLoad(o.onSlotLoad),o.onSlotRequested&&t.handleSlotRequested(o.onSlotRequested),o.onSlotIsViewable&&t.handleSlotIsViewable(o.onSlotIsViewable),o.onSlotRenderEnded&&t.handleSlotRenderEnded(o.onSlotRenderEnded),o.type==="rewarded"&&o.settings.onReady&&t.handleRewardedSlotReady(o.settings.onReady),o.type==="rewarded"&&o.settings.onClosed&&t.handleRewardedSlotClosed(o.settings.onClosed),o.type==="rewarded"&&o.settings.onGranted&&t.handleRewardedSlotGranted(o.settings.onGranted),t.addService(g),o.withStaticAds||t.enableOutOfPageService(g),u({slotId:o.type,unit:g})}}if(s)for(let g of Object.keys(s))t.setTargeting(g,s[g]);t.handleSlotLoad(w),t.handleSlotRequested(E),t.handleSlotIsViewable(P),t.handleSlotRenderEnded(T),t.handleFallback(S)})),()=>{t.removeSlotLoad(w),t.removeSlotRequested(E),t.removeSlotIsViewable(P),t.removeSlotRenderEnded(T)}),[S,o,s,y,p,u,w,E,P,T]),{units:n,addUnit:f}};var x=require("react/jsx-runtime"),K=(0,b.createContext)({}),j=e=>{let{children:n,...i}=e,p=F(i),a=(0,b.useMemo)(()=>p,[p]);return(0,x.jsxs)(K.Provider,{value:{...i,...a},children:[n,i.debug&&(0,x.jsx)(U,{})]})},A=()=>(0,b.useContext)(K);var Y=require("react");var _=require("react");var H=e=>{let{adUnit:n,sizes:i,sizeMapping:p,slotId:a,targetingArguments:y,onSlotLoad:v,onSlotRequested:S,onSlotIsViewable:s,onSlotRenderEnded:o,fallback:u="default"}=e,{networkId:f,units:w,lazyLoad:E,singleRequest:P,addUnit:T}=A(),l=t.getAdUnitPath(f,n),g=(0,_.useRef)();return(0,_.useEffect)(()=>(t.init(),t.push(()=>{let m=null;if(!(g.current||w?.find(d=>d.slotId===a))&&(m=t.createSlot(l,i,a),m!==null)){if(p){let d=t.getMapping();for(let{viewport:J,sizes:ee}of p)d.addSize(J,ee);let R=d.build();m.defineSizeMapping(R)}if(y)for(let d of Object.keys(y))m.setTargeting(d,y[d]);if(E!==void 0&&t.enableLazyLoad(E),v&&O("slot_load",d=>{d.slot.getSlotElementId()===a&&v(d)}),S&&O("slot_requested",d=>{d.slot.getSlotElementId()===a&&S(d)}),s&&O("impression_viewable",d=>{d.slot.getSlotElementId()===a&&s(d)}),o&&O("slot_render_ended",d=>{d.slot.getSlotElementId()===a&&o(d)}),u&&u!=="default")switch(u){case"expand":{m.setCollapseEmptyDiv(!0,!0);break}case"expand_strict":{m.setCollapseEmptyDiv(!1);break}case"collapse":{m.setCollapseEmptyDiv(!0);break}default:break}g.current={slotId:a,unit:m},a&&T({slotId:a,unit:m}),P&&t.enableSingleRequest(),t.enableService(a)}}),()=>{v&&G("slot_load",v),S&&G("slot_requested",S),s&&G("impression_viewable",s),o&&G("slot_render_ended",o)}),[y,p,a,l,u,i,w,E,P,T,v,S,s,o]),{style:i?typeof i=="string"?{width:"100%"}:Array.isArray(i[0])?{width:"100%"}:{width:`${i[0]}px`,height:`${i[1]}px`}:{}}};var X=require("react/jsx-runtime"),Me=e=>{let{slotId:n,className:i,dataTestId:p}=e,{style:a}=H(e);return(0,X.jsx)("div",{id:n,style:a,className:i,"data-testid":p})},$=(0,Y.memo)(Me);var Be={BILLBOARD:[970,250],SKYSCRAPER_WIDE:[300,600],SKYSCRAPER:[160,600],SKYSCRAPER_SLIM:[120,600],LEADERBOARD_XL:[970,90],LEADERBOARD_LARGE:[920,90],LEADERBOARD:[728,90],MPU:[320,250],MPU_300:[300,250],MOBILE_LEADERBOARD_LARGE:[468,60],MOBILE_LEADERBOARD_MEDIUM:[320,100],MOBILE_LEADERBOARD:[320,50],LINE_TEXT_UNIT:[280,18],ONE_BY_ONE:[1,1],FLUID:"fluid"},We={DESKTOP_LARGEST:[1220,0],DESKTOP_PLUS:[970,0],DESKTOP:[861,0],TABLET_PLUS:[728,0],TABLET:[600,0],MOBILE_PLUS:[468,0],MOBILE:[320,0]},Q={UNIT_SIZE:Be,SCREEN_SIZE:We};var Z=()=>{let{units:e,limitedAds:n}=A();return{refresh:s=>{t.push(()=>{s&&s.length!==0?t.refresh(s):t.refresh()})},setTargetingAttributes:(s,o)=>{t.push(()=>{let u=e.find(f=>f.slotId===s)?.unit;for(let f of Object.keys(o))u?.setTargeting(f,o[f])})},setPageTargetingAttributes:s=>{t.push(()=>{for(let o of Object.keys(s))t.setTargeting(o,s[o])})},clearTargetingAttributes:(s,o)=>{t.push(()=>{let u=e.find(f=>f.slotId===s)?.unit;if(o)for(let f of o)u?.clearTargeting(f);else u?.clearTargeting()})},clearPageTargetingAttributes:s=>{t.push(()=>{if(s)for(let o of s)t.clearTargeting(o);else t.clearTargeting()})},setPrivacySettings:s=>{if(!n&&s.limitedAds!==void 0)throw new Error("limited ads must be enabled on GPTContext to set privacy settings");t.push(()=>{t.setPrivacySettings(s)})}}};0&&(module.exports={GPTProvider,GPTSlot,GUIDELINES,useGPT});