UNPKG

@rigu/svelte-gpt

Version:

Svelte library to render google ADS using google gpt

19 lines (18 loc) 883 B
export const useAds = (networkCode, unitCode, size = [], sizeMapping = {}, containerId = 'svelte-gpt-ad-slot') => { if (typeof window !== 'undefined') { const { googletag } = window; googletag.cmd.push(function () { const adMapping = googletag.sizeMapping(); Object.keys(sizeMapping).forEach((breakpoint) => { adMapping.addSize([parseInt(breakpoint), 0], sizeMapping[breakpoint]); }); const builtMapping = adMapping.build(); const adSlot = googletag.defineSlot(`/${networkCode}/${unitCode}`, size, `${containerId}-${unitCode}`); adSlot.defineSizeMapping(builtMapping).addService(googletag.pubads()); googletag.enableServices(); }); googletag.cmd.push(function () { googletag.display(`${containerId}-${unitCode}`); }); } };