Refresh ads in Google DFP - google-dfp

Having DFP refresh issues when following the directions on their site.
I've tried the other method seen here: Refresh DFP ads without any luck.
Have a plugin that we created to stick ad units into widgets and it works fine. Trying to update it to refresh ads and it will not refresh anything. When I try to add the button to refresh ads manually to test it makes the ads disappear completely.
Here is the code that's in the head:
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
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);
})();
</script>
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/5251611/db_archive_leaderboard_728x90_1', [728, 90], 'div-gpt-ad-1436890018007-0').addService(googletag.pubads());
googletag.defineSlot('/5251611/db_frontpage_leaderboard_728x90_1', [728, 90], 'div-gpt-ad-1436890018007-1').addService(googletag.pubads());
googletag.defineSlot('/5251611/db_frontpage_leaderboard_728x90_2', [728, 90], 'div-gpt-ad-1436890018007-2').addService(googletag.pubads());
googletag.defineSlot('/5251611/db_frontpage_med_rect_300x250_1', [300, 250], 'div-gpt-ad-1436890018007-3').addService(googletag.pubads());
googletag.defineSlot('/5251611/db_frontpage_med_rect_300x250_2', [300, 250], 'div-gpt-ad-1436890018007-4').addService(googletag.pubads());
googletag.defineSlot('/5251611/db_frontpage_med_rect_300x250_3', [300, 250], 'div-gpt-ad-1436890018007-5').addService(googletag.pubads());
googletag.defineSlot('/5251611/db_frontpage_med_rect_300x250_4', [300, 250], 'div-gpt-ad-1436890018007-6').addService(googletag.pubads());
googletag.defineSlot('/5251611/db_frontpage_med_rect_300x250_5', [300, 250], 'div-gpt-ad-1436890018007-7').addService(googletag.pubads());
googletag.defineSlot('/5251611/db_frontpage_med_rect_300x250_6', [300, 250], 'div-gpt-ad-1436890018007-8').addService(googletag.pubads());
googletag.defineSlot('/5251611/db_frontpage_pencil_975x50', [975, 50], 'div-gpt-ad-1436890018007-9').addService(googletag.pubads());
googletag.defineSlot('/5251611/db_half_page_300x600', [300, 600], 'div-gpt-ad-1436890018007-10').addService(googletag.pubads());
googletag.defineSlot('/5251611/db_posts_leaderboard_728x90_1', [728, 90], 'div-gpt-ad-1436890018007-11').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
And this is a sample of the ad plugin code :
<!-- /5251611/db_half_page_300x600 -->
<div id='div-gpt-ad-1436890018007-10' style='height:600px; width:300px; padding:10px 0px 10px 10px;'>
<script type="text/javascript">
googletag.cmd.push(function() {
var slot10 = googletag.defineSlot("/5251611/db_half_page_300x600", [300, 600],
"div-gpt-ad-1436890018007-10").addService(googletag.pubads());
googletag.enableServices();
googletag.display("div-gpt-ad-1436890018007-10");
setInterval(function(){googletag.pubads().refresh([slot10]);}, 30000);
});
</script>
</div>
The ad code above is the same for 10 ad slots with the slot number changed in each one. What am I missing here? Cannot get it to refresh after 30 seconds.

Console is right. setInterval function does not recognize slot10 because it out of its scope. If you were to just write the following: googletag.pubads().refresh([slot10]) rather than using it in setInterval function then you will see that the ad will be refreshed.
You should make your code so that setInterval can actually access slot10. Maybe you should pass slot10 as a variable for your setInterval function??

Related

Color provinces in my country with Google charts (geocharts)

