NodeBB and ads - A never ending story (Part 2)
-
When I got DFP working it was with the below code
google DFP widget ad code
google DFP widget ad code. GitHub Gist: instantly share code, notes, and snippets.
Gist (gist.github.com)
Is that no longer working?
-
Giving this a bump again (I know it was weekend, but still, just want to make sure it doesn't gets forgotten like my old thread.
Besides a general note, the issue is not just with DFP. Same happens when I use ad code from Sulvo or any other advertiser who uses document.write. In worst case the site breaks or the script as seen with blockadblock.org. Their script stops working entirely.
-
@baris before it worked though.
I know you are not Jesus (or maybe you are, at least you are a cat), but do you remember any changes which could be responsible for this?How about Ajax being the issue? Wouldn't this be the most "obvious" one or is there anything else responsible for rendering?
-
Maybe they weren't using document.write before? NodeBBs rendering engine hasn't changed for a very long time. After the initial page load, when you navigate from page to page we only grab json data from the server via ajax and update the #content element on the page client side.
-
@baris Maybe something to do with widgets?
@AOKP what is the DFP code that was working for you before? Where were you putting the DFP ad code, in HTML widgets?
As for that adsense code hack, you shouldn't need to change core files, the following should achieve the same result:
var _refreshTitle = app.refreshTitle; app.refreshTitle = function (title) { _refreshTitle(title); googletag.pubads().refresh(); };
Also, please don't bump this topic every day.
-
@PitaJ again. I inserted DFP over the Custom HTML & CSS in the Admin CP.
The code I used is the official Google one.Second, I do not use any code hack.
Third, sure the ads will reload, but I am not sure whether or not this is a violation against AdSense ToS. Without DFP this doesn't seems to be allowed actually.
Fourth, last time I didn't bumped my topic it got forgotten. And actually it is the third time that I complain about issues with NodeBB and DFP/ad providers in general.
Fifth, the only way to get it working again is to use a code hack. I did a few experiments yesterday and loaded my former Anti-AdBlock plugin over the base array of js.js (src/meta). And tada, it was working again. Unfortunately whenever I tried this for DFP ad units remained empty. However, I think DFP for jQuery might be able to work out overall.
I will report back, whether or not I will have to do any hack or if it works straight out of the Admin CP.@baris they used document.write before. This has been confirmed by a DFP official to me. Same about the Anti-AdBlock plugin. The creator gave me an older version which worked just fine before I did an upgrade. As expected it did not work.
Thanks for the interest so far, but please stop looking for the issue on DFP's or the other script providers end. All of them told me after their own investigations that the issue was on my end and after several tests and code hacks with their code it really seems to be the case.
P.S.: Yes, I use Google PageSpeed, but disabling it didn't changed a thing.
-
@AOKP I said to please not bump every day. You can bump whenever you want but please give people some time to respond.
Where are your DFP ad units located? Are they in your theme? Embedded with widgets?
Please provide the exact code you were using before DFP stopped working for you. You can of course censor anything compromising if you wish.
-
So this is the only thing that need to be included in the head (With custom header) to get reload to work when using the adsence-plugin?
var _refreshTitle = app.refreshTitle; app.refreshTitle = function (title) { _refreshTitle(title); googletag.pubads().refresh(); };
Third, sure the ads will reload, but I am not sure whether or not this is a violation against AdSense ToS. Without DFP this doesn't seems to be allowed actually.
Is there anyway to verify this?
Edit: http://stackoverflow.com/questions/30294227/reload-adsense-ads-or-have-to-use-dfp
This means that we need to solve this issue with DFP. I guess "googletag.pubads().refresh();" code is for Google DFP only. When this is solved we should make a new clean thread with all necessary information to get this working
-
-
- If we get the DFP to work, is it possible to add adds in the first post of every thread? Header and footer is solvable with widgets.
- It must be a way to skip the modify of /public/src/ajaxify.js (function renderTemplate): Is it possible to merge the change to core in a good way? What are the downsides of modifying ajaxify.js?
@AOKP Can I see your webpage, url? Nice to see how you have solved the ad placements
-
@Jenkler yes, even without DFP this is possible. I personally discourage from doing so and recommend to use an after first post ad placement.
None. No functionallity will be broken or affected by the modification. However, as @PitaJ suggested it can be done as well by a simple header code.
My NodeBB forum:
https://forum.meizufans.eu@PitaJ & @baris, this is how the recent DFP code looks like:
Header code:<script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script> <script> var googletag = googletag || {}; googletag.cmd = googletag.cmd || []; </script> <script> googletag.cmd.push(function() { googletag.defineSlot('/275425923/AdX_Footer', [[970, 250], [336, 280], [728, 90], [970, 90]], 'div-gpt-ad-1476529722718-0').addService(googletag.pubads()); googletag.defineSlot('/275425923/AdX_Footer_Mobile', [[320, 100], [300, 250], [320, 50]], 'div-gpt-ad-1476529722718-1').addService(googletag.pubads()); googletag.defineSlot('/275425923/AdX_Mid', [[336, 280], [728, 90], [970, 90]], 'div-gpt-ad-1476529722718-2').addService(googletag.pubads()); googletag.defineSlot('/275425923/AdX_Mid_Mobile', [[320, 100], [300, 250], [320, 50]], 'div-gpt-ad-1476529722718-3').addService(googletag.pubads()); googletag.defineSlot('/275425923/AdX_Post', [[336, 280], [728, 90], [970, 90]], 'div-gpt-ad-1476529722718-4').addService(googletag.pubads()); googletag.defineSlot('/275425923/AdX_Post_Mobile', [[320, 100], [300, 250], [320, 50]], 'div-gpt-ad-1476529722718-5').addService(googletag.pubads()); googletag.defineSlot('/275425923/AdX_Side', [[160, 600], [300, 250], [300, 600]], 'div-gpt-ad-1476529722718-6').addService(googletag.pubads()); googletag.defineSlot('/275425923/AdX_Top', [[336, 280], [728, 90], [970, 90]], 'div-gpt-ad-1476529722718-7').addService(googletag.pubads()); googletag.defineSlot('/275425923/AdX_Top_Mobile', [[320, 100], [320, 50]], 'div-gpt-ad-1476529722718-8').addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); googletag.pubads().collapseEmptyDivs(); googletag.enableServices(); }); </script>
Body code (ad units):
<!-- /275425923/AdX_Footer --> <div id='div-gpt-ad-1476529722718-0'> <script> googletag.cmd.push(function() { googletag.display('div-gpt-ad-1476529722718-0'); }); </script> </div> <!-- /275425923/AdX_Footer_Mobile --> <div id='div-gpt-ad-1476529722718-1'> <script> googletag.cmd.push(function() { googletag.display('div-gpt-ad-1476529722718-1'); }); </script> </div> <!-- /275425923/AdX_Mid --> <div id='div-gpt-ad-1476529722718-2'> <script> googletag.cmd.push(function() { googletag.display('div-gpt-ad-1476529722718-2'); }); </script> </div> <!-- /275425923/AdX_Mid_Mobile --> <div id='div-gpt-ad-1476529722718-3'> <script> googletag.cmd.push(function() { googletag.display('div-gpt-ad-1476529722718-3'); }); </script> </div> <!-- /275425923/AdX_Post --> <div id='div-gpt-ad-1476529722718-4'> <script> googletag.cmd.push(function() { googletag.display('div-gpt-ad-1476529722718-4'); }); </script> </div> <!-- /275425923/AdX_Post_Mobile --> <div id='div-gpt-ad-1476529722718-5'> <script> googletag.cmd.push(function() { googletag.display('div-gpt-ad-1476529722718-5'); }); </script> </div> <!-- /275425923/AdX_Side --> <div id='div-gpt-ad-1476529722718-6'> <script> googletag.cmd.push(function() { googletag.display('div-gpt-ad-1476529722718-6'); }); </script> </div> <!-- /275425923/AdX_Top --> <div id='div-gpt-ad-1476529722718-7'> <script> googletag.cmd.push(function() { googletag.display('div-gpt-ad-1476529722718-7'); }); </script> </div> <!-- /275425923/AdX_Top_Mobile --> <div id='div-gpt-ad-1476529722718-8'> <script> googletag.cmd.push(function() { googletag.display('div-gpt-ad-1476529722718-8'); }); </script> </div>
Here how the header code looks like with synchronous rendering:
<script> (function() { var useSSL = 'https:' == document.location.protocol; var src = (useSSL ? 'https:' : 'http:') + '//www.googletagservices.com/tag/js/gpt.js'; document.write('<scr' + 'ipt src="' + src + '"></scr' + 'ipt>'); })(); </script> <script> googletag.cmd.push(function() { googletag.defineSlot('/275425923/AdX_Footer', [[336, 280], [970, 90], [728, 90], [970, 250]], 'div-gpt-ad-1476529786566-0').addService(googletag.pubads()); googletag.defineSlot('/275425923/AdX_Footer_Mobile', [[320, 50], [320, 100], [300, 250]], 'div-gpt-ad-1476529786566-1').addService(googletag.pubads()); googletag.defineSlot('/275425923/AdX_Mid', [[336, 280], [970, 90], [728, 90]], 'div-gpt-ad-1476529786566-2').addService(googletag.pubads()); googletag.defineSlot('/275425923/AdX_Mid_Mobile', [[320, 50], [320, 100], [300, 250]], 'div-gpt-ad-1476529786566-3').addService(googletag.pubads()); googletag.defineSlot('/275425923/AdX_Post', [[336, 280], [970, 90], [728, 90]], 'div-gpt-ad-1476529786566-4').addService(googletag.pubads()); googletag.defineSlot('/275425923/AdX_Post_Mobile', [[320, 50], [320, 100], [300, 250]], 'div-gpt-ad-1476529786566-5').addService(googletag.pubads()); googletag.defineSlot('/275425923/AdX_Side', [[300, 600], [160, 600], [300, 250]], 'div-gpt-ad-1476529786566-6').addService(googletag.pubads()); googletag.defineSlot('/275425923/AdX_Top', [[336, 280], [970, 90], [728, 90]], 'div-gpt-ad-1476529786566-7').addService(googletag.pubads()); googletag.defineSlot('/275425923/AdX_Top_Mobile', [[320, 50], [320, 100]], 'div-gpt-ad-1476529786566-8').addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); googletag.pubads().collapseEmptyDivs(); googletag.pubads().enableSyncRendering(); googletag.enableServices(); }); </script>
Body code remains same, no matter if async or sync.
-
However, as @PitaJ suggested it can be done as well by a simple header code.
What code do you refer to? Do you mean this?
var _refreshTitle = app.refreshTitle; app.refreshTitle = function (title) { _refreshTitle(title); googletag.pubads().refresh(); };
- Can I do a "after first post ad placement." with widgets?
- Do your header + body code need additional mods to work? Extra headercode or modify of ajax file?
I will keep following this thred and when everything is solved maybe you can help me out with a working simple example I guess I need this working too Thanks!
EDIT: It seams that you site reload the whole site for every click i do. It it a temp fix?
-
@Jenkler yes the reloading you see on my site is temp as I do not want to violate AdSense ToS.
And the after first post ad cannot be done without any modification to the widgets.js. However, it is a relatively simple thing to do.
-
@AOKP the after first post ad should be able to be done by modifying your theme files.
-
@AOKP I'm looking at your forum, and it appears that your ads are inserted with widgets. I would recommend trying putting the ad elements into your theme files directly. You can make them partials and just include them in the main theme files for topics, main content, etc.
If you were trying to use DFP sync rendering inside widgets, it wouldn't work since I think widgets are loading asynchronously and inserted into the page. In fact, you should probably bake all of your DFP code into a custom theme.
-
@AOKP it could be that the widget HTML hasn't loaded in before it attempts to load the ads, so the ads fail to load.
Please try putting the DFP stuff directly in your theme.