react-dfp
Version:
A React implementation of the google [DFP](https://developers.google.com/doubleclick-gpt/reference "GPT Reference") API. This package is inspired in the awesome library [jquery.dfp](https://github.com/coop182/jquery.dfp.js), and aims to provide its same e
28 lines (24 loc) • 897 B
JavaScript
const GPT_SRC = {
standard: 'securepubads.g.doubleclick.net',
limitedAds: 'pagead2.googlesyndication.com',
};
function doloadGPTScript(resolve, reject, limitedAds) {
window.googletag = window.googletag || {};
window.googletag.cmd = window.googletag.cmd || [];
const scriptTag = document.createElement('script');
scriptTag.src = `${document.location.protocol}//${limitedAds ? GPT_SRC.limitedAds : GPT_SRC.standard}/tag/js/gpt.js`;
scriptTag.async = true;
scriptTag.type = 'text/javascript';
scriptTag.onerror = function scriptTagOnError(errs) {
reject(errs);
};
scriptTag.onload = function scriptTagOnLoad() {
resolve(window.googletag);
};
document.getElementsByTagName('head')[0].appendChild(scriptTag);
}
export function loadGPTScript(limitedAds = false) {
return new Promise((resolve, reject) => {
doloadGPTScript(resolve, reject, limitedAds);
});
}