Double Click Publisher 2 leaderboard banner in one page - javascript

Hi I try to put the 2 leaderboard in one page but its shows only one leaderboard.
This is my Header code
<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('/179670003/Leaderboard', [728, 90], 'div-gpt- ad-1363780690140-0').addService(googletag.pubads());
googletag.enableServices();
});
</script>
This is my Document Body
<!-- Leaderboard -->
<div id='div-gpt-ad-1363780690140-0' style='width:728px; height:90px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1363780690140-0'); });
</script>
</div>
<!-- Leaderboard -->
<div id='div-gpt-ad-1363780690140-0' style='width:728px; height:90px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1363780690140-0'); });
</script>
</div>
will it possible to add 2 leaderboard banner in one page?

Try creating a second ad unit called Leaderboard2. You can only display an adunit once per page. Then you could create a placement that includes both of your Leaderboard ad units and target all of your Leaderboard line items at the placement, they will then intelligently be shared between the two Leaderboard ad units.

Related

Google Publisher Tag loads synchronously despite async=true

I have some Google Publisher Tag code for an affiliate network. As far as I can tell, the code says it's supposed to load asynchronously. However, GTMetrix says that it is loading synchronously. GTMetrix also warns me of this 15 times, even though there are only 5 Google Publisher Tags.
The error message is "BA.com loads https://www.googletagservices.com/tag/js/gpt.js synchronously." As I said, this same error message is repeated 15 times.
Is there something obviously wrong here? I've included the header script for all five ads as well as the script in the widget area where just one of the ads is displayed.
//* Header Script
<!-- GPT Async -->
<script type='text/javascript'>
var gptadslots = [];
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() {
var mapping = googletag.sizeMapping().
addSize([768, 0], [728, 90]).
addSize([0, 0], [300, 250]).
build();
gptadslots[0] = googletag.defineSlot('/1019006/BA0', [[728, 90], [300, 250]], 'div-gpt-ad-1452116728891-0').defineSizeMapping(mapping).addService(googletag.pubads());
gptadslots[1] = googletag.defineSlot('/1019006/BA1', [300, 250], 'div-gpt-ad-1452116728891-1').addService(googletag.pubads());
gptadslots[2] = googletag.defineSlot('/1019006/BA2', [300, 250], 'div-gpt-ad-1452116728891-2').addService(googletag.pubads());
gptadslots[3] = googletag.defineSlot('/1019006/BA3', [300, 250], 'div-gpt-ad-1452116728891-3').addService(googletag.pubads());
gptadslots[4] = googletag.defineSlot('/1019006/BA4', [[728, 90], [300, 250]], 'div-gpt-ad-1452116728891-4').defineSizeMapping(mapping).addService(googletag.pubads());
googletag.pubads().setTargeting('blogname', ['BA']);
googletag.pubads().enableAsyncRendering();
googletag.enableServices();
});
</script>
//* Sidebar
<div class="sidebar-ad-widget"><!-- /1019006/BA1 -->
<div id="div-gpt-ad-1452116728891-1" style="height:250px; width:300px; margin:auto;">
<script type="text/javascript">
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1452116728891-1'); });
</script>
</div></div>

Use PHP to find and remove some javascript tag but leave another tag

i have html containt some googletag like this :
<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('/6176201/Opera_120x600', [120, 600], 'div-gpt-ad-6176201-opera_120x600').addService(googletag.pubads());
googletag.defineSlot('/6176201/Opera_300x250', [300, 250], 'div-gpt-ad-6176201-opera_300x250').addService(googletag.pubads());
googletag.defineSlot('/6176201/Opera_728x90', [728, 90], 'div-gpt-ad-6176201-opera_728x90').addService(googletag.pubads());
googletag.defineSlot('/6176201/Contextuals_Operaweb', [557, 30], 'div-gpt-ad-6176201-contextuals_operaweb').addService(googletag.pubads());
googletag.pubads().collapseEmptyDivs();
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-6176201-opera_728x90'); });
</script>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-6176201-opera_120x600'); });
</script>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-6176201-opera_300x250'); });
</script>
It place random in html code, i want to find and remove it but do not touch another script tag like google analytics, etc. Just do Google search and look in to a lot of answer but still don't know how to do. Please help.
Try this one regex:
/<script type='text\/javascript'(?:(?!<\/?script).\n)+?(\n*.*?)*?(googletag)(\n*.*?)*(?:(?!<\/?script>))*?<\/script>/gi
Test it online
If each of your googletag occurences have exclusive script tag, I suggest to use preg_replace with this pattern:
%<script>(.*)(googletag)(.*)</script>%
This will match any <script>...</script> tag with at least one occurence of googletag inside, and this should not touch Google Analytics code.
I changed default delimiter / to % to use slash in tag end without problem. Just use preg_replace:
preg_replace(pattern, "", $htmldoc);

When using Google Custom Search, page is blank

When I put my script code (html javascript) on my website, the page is blank and the google search bar is not there. I have set it up properly with the right website etc, but as soon as I go on the webiste it is still blank. Code:
<!DOCTYPE html>
<html>
<head>
<title>******* - ************!</title>
</head>
<body>
<div id="wrapper">
<script>
(function() {
var cx = '008901018504642689698:vb4c0smx720';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:search></gcse:search>
</div>
</body>
</html>
Please Help

Display complete Javascript tag in div

I need to place an entire javascript function in a div and show it for testing purposes, how can I accomplish this? I am doing this from code behind in asp.net
EDIT
<!-- Facebook Conversion Code for Website Purchase -->
<script type='text/javascript'>
(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement('script');
fbds.async = true;
fbds.src = '//connect.facebook.net/en_US/fbds.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(fbds, s);
_fbq.loaded = true;
}
})();
window._fbq = window._fbq || [];
</script>
Edit: You need to do some trickery: How to show <div> tag literally in <code>/<pre> tag? Which says that you need to escape your < and > characters in your tag to < and > for them to show in the <pre>. The example below has been modified to show this.
You should try using the html <pre> tag, it's commonly supported and does exactly what you're asking for:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre
<pre>
<script type="text/javascript">
console.log('hi');
</script>
</pre>
should show something like
<script type="text/javascript">
console.log('hi');
</script>

adsbygoogle.push(); 0 how to repush Google Ads

I have an Ajax site and I would like to reload the footer banner on the site each time that a user clicks a link on our website.
I thought that byy adding
adsbygoogle.push();
it would work, but all that seems to do in our ajax site is cause the page to load as normal and stop the ajax from working.
is there an issue with this function or is there another way to request new ads - and tell google the user has requested another page.
I have tried to follow https://support.google.com/dfp_sb/answer/3058726?hl=en
but the page is a bit lakelaster as it does not tell the reader where I need to place My ad code.
so this is what my page kinda looks like
<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);
})();
</script>
</head>
<body>
<!-- **Blocked ad for testing** Footer
<ins class="adsbygoogle" style="display:block;width:970px;height:250px; margin: 0 auto;" data-ad-client="ca-pub-4999865903647931" data-ad-slot="9664429631"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>-->
<div id="div-gpt-ad-1327312723268-0" style="width:728px; height:90px;">
<script type="text/javascript">
googletag.cmd.push(function() {
var slot1 = googletag.defineSlot("/9664429631/Refresh_Example", [970, 250],
"div-gpt-ad-1327312723268-0").addService(googletag.pubads());
googletag.enableServices();
googletag.display("div-gpt-ad-1327312723268-0");
setInterval(function(){googletag.pubads().refresh([slot1]);}, 30000);
});
</script>
</div>
</body>
</html>

Categories

Resources