We are getting some not-understandable problems with Google Doubleclick
The banners are showing and disappearing constantly.
Debug show us this:
gpt.js:49 Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
We are calling the codes separately in php , because Wordpress and the LOLS
with this function, we call the main JS
function googletag(){
$googletag = "
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function(){
//console.log('Failed to display 3rd party ad, displaying google ad instead');
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') + '//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
";
echo "\n<script>\n/* <![CDATA[ */$googletag\n/* ]]> */\n</script>\n";
}
and then the DFP elements:
<?php
function doubleclick(){
global $post;
$url = get_template_directory_uri();
$doubleclick = '';
if(is_category('11142')) {
$doubleclick .="<script src=\"$url/js/double/slot-allaccess.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('363')) {
$doubleclick .="<script src=\"$url/js/double/slot-artroom.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('11098')) {
$doubleclick .="<script src=\"$url/js/double/slot-beauty.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('360')) {
$doubleclick .="<script src=\"$url/js/double/slot-chefs.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('11096')) {
$doubleclick .="<script src=\"$url/js/double/slot-cookbook.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('365')) {
$doubleclick .="<script src=\"$url/js/double/slot-decor.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('362')) {
$doubleclick .="<script src=\"$url/js/double/slot-drinks.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('354')) {
$doubleclick .="<script src=\"$url/js/double/slot-fashion.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('357')) {
$doubleclick .="<script src=\"$url/js/double/slot-gossip.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_home() || is_front_page()) {
$doubleclick .="<script src=\"$url/js/double/slot-home.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('361')) {
$doubleclick .="<script src=\"$url/js/double/slot-hotspots.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('349')) {
$doubleclick .="<script src=\"$url/js/double/slot-jewels.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('17')) {
$doubleclick .="<script src=\"$url/js/double/slot-listen.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('364')) {
$doubleclick .="<script src=\"$url/js/double/slot-mixtape.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('11097')) {
$doubleclick .="<script src=\"$url/js/double/slot-musichall.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('356')) {
$doubleclick .="<script src=\"$url/js/double/slot-muscwatch.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('11143')) {
$doubleclick .="<script src=\"$url/js/double/slot-redcarpet.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('369')) {
$doubleclick .="<script src=\"$url/js/double/slot-scents.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('15')) {
$doubleclick .="<script src=\"$url/js/double/slot-see.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('13')) {
$doubleclick .="<script src=\"$url/js/double/slot-smell.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('368')) {
$doubleclick .="<script src=\"$url/js/double/slot-spa.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('355')) {
$doubleclick .="<script src=\"$url/js/double/slot-spotted.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('16')) {
$doubleclick .="<script src=\"$url/js/double/slot-taste.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('350')) {
$doubleclick .="<script src=\"$url/js/double/slot-tech.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('352')) {
$doubleclick .="<script src=\"$url/js/double/slot-timekeepers.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('14')) {
$doubleclick .="<script src=\"$url/js/double/slot-touch.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('351')) {
$doubleclick .="<script src=\"$url/js/double/slot-toysfb.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('353')) {
$doubleclick .="<script src=\"$url/js/double/slot-traveling.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} elseif(is_category('367')) {
$doubleclick .="<script src=\"$url/js/double/slot-wellness.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
} else {
$doubleclick .="<script src=\"$url/js/double/slot-notas.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
}
if(!empty($doubleclick)) {
$doubleclick = "\n<!-- Doubleclick Tag Script -->\n" . $doubleclick . "\n";
echo $doubleclick;
}
}
?>
And then we place one of the banners:
function top_banner(){
if ( is_home() || is_front_page()) {
echo "<!-- home_960x90a -->";
echo "<div id=\"div-gpt-ad-1427326520458-38\" style=\"width:728px; height:90px;margin:0 auto;\">\n";
echo "<script>\n/* <![CDATA[ */\n";
echo "googletag.cmd.push(function() { googletag.display('div-gpt-ad-1427326520458-38'); });\n";
echo "/* ]]> */\n</script>\n";
echo "</div>\n";
}
But nothing is working, or well is working sometimes.
Apparently the tags you are trying to load are using campaigns which are using document.write and they are loaded asynchronously. You should migrate the campaigns (you or your provider) to an async solution or to load the tags synchronously: https://support.google.com/dfp_premium/answer/1638622
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.