UNPKG

c3-sdk

Version:

A lightweight JavaScript SDK for Google AdSense, Google Publisher Tag (GPT), and Google AdSense for Search (AFS) integration

1 lines 21.2 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).C3=e()}(this,function(){"use strict";var t=Object.defineProperty,e=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,o=(e,n,i)=>n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[n]=i,r=(t,r)=>{for(var s in r||(r={}))n.call(r,s)&&o(t,s,r[s]);if(e)for(var s of e(r))i.call(r,s)&&o(t,s,r[s]);return t};function s(t,e={}){return new Promise((n,i)=>{if(document.querySelector(`script[src="${t}"]`))return void n();const o=document.createElement("script");o.src=t,o.async=e.async,e.pubId&&(o.setAttribute("data-ad-client",e.pubId),o.setAttribute("data-ad-frequency-hint",e.hint)),e.crossOrigin&&o.setAttribute("crossorigin",e.crossOrigin),o.onload=()=>{n()},o.onerror=()=>{i(new Error(`Script load failed: ${t}`))},document.head.appendChild(o)})}function a(t,e,n={}){const{rootMargin:i="50px"}=n;if(!window.IntersectionObserver)return e(),null;const o=new IntersectionObserver(n=>{n.forEach(n=>{n.isIntersecting&&(e(),o.unobserve(t))})},{rootMargin:i,threshold:.01});return o.observe(t),o}function d(t,e){return e<=0?null:setInterval(()=>{try{t()}catch(e){}},1e3*e)}function c(t){t&&clearInterval(t)}const AdSense={init(t){this.config=t,this.pubId=t.pubId,this.ads=[],this.hashChangeHandler=null,this.adCounter=0,window.adsbygoogle=window.adsbygoogle||[];const e=t.adsenseConfig&&t.adsenseConfig.vignetteConfig||t.vignetteConfig;e&&e.enabled&&this.setupHashChangeListener(),e&&e.initialPrerollDelay>0&&this.setupInitialPreroll(),(t.adsenseConfig&&t.adsenseConfig.rewardConfig||{}).initialRewardDelay>0&&this.setupInitialReward()},setupHashChangeListener(){const t=this.getVignetteConfig();t&&t.enabled&&(this.initAdTracking(),this.hashChangeHandler=()=>{this.handleHashChange()},window.addEventListener("hashchange",this.hashChangeHandler),t.maxVignetteMissed>0&&(this.vignetteCheckInterval=setInterval(()=>{this.checkMissedVignette()},3e4)),this.handleHashChange(),this.initCycleState())},getVignetteConfig(){return this.config.adsenseConfig&&this.config.adsenseConfig.vignetteConfig||this.config.vignetteConfig},checkMissedVignette(){const t=this.getVignetteConfig();if(!t||!t.enabled||t.maxVignetteMissed<=0)return;const e=this.getAdTracking();if(e&&Date.now()-(e.lastVignetteTime||0)>6e4&&e.lastVignetteTime>0){const n=(e.missedVignetteCount||0)+1;this.updateAdTracking({missedVignetteCount:n}),n>=t.maxVignetteMissed&&this.t()}},initAdTracking(){const t="c3_adsense_ad_tracking";if(!sessionStorage.getItem(t)){const e={vignetteCount:0,prerollCount:0,lastVignetteTime:0,missedVignetteCount:0,totalVignetteCount:0,totalPrerollCount:0,currentCycle:"vignette"};sessionStorage.setItem(t,JSON.stringify(e))}},initCycleState(){const t=this.getAdTracking();t&&!t.currentCycle&&this.updateAdTracking({currentCycle:"vignette"})},getAdTracking(){const t=sessionStorage.getItem("c3_adsense_ad_tracking");return t?JSON.parse(t):null},updateAdTracking(t){const e=this.getAdTracking()||{vignetteCount:0,prerollCount:0,lastVignetteTime:0,missedVignetteCount:0,totalVignetteCount:0,totalPrerollCount:0,currentCycle:"vignette"},n=r(r({},e),t);return sessionStorage.setItem("c3_adsense_ad_tracking",JSON.stringify(n)),n},handleHashChange(){const t=window.location.hash,e=this.getVignetteConfig();if(!e||!e.enabled)return;let n=this.getAdTracking();if(t.includes("google_vignette")){const t=(n.vignetteCount||0)+1,i=(n.totalVignetteCount||0)+1;if(n=this.updateAdTracking({vignetteCount:t,totalVignetteCount:i,lastVignetteTime:Date.now(),missedVignetteCount:0,currentCycle:"vignette"}),t>=e.vignetteToPreroll.count&&e.vignetteToPreroll.count>0){n=this.updateAdTracking({vignetteCount:0,prerollCount:0,currentCycle:"preroll"});const t=e.vignetteToPreroll.trigger||1;setTimeout(()=>{this.triggerPrerollCycle(t,0)},100)}}else if(t.includes("goog_fullscreen_ad")){const t=(n.prerollCount||0)+1,i=(n.totalPrerollCount||0)+1;n=this.updateAdTracking({prerollCount:t,totalPrerollCount:i,missedVignetteCount:0,currentCycle:"preroll"}),t>=e.prerollToVignette.count&&e.prerollToVignette.count>0&&(n=this.updateAdTracking({vignetteCount:0,prerollCount:0,currentCycle:"vignette"}))}else if(t&&t!==window.location.hash){const t=(n.missedVignetteCount||0)+1;n=this.updateAdTracking({missedVignetteCount:t}),t>=e.maxVignetteMissed&&e.maxVignetteMissed>0&&"vignette"===n.currentCycle&&setTimeout(()=>{this.t()},100)}},checkAndTriggerPreroll(){const t=this.getVignetteConfig();if(!t||!t.enabled)return!1;const e=this.getAdTracking();if(!e)return!1;const n=e.vignetteCount>=t.vignetteToPreroll.count&&t.vignetteToPreroll.count>0&&"vignette"===e.currentCycle,i=e.missedVignetteCount>=t.maxVignetteMissed&&t.maxVignetteMissed>0&&"vignette"===e.currentCycle;if(n){const e=t.vignetteToPreroll.trigger||1;return this.triggerPrerollCycle(e,0),!0}return!!i&&(this.t(),!0)},i:()=>!!window.adsbygoogle&&"object"==typeof window.adsbygoogle&&!!document.querySelector('script[src*="adsbygoogle.js"]'),o(t,e=0,n=5){if(!(e>=n)){if(!this.i())return void setTimeout(()=>{this.o(t,e+1,n)},e<2?500:1e3);try{t()}catch(i){i.message&&(i.message.includes("no interstitial API")||i.message.includes("interstitial"))&&setTimeout(()=>{this.o(t,e+1,n)},e<2?1e3:2e3)}}},t(){this.o(()=>{window.adBreak&&window.adBreak({type:"preroll",adBreakDone:()=>{const t=this.getAdTracking(),e=((null==t?void 0:t.prerollCount)||0)+1,n=((null==t?void 0:t.totalPrerollCount)||0)+1;this.updateAdTracking({prerollCount:e,totalPrerollCount:n,missedVignetteCount:0,currentCycle:"preroll"});const i=this.getVignetteConfig();i&&e>=i.prerollToVignette.count&&i.prerollToVignette.count>0&&this.updateAdTracking({vignetteCount:0,prerollCount:0,currentCycle:"vignette"})}})})},showPreroll(t={}){const e=t.beforeAd,n=t.adDismissed,i=t.adViewed,o=t.afterAd,r=t.adBreakDone;this.o(()=>{if(window.adBreak){const t={type:"preroll",beforeAd:()=>{e&&e()},adDismissed:()=>{n&&n()},adViewed:()=>{i&&i()},afterAd:()=>{o&&o()},adBreakDone:()=>{const t=this.getAdTracking(),e=((null==t?void 0:t.prerollCount)||0)+1,n=((null==t?void 0:t.totalPrerollCount)||0)+1;this.updateAdTracking({prerollCount:e,totalPrerollCount:n,missedVignetteCount:0,currentCycle:"preroll"});const i=this.getVignetteConfig();i&&e>=i.prerollToVignette.count&&i.prerollToVignette.count>0&&this.updateAdTracking({vignetteCount:0,prerollCount:0,currentCycle:"vignette"}),r&&r()}};window.adBreak(t)}})},triggerPrerollCycle(t,e){if(e>=t)return;const n=this.getAdTracking(),i=(null==n?void 0:n.prerollCount)||0;this.t();const o=setInterval(()=>{const e=this.getAdTracking(),n=(null==e?void 0:e.prerollCount)||0;n>i&&(clearInterval(o),setTimeout(()=>{this.triggerPrerollCycle(t,n)},500))},500);setTimeout(()=>{clearInterval(o);const n=this.getAdTracking(),r=(null==n?void 0:n.prerollCount)||0;r===i?this.triggerPrerollCycle(t,e+1):this.triggerPrerollCycle(t,r)},3e4)},setupInitialPreroll(){const t=this.getVignetteConfig();if(!t||t.initialPrerollDelay<=0)return;const e="c3_adsense_initial_preroll_triggered";"true"!==sessionStorage.getItem(e)&&(this.initialPrerollTimer=setTimeout(()=>{"true"!==sessionStorage.getItem(e)&&(sessionStorage.setItem(e,"true"),this.t())},1e3*t.initialPrerollDelay))},setupInitialReward(){const t=(this.config.adsenseConfig||{}).rewardConfig||{};if(!t||t.initialRewardDelay<=0)return;const e="c3_adsense_initial_reward_triggered";"true"!==sessionStorage.getItem(e)&&(this.initialRewardTimer=setTimeout(()=>{"true"!==sessionStorage.getItem(e)&&(sessionStorage.setItem(e,"true"),this.showReward())},1e3*t.initialRewardDelay))},cleanup(){this.hashChangeHandler&&(window.removeEventListener("hashchange",this.hashChangeHandler),this.hashChangeHandler=null),this.vignetteCheckInterval&&(clearInterval(this.vignetteCheckInterval),this.vignetteCheckInterval=null),this.initialPrerollTimer&&(clearTimeout(this.initialPrerollTimer),this.initialPrerollTimer=null),this.initialRewardTimer&&(clearTimeout(this.initialRewardTimer),this.initialRewardTimer=null)},createAd(t={}){if(!this.config)throw new Error("AdSense not initialized, call c3.init() first");const{adSlotId:e,adFormat:n="auto",fullWidthResponsive:i=!0,containerId:o,lazyLoad:r=!1,autoRefreshSeconds:s=0,width:c,height:l,display:u="inline-block"}=t;if(!e)throw new Error("adSlotId is required");const h=o?document.getElementById(o):document.body;if(!h)throw new Error(`Container not found: ${o||"body"}`);const w=document.createElement("ins");w.className="adsbygoogle",w.style.display=u,w.style.width=c?"number"==typeof c?`${c}px`:c:"100%",l&&(w.style.height="number"==typeof l?`${l}px`:l),w.setAttribute("data-ad-client",this.pubId),w.setAttribute("data-ad-slot",e),l||(w.setAttribute("data-full-width-responsive","true"),w.setAttribute("data-ad-format",n)),h.appendChild(w);const g=`c3_ad_${Date.now()}_${++this.adCounter}_${Math.random().toString(36).substr(2,9)}`,f=()=>{const t=document.createElement("ins");return t.className="adsbygoogle",t.style.display=u,t.style.width=void 0!==c?"number"==typeof c?`${c}px`:c:"100%",void 0!==l&&(t.style.height="number"==typeof l?`${l}px`:l),t.setAttribute("data-ad-client",this.pubId),t.setAttribute("data-ad-slot",e),i&&(t.setAttribute("data-full-width-responsive","true"),t.setAttribute("data-ad-format",n)),t},m=()=>{try{(window.adsbygoogle=window.adsbygoogle||[]).push({})}catch(t){}},p=()=>{try{const t=this.ads.findIndex(t=>t.id===g);if(-1===t)return;const e=this.ads[t],n=e.element;if(!n||!n.parentNode)return;const i=n.parentNode;i.removeChild(n);const o=f();i.appendChild(o),e.element=o,e.observer&&(e.observer.disconnect(),e.observer=null),r?e.observer=a(o,m,{rootMargin:"50px"}):m()}catch(t){}};let y=null;r?y=a(w,m,{rootMargin:"50px"}):m();let v=null;s>0&&(v=d(p,s));const C={id:g,element:w,adSlotId:e,containerId:o||"body",lazyLoad:r,autoRefreshSeconds:s,refreshTimer:v,observer:y,adFormat:n,fullWidthResponsive:i,width:c,height:l,display:u,container:h,refreshAd:p};return this.ads.push(C),C},refresh(t){if(t){if("object"==typeof t&&t.id){const e=this.ads.find(e=>e.id===t.id);e&&(e.refreshAd&&"function"==typeof e.refreshAd?e.refreshAd():this.l(e))}else if("string"==typeof t)if(t.startsWith("c3_ad_")){const e=this.ads.find(e=>e.id===t);e&&(e.refreshAd&&"function"==typeof e.refreshAd?e.refreshAd():this.l(e))}else this.ads.filter(e=>e.adSlotId===t).forEach(t=>{t.refreshAd&&"function"==typeof t.refreshAd?t.refreshAd():this.l(t)})}else this.ads.forEach(t=>{t.refreshAd&&"function"==typeof t.refreshAd?t.refreshAd():this.l(t)})},l(t){if(t.element&&t.element.parentNode)try{const e=t.element.parentNode,n=t.container||e;e.removeChild(t.element);const i=document.createElement("ins");if(i.className="adsbygoogle",i.style.display=t.display||"inline-block",void 0!==t.width?"number"==typeof t.width?i.style.width=`${t.width}px`:i.style.width=t.width:i.style.width="100%",void 0!==t.height&&("number"==typeof t.height?i.style.height=`${t.height}px`:i.style.height=t.height),i.setAttribute("data-ad-client",this.pubId),i.setAttribute("data-ad-slot",t.adSlotId),t.fullWidthResponsive&&(i.setAttribute("data-full-width-responsive","true"),i.setAttribute("data-ad-format",t.adFormat||"auto")),n.appendChild(i),t.element=i,t.observer&&(t.observer.disconnect(),t.observer=null),t.lazyLoad){const e=()=>{try{(window.adsbygoogle=window.adsbygoogle||[]).push({})}catch(t){}};t.observer=a(i,e,{rootMargin:"50px"})}else(window.adsbygoogle=window.adsbygoogle||[]).push({})}catch(e){}},remove(t){const e=this.ads.findIndex(e=>e.adSlotId===t);if(-1!==e){const t=this.ads[e];t.refreshTimer&&c(t.refreshTimer),t.observer&&t.observer.disconnect(),t.element&&t.element.parentNode&&t.element.parentNode.removeChild(t.element),this.ads.splice(e,1)}},triggerPreroll(t={}){this.showPreroll(t)},showReward(t={}){const e=(this.config.adsenseConfig||{}).rewardConfig||{},n=t.name||e.name||"c3_reward",i=t.beforeAd||e.beforeAd,o=t.beforeReward||e.beforeReward,r=t.adDismissed||e.adDismissed,s=t.adViewed||e.adViewed,a=t.afterAd||e.afterAd,d=t.adBreakDone||e.adBreakDone;try{if(window.adBreak){const t={type:"reward",name:n,beforeAd:()=>{i&&i()},beforeReward:t=>{o?o(t):t&&t()},adDismissed:()=>{r&&r()},adViewed:()=>{s&&s()},afterAd:()=>{a&&a()},adBreakDone:()=>{d&&d()}};window.adBreak(t)}}catch(c){}},getAdTrackingStats(){return this.getAdTracking()},resetAdTracking(){sessionStorage.removeItem("c3_adsense_ad_tracking"),this.initAdTracking()},resetInitialPreroll(){sessionStorage.removeItem("c3_adsense_initial_preroll_triggered")},resetInitialReward(){sessionStorage.removeItem("c3_adsense_initial_reward_triggered")},triggerReward(t={}){this.showReward(t)},getAds(){return this.ads}},GPT={init(t){this.config=t,this.pubId=t.pubId,this.slots=[],window.googletag||(window.googletag=window.googletag||{},window.googletag.cmd=window.googletag.cmd||[]),window.googletag.cmd.push(()=>{window.googletag.pubads().enableSingleRequest(),window.googletag.pubads().enableAsyncRendering(),window.googletag.pubads().collapseEmptyDivs(),t.pubId&&window.googletag.pubads().setPublisherProvidedId(t.pubId),t.nativeAfgSupport&&window.googletag.pubads().enableNativeAds(),t.gptConfig&&"object"==typeof t.gptConfig&&Object.keys(t.gptConfig).forEach(e=>{"function"==typeof window.googletag.pubads()[e]&&window.googletag.pubads()[e](t.gptConfig[e])})})},defineSlot(t={}){if(!this.config)throw new Error("GPT not initialized, call c3.init() first");const{adUnitPath:e,size:n,divId:i,targeting:o={},lazyLoad:r=!1,autoRefreshSeconds:s=0}=t;if(!e||!n||!i)throw new Error("adUnitPath, size and divId are required");let c,l=document.getElementById(i);l||(l=document.createElement("div"),l.id=i,document.body.appendChild(l));const u=()=>{window.googletag.cmd.push(()=>{if(c=window.googletag.defineSlot(e,n,i),!c)throw new Error("Failed to define slot");Object.keys(o).forEach(t=>{c.setTargeting(t,o[t])}),c.addService(window.googletag.pubads()),window.googletag.display(i)})};let h=null;r?h=a(l,u,{rootMargin:"50px"}):u();let w=null;s>0&&(w=d(()=>{c&&window.googletag.cmd.push(()=>{window.googletag.pubads().refresh([c])})},s));const g={slot:c,adUnitPath:e,size:n,divId:i,targeting:o,lazyLoad:r,autoRefreshSeconds:s,refreshTimer:w,observer:h};return this.slots.push(g),g},refresh(t,e={}){const n=this.slots.find(e=>e.divId===t);if(!n||!n.slot)throw new Error(`Slot not found: ${t}`);window.googletag.cmd.push(()=>{window.googletag.pubads().refresh([n.slot],e)})},preload(){this.config&&this.config.preloadAd&&window.googletag.cmd.push(()=>{})},clear(t){const e=this.slots.find(e=>e.divId===t);e&&e.slot&&window.googletag.cmd.push(()=>{window.googletag.pubads().clear([e.slot])})},remove(t){const e=this.slots.findIndex(e=>e.divId===t);if(-1!==e){const n=this.slots[e];n.refreshTimer&&c(n.refreshTimer),n.observer&&n.observer.disconnect(),n.slot&&window.googletag.cmd.push(()=>{window.googletag.destroySlots([n.slot])});const i=document.getElementById(t);i&&i.parentNode.removeChild(i),this.slots.splice(e,1)}},getSlots(){return this.slots},setTargeting(t,e){window.googletag.cmd.push(()=>{window.googletag.pubads().setTargeting(t,e)})}},AFS={init(t){this.config=t,this.searchBoxes=[]},createSearchBox(t={}){if(!this.config)throw new Error("AFS not initialized, call c3.init() first");const{containerId:e,pubId:n=this.config.pubId||"",channelId:i=this.config.channelId||"",placeholder:o="Search...",language:r="zh_CN",searchEngineId:a=""}=t;if(!e)throw new Error("containerId is required");let d=document.getElementById(e);d||(d=document.createElement("div"),d.id=e,document.body.appendChild(d));const c=document.createElement("form");c.id=`afs-search-form-${e}`,c.method="get",c.action="https://www.google.com/search";const l=document.createElement("input");l.type="text",l.name="q",l.placeholder=o,l.style.width="100%",l.style.padding="8px",l.style.fontSize="16px";const u=document.createElement("button");u.type="submit",u.textContent="Search",u.style.padding="8px 16px",u.style.marginLeft="8px";const h=document.createElement("input");h.type="hidden",h.name="cx",h.value=a||`partner-pub-${n}:${i}`;const w=document.createElement("input");w.type="hidden",w.name="ie",w.value="UTF-8",c.appendChild(l),c.appendChild(u),c.appendChild(h),c.appendChild(w),d.appendChild(c);const g=document.createElement("div");g.id=`afs-results-${e}`,g.style.marginTop="16px",d.appendChild(g),a&&s(`https://www.google.com/cse?cx=${a}`,{async:!0}).catch(t=>{});const f={containerId:e,form:c,input:l,button:u,resultsContainer:g,pubId:n,channelId:i,language:r};return this.searchBoxes.push(f),f},createSearchAd(t={}){if(!this.config)throw new Error("AFS not initialized, call c3.init() first");const{containerId:e,adSlotId:n,adFormat:i="auto",lazyLoad:o=!1,autoRefreshSeconds:r=0}=t;if(!e||!n)throw new Error("containerId and adSlotId are required");const s=document.getElementById(e);if(!s)throw new Error(`Container not found: ${e}`);const c=document.createElement("ins");c.className="adsbygoogle",c.style.display="block",c.setAttribute("data-ad-client",this.config.pubId||""),c.setAttribute("data-ad-slot",n),c.setAttribute("data-ad-format",i),c.setAttribute("data-full-width-responsive","true"),s.appendChild(c);const l=()=>{try{(window.adsbygoogle=window.adsbygoogle||[]).push({})}catch(t){}};let u=null;o?u=a(c,l,{rootMargin:"50px"}):l();let h=null;r>0&&(h=d(()=>{try{(window.adsbygoogle=window.adsbygoogle||[]).push({})}catch(t){}},r));const w={element:c,adSlotId:n,containerId:e,lazyLoad:o,autoRefreshSeconds:r,refreshTimer:h,observer:u},g=this.searchBoxes.find(t=>t.containerId===e);return g&&(g.ads||(g.ads=[]),g.ads.push(w)),w},getSearchBoxes(){return this.searchBoxes},remove(t){const e=this.searchBoxes.findIndex(e=>e.containerId===t);if(-1!==e){const n=this.searchBoxes[e];n.ads&&Array.isArray(n.ads)&&n.ads.forEach(t=>{t.refreshTimer&&c(t.refreshTimer),t.observer&&t.observer.disconnect()});const i=document.getElementById(t);i&&i.parentNode.removeChild(i),this.searchBoxes.splice(e,1)}}};let l=null,u=!1;const C3={init:function(t={}){if(u)return Promise.resolve();if(!t.platform)return Promise.reject(new Error("platform is required"));if(!t.pubId&&"afs"!==t.platform)return Promise.reject(new Error("pubId is required"));var e;switch(l={platform:t.platform,pubId:t.pubId||"",nativeAfgSupport:t.nativeAfgSupport,channelId:t.channelId||"",useGa:t.useGa||!1,useGtm:t.useGtm||!1,gaMeasurementId:t.gaMeasurementId||"",gtmContainerId:t.gtmContainerId||"",preloadAd:t.preloadAd,adsenseConfig:r({vignetteConfig:t.adsenseConfig&&t.adsenseConfig.vignetteConfig||t.vignetteConfig||{enabled:!1,vignetteToPreroll:{count:3,trigger:1},prerollToVignette:{count:1,trigger:3},maxVignetteMissed:2,initialPrerollDelay:0},rewardConfig:t.adsenseConfig&&t.adsenseConfig.rewardConfig||{name:"c3_reward",initialRewardDelay:0}},t.adsenseConfig?Object.keys(t.adsenseConfig).filter(t=>"vignetteConfig"!==t&&"rewardConfig"!==t).reduce((e,n)=>(e[n]=t.adsenseConfig[n],e),{}):{}),gptConfig:t.gptConfig||{},afsConfig:t.afsConfig||{}},l.useGa&&l.gaMeasurementId&&function(t){function e(){window.dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],window.gtag=e,e("js",new Date),s(`https://www.googletagmanager.com/gtag/js?id=${t}`,{async:!0}).then(()=>{e("config",t)}).catch(t=>{})}(l.gaMeasurementId),l.useGtm&&l.gtmContainerId&&(e=l.gtmContainerId,window.dataLayer=window.dataLayer||[],window.dataLayer.push({"gtm.start":(new Date).getTime(),event:"gtm.js"}),s(`https://www.googletagmanager.com/gtm.js?id=${e}`,{async:!0}).then(()=>{if(!document.getElementById("gtm-noscript")){const t=document.createElement("noscript");t.id="gtm-noscript";const n=document.createElement("iframe");n.src=`https://www.googletagmanager.com/ns.html?id=${e}`,n.height="0",n.width="0",n.style.display="none",n.style.visibility="hidden",t.appendChild(n),document.body.insertBefore(t,document.body.firstChild)}}).catch(t=>{})),u=!0,l.platform){case"ads":return function(){window.adsbygoogle=window.adsbygoogle||[];let t="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client="+l.pubId,e={async:!0,crossOrigin:"anonymous"};return l.nativeAfgSupport&&(t="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js",e={async:!0,hint:"10s",pubId:l.pubId}),window.adBreak=window.adConfig=function(t){window.adsbygoogle.push(t)},l.preloadAd&&window.adConfig({sound:"on",preloadAdBreaks:"on"}),s(t,e).then(()=>(AdSense.init(l),Promise.resolve())).catch(t=>Promise.reject(t))}();case"gpt":return s("https://securepubads.g.doubleclick.net/tag/js/gpt.js",{async:!0}).then(()=>new Promise(t=>{window.googletag&&window.googletag.apiReady?(GPT.init(l),l.preloadAd&&GPT.preload(),t()):(window.googletag=window.googletag||{},window.googletag.cmd=window.googletag.cmd||[],window.googletag.cmd.push(()=>{GPT.init(l),l.preloadAd&&GPT.preload(),t()}))})).catch(t=>Promise.reject(t));case"afs":return s("https://www.google.com/adsense/search/ads.js",{async:!0,crossOrigin:"anonymous"}).then(()=>(AFS.init(l),Promise.resolve())).catch(t=>Promise.reject(t));default:return Promise.reject(new Error(`Unsupported platform: ${l.platform}`))}},AdSense:AdSense,GPT:GPT,AFS:AFS,version:"1.0.14"};return"undefined"!=typeof window&&(window.c3=C3),C3});