I'm trying to light up "Ha Noi" and "Ho Chi Minh" using Google Charts but it's not working by modifying the example in the document.
google.charts.load('upcoming', {'packages':['geochart']});
google.charts.setOnLoadCallback(drawRegionsMap);
function drawRegionsMap() {
var data = google.visualization.arrayToDataTable([
['Provinces', 'Popularity'],
['Hanoi', 200],
['HCM', 300],
]);
var options = {region:'VN',resolution:'provinces'};
var chart = new google.visualization.GeoChart(document.getElementById('regions_div'));
chart.draw(data, options);
}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<div id="regions_div" style="width: 900px; height: 500px;"></div>
https://jsfiddle.net/na8hvgts/
I wonder whether it's possible at all to color provinces/states outside the US.Thanks.
try using the ISO 3166-2:VN codes
see following working snippet...
also, the colorAxis will default to the min and max values in the data
leaving the min value transparent when there are only two rows
set specific colorAxis.min / colorAxis.max to avoid...
google.charts.load('upcoming', {'packages':['geochart']});
google.charts.setOnLoadCallback(drawRegionsMap);
function drawRegionsMap() {
var data = google.visualization.arrayToDataTable([
['Provinces', 'Popularity'],
[{v: 'VN-HN', f: 'Hanoi'}, 200],
[{v: 'VN-SG', f: 'HCM'}, 300],
]);
var options = {
region:'VN',
resolution:'provinces',
colorAxis: {
minValue: 0,
maxValue: 400
}
};
var chart = new google.visualization.GeoChart(document.getElementById('regions_div'));
chart.draw(data, options);
}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<div id="regions_div" style="width: 900px; height: 500px;"></div>

DoubleClick for Publishers "Ad unit did not render."

As I am completely newbie this issue will be probably an easy one for others.
My ads are not displayed on the web (various banners, multiple places, none shown).
On the www.motoraport.pl/stacje I expect 2 banners to be displayed on the right, but the slots are empty.
When debugging I get an info like
MRPrawa1
Slot size: 300x250Format: DivService: DFP
Ad unit did not fetch.
Ad unit did not render.
Ad fetch count: 1
Iframe type: none
Warnings:
Ad unit failed to fetch.
-or-
MRPrawa1
Slot size: 300x250Format: DivService: DFP
251 ms to fetch creative
Ad unit did not render.
Ad fetch count: 1
Iframe type: none
However if I click in the debug console Open Creative in New Window I see the banner images.
I thought there could have been a code mess up so I created simple localhost page
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
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);
})();
googletag.cmd.push(function() {
googletag.defineSlot('/19844765/MRPrawa1', [300, 250], 'div-gpt-ad-1450140062768-3').addService(googletag.pubads());
googletag.defineSlot('/19844765/MRPrawa2', [300, 250], 'div-gpt-ad-1450140062768-4').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.pubads().enableSyncRendering();
googletag.enableServices();
});
</script>
</head>
<body>
<!-- MRPrawa1 -->
<!-- /19844765/MRPrawa1 -->
<div id='div-gpt-ad-1450140062768-3' style='height:250px; width:300px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1450140062768-3'); });
</script>
</div>
<!-- /19844765/MRPrawa2 -->
<div id='div-gpt-ad-1450140062768-4' style='height:250px; width:300px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1450140062768-4'); });
</script>
</div>
</body>
</html>
But the problem remains. Anybody could help?
After a couple days of pissing in the wind I accidentally discovered that all ad slots that are declared in <head/> must be implemented in <body/>.
In my case there were primarily 5 slots declared in head and 1-2 used in body depending on page.
Somehow this caused that all ads came up blank.
I hope this will help others to get through embedding DFP ads.

DFP code in Chrome not working

I have problem with my DFP code in Chrome.
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
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);
})();
</script>
<div>
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/00000000/970x90_ads_block', [970, 90], 'div-gpt-ad-1390508789385-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
<!-- 970x90_ads_block -->
<div id='div-gpt-ad-0000000000000-0' style='width:970px; height:90px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-000000000000-0'); });
</script>
</div>
It works fine in Firefox and IE, but in Chrome I receive error in line 38 in www.googletagservices.com/tag/js/gpt.js
Resolved! Problem was in in AdBlock plugin in Chrome. I completely forgot about it.

How to get ads to refresh using googletag.pubads().refresh()?

