NodeBB and ads - A never ending story

  • Global Moderator Plugin & Theme Dev

    Anti-AdBlock script

    No, no, no. Never use any adblock prevention measures. Make your ads unobtrusive, static, and safe. Then, simply ask your users to whitelist your site. Running a script that defeats adblocking will just piss off people.

    DFP support might not be a core functionality of NodeBB, but what else we can do?

    You can ask people for help in getting the stuff working on this forum. If a real issue is found that can be fixed, we can help resolve that issue. The reason your Github issue was closed is because at the moment, the core devs would rather focus on things like widget system overhauls and the core plugins. I believe julian wants to keep ad functionality out of core and in the plugin space, since displaying ads is a very specific and volatile scope due to the many different and changing networks. That's why adsense is accomplished with a plugin.

    I know no forum which has no ads by the way. Except the few product ones like Microsoft or Steam.

    Well you must not be looking very hard. There are tons of small forums all around which operate on sponsor money without ads.

    It will be annoying and stressful for the developers to identify the issue, but at the same time it should be rewarding as well as they know that such a fix could mean potentially more users and so a bigger reach for the project.

    I agree that working advertisements will certainly make NodeBB more attractive, but you have to understand that there are many other things which should be prioritized over that, especially when considering that some ads do work.

    Now that we've got that out of the way, answer a few questions, please, so we can help you more easily:

    1. What script did you use to use?
    2. What did it used to do?
    3. What doesn't it do now?
    4. What errors do you get in your browser or the server log?
    5. Where did you get the script?
    6. How can I reproduce this or test it myself?
  • NodeBB

    FYI at somepoint I managed to get DFP working with the below script.

    Part of it goes into the custom script part and part of it goes into a sidebar widget. You have to edit the ad ids and what not.


  • @PitaJ regular visitors do so, but what with one time visitors?
    In my use case it was absolutely the right decision and I would do it anytime again.
    Even my users support me with that decision.
    And no worries about my ad quality, I use AdX (yes I have "premium" access).

    Nonetheless I got my own solution for that now. However, I still think that the old script and DFP sync rendering not working are somehow related.

    The issue with DFP is related to something at the core and therefore should be properly investigated before it would be too much to get it working again and lets not even talk about small forums. The majority of webmasters still relies on classical banner advertisments.

    Before answering a few questions, I would also like to tag @baris. The issue is not that the ads do not show up or anything like that. Actually I even got them reloading a way it suits the Google ToS.

    1. The code which is not working is the so called synchronous rendering of ads, which is done with this function:
        googletag.pubads().enableSyncRendering();
    

    In baris example it would look like this:

    <script type='text/javascript'>
      googletag.cmd.push(function() {
        googletag.defineSlot('/80273159/nodebbtest', [160, 600], 'div-gpt-ad-1451410127852-0').addService(googletag.pubads());
        googletag.pubads().enableSingleRequest();
        googletag.pubads().enableSyncRendering();
        googletag.enableServices();
      });
    </script>
    
    1. This function does what it is named like. Synchronous ad rendering. For those who cannot imagine what it does:
      Without this function whitespaces on the site will appear and then will be filled with the ads, causing the content to be pushed down.
      On a desktop PC this is quite okay, but on a mobile device it is unacceptable.

    With this function the site will load just nicely and no content or whatsover will be "pushed" down.

    1. Unfortunately using the synchronous rendering results in the DOM structure to break, causing the forum to dissapear and just the ads to show up. It is basically like the page would only load the ads, but has no content.

    2. None. Even my Google Account Manager looked into it. Nothing was triggered at all.

    3. DFP of course.

    4. Just select to render ads synchronously and place the code on the site. Basically as @baris suggested it down below.

  • Community Rep

    Do you have ajaxify disabled? There's no way to do that currently with ajaxify enabled, due to the ad script calling document.write()


  • What exactly is not possible @yariplus? Realoding ads? If you mean that, I have to dissapoint you. They work just fine 😄

    Here a little how to for DFP users:
    Open up public/src/ajaxify.js and go to line 161 ( function renderTemplate(url, tpl_url, data, callback) { ).
    Below app.refreshTitle(data.title); add googletag.pubads().refresh(); .
    This will work just fine and complies with Google ToS.

  • Community Rep

    I apologise I am not very familiar with DFP.

    The problem you describe here: synchronous rendering results in the DOM structure to break, causing the forum to disappear and just the ads to show up. It is basically like the page would only load the ads, but has no content. is the result of a script calling document.write() after a page has loaded.

    Since ajaxify asynchronously loads the widget data, I assume something in the widget script must be calling document.write().


  • @yariplus with tags without sync rendering it works just fine though.


  • Don't know if the problem is the same, but a few years ago I did a custom ad network (because I didn't like DFP) to serve custom banners and Adsense ads. And I had a problem with document.write() too.

    The problem was solved overriding the document.write function. Kinda tricky, but worked: before loading the adsense ad, the document.write function is replaced with a custom function that inserts the content into an element, instead of writing it to the dom directly. After inserting the content, the original document.write function is restored.
    That is, a one time function replacement.

    Here is some code:

    var originalFunction = document.write;
    
    overrideDocumentWriteFunction = function(container) {
    	document.write = function(content) {
    		container.innerHTML = content;
    		document.write = originalFunction;
    	};
    };
    

    And I used it like this:

    var div = document.getElementById('adPlacement');
    overrideDocumentWriteFunction(div);
    
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.innerHTML = '{adsense script content}'
    document.body.appendChild(script);
    

    This way the document.write function was customized to ensure the Adsense script worked after the page was loaded.

    I haven't tried DFP on NodeBB but maybe this helps.

  • GNU/Linux Admin

    Ha, that's tricky 😄 Does it run afoul of their TOS?

  • Community Rep

    @julian I doubt it, since it should only be called once.

    This is a neat trick, I don't think it would work as-is with DFP though, how would you determine what content goes into what container? Page order maybe?


  • Thought it was working on the latest master. But nope...

  • Global Moderator Plugin & Theme Dev

    @AOKP so is your only problem with sync rendering?


  • @PitaJ yep. I can get ads to reload fine, the ads work as well. But without synchronous ad rendering the UX is somewhat fucked up.

Suggested Topics

  • 3
  • 1
  • 10
  • 2
  • 6
| |