I have an ad and a link in a page like so:
<!DOCTYPE html>
<head profile="http://www.w3.org/1999/xhtml/vocab">
<title>DPT - Asynchronous + Single Rest Architecture</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
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);
})();
</script>
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.pubads().enableAsyncRendering();
googletag.defineSlot('/1001256/Home_Top_Leaderboard_728x90', [728, 90], 'div-gpt-ad-1342320102476-72').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
</head>
<body>
<div id="div-gpt-ad-1342320102476-72" style="width:728px; height:90px;">
<script type="text/javascript">
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1342320102476-72'); });
</script>
</div>
<a id="refresh" href="#">Refresh ad</a>
<script type='text/javascript'>
(function ($) {
$('#refresh').click(function() {
googletag.cmd.push(googletag.pubads().refresh());
return false;
});
})(jQuery);
</script>
</body>
</html>
The first time I click the link, the ad refreshes. All other times nothing happens. Even just calling the refresh() method in Firebug etc does nothing after the first time.
What's wrong with the above?
According to https://support.google.com/dfp_premium/answer/4578089 the refresh function takes a parameter of an array of adSlots:
googletag.pubads().refresh([gptAdSlots[0], gptAdSlots[1]]);
Does that change the behaviour for you?
Failing that, I would recommend enabling the Google Publisher Console by adding the google_console or googfc parameter to your querystring (see https://support.google.com/dfp_sb/answer/181070?hl=en for details), and checking for errors
This is the source of the problem
googletag.pubads().enableSingleRequest();
Stop using singlerequest mode and you can call googletag.pubads().refresh() with no problem. Not managed to find any documentation explaining this.
Try it:
googletag.pubads().refresh(null, {changeCorrelator: false});
From https://developers.google.com/doubleclick-gpt/reference:
Fetches and displays new ads for specific or all slots on the page. Works only in asynchronous rendering mode.
For proper behavior across all browsers, calling refresh must be preceded by a call to display the ad slot. If the call to display is omitted, refresh may behave unexpectedly. If desired, the disableInitialLoad method can be used to stop display from fetching an ad.
and:
Configuration options associated with this refresh call. changeCorrelator specifies whether or not a new correlator is to be generated for fetching ads. Our ad servers maintain this correlator value briefly (currently for 30 seconds, but subject to change), such that requests with the same correlator received close together will be considered a single page view. By default a new correlator is generated for every refresh.
I hope it helped a little at least.
I can't see any answer to the issue right now. I encountered the same problem in the site I am currently working and lucky enough to accidentally solve the issue by adding $(window).load(function(){ }); in the javascript code.
You need to define slot in both the parts:
<script src='https://www.googletagservices.com/tag/js/gpt.js'></script>
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
</script>
<script>
googletag.cmd.push(function() {
slot1 = googletag.defineSlot('/xxxx/suihgdwiuhdwiu', [728, 90], 'div-gpt- ad-xxxxxxx-0').
setTargeting("test", "refresh").
addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
And:
<div id='div-gpt-ad-xxxxxxxxx-0' class="adsbygoogle">
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-xxxxxxxx-0'); });
setInterval(function(){googletag.pubads().refresh([slot1]);}, 60000);
</script>
</div>
</div>
I don't think you have got your ad unit definition quite right.
Try:
<html>
<head>
<title>DFP test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
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);
})();
</script>
<script type="text/javascript">
googletag.cmd.push(function() {
googletag.pubads().enableAsyncRendering();
googletag.defineSlot('/1234567/Home_Top_Leaderboard_728x90', [728, 90], 'div-gpt-ad-1342320102476-72').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
</head>
<body>
<div id='div-gpt-ad-1342320102476-72' style='width:728px; height:90px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1342320102476-72'); });
</script>
</div>
<a id="refresh" href="#">Refresh ad</a>
<script type='text/javascript'>
(function ($) {
$('#refresh').click(function() {
googletag.cmd.push(googletag.pubads().refresh());
return false;
});
})(jQuery);
</script>
</body>
</html>
Obviously to get this working you will need to change /1234567/Home_Top_Leaderboard_728x90 to the correct values.
For me the solution was:
googletag.pubads().updateCorrelator();
googletag.pubads().refresh();
If you want to make the ad slot are refresh perhaps may using this method,
<!-- header script -->
<script async='true' src='https://securepubads.g.doubleclick.net/tag/js/gpt.js'></script>
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
var REFRESH_KEY='refresh';
var REFRESH_VALUE='true';
</script>
<script>
googletag.cmd.push(function() {
var slot_bottomframe = googletag.defineSlot('/1001256/Home_Top_Leaderboard_728x90', [728,90], 'div-gpt-ad-1342320102476-72');
slot_leaderboard.setTargeting('pos',['leaderboard']);
slot_leaderboard.setTargeting(REFRESH_KEY,REFRESH_VALUE);
slot_leaderboard.addService(googletag.pubads());
var SECOND = 60;
googletag.pubads().addEventListener('impressionViewable',function(event) {
var slot=event.slot;
if(slot.getTargeting(REFRESH_KEY).indexOf(REFRESH_VALUE)>-1) {
setTimeout(function() {
googletag.pubads().refresh([slot]);
}, SECOND*1000);
}
});
googletag.pubads().enableSingleRequest();
googletag.pubads().collapseEmptyDivs();
googletag.enableServices();
});
</script>

google dfp pubads().refresh() not working as expected

I'm using some of the new features in Google DFP and can't get a single add to refresh on it's own. I can refresh all ads on the page but I can't get just one to refresh by itself.
I've been trying the following code to get one add to refresh without luck:
var slot1 = googletag.display('/6900315/myad2', [300, 250], 'div-2');
googletag.pubads().refresh([slot1]);
Any help would be appreciated!
Full source:
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function () {
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);
})();
</script>
script type='text/javascript'>
googletag.cmd.push(function () {
googletag.pubads().enableAsyncRendering();
googletag.defineSlot("/69003153/myad1", [728, 90], "div-1").addService (googletag.pubads());
googletag.defineSlot("/69003153/myad2", [300, 250], "div-2").addService (googletag.pubads());
googletag.enableServices();
});
</script>
<script type='text/javascript'>
function changeAd() {
googletag.cmd.push(function () {
var slot1 = googletag.display('/6900315/myad2', [300, 250], 'div-2');
googletag.pubads().refresh([slot1]);
//googletag.pubads().refresh();
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id='div-1' style='width:728px; height:90px;'>
<script type='text/javascript'>
googletag.cmd.push(function () { googletag.display('div-1'); });
</script>
</div>
<!-- BoxAdd_Details -->
<div id='div-2' style='width:300px; height:250px;'>
<script type='text/javascript'>
googletag.cmd.push(function () { googletag.display('div-2); });
</script>
</div>
<input type="button" name="test" title="test" onclick="javascript:window.changeAd();" value="Reload Ad" />
I'm also having the same problem. I haven't got my ads to refresh yet, but I should suggest that you don't need to redeclare your ad slot in changeAd().
Instead of:
googletag.cmd.push(function () {
googletag.pubads().enableAsyncRendering();
googletag.defineSlot("/69003153/myad1", [728, 90], "div-1").addService (googletag.pubads());
googletag.defineSlot("/69003153/myad2", [300, 250], "div-2").addService (googletag.pubads());
googletag.enableServices();
});
Try:
googletag.cmd.push(function () {
googletag.pubads().enableAsyncRendering();
slot1 = googletag.defineSlot("/69003153/myad1", [728, 90], "div-1").addService (googletag.pubads());
slot2 = googletag.defineSlot("/69003153/myad2", [300, 250], "div-2").addService (googletag.pubads());
googletag.enableServices();
});
Declaring them without 'var' preceding them makes the slots global in scope. In your changeAd() function, simply call
googletag.pubads().refresh([slot1]);
I'm not even sure if you need to place that inside googletag.cmd.push()
When I execute it this way, my ads still dont refresh, but running console.log(slot1) shows that the ad slot is alive and kicking...
Can anyone else help further?