Adsense advertisement (inarticle) in first post

Currently I’m using the following code to add an in-article advertisement in the first and twentyfirth post and a linkunit in the second post. These are only shown to registered users, and I’ve set in Adsense that ads are only shown to about 50% of the page views (which would still be good for 99% of the revenue).

So far I had none complaints probably due to the fact that they don’t appear to on all sessions and because they are decently integrated.

However, since I use this, Google deducts a fair amount of revenue for invalid traffic/clicks. Possibly because it doesn’t like injecting Javascript as I do. Nevertheless, the revenue is still better than without the ads. And I’ve already lost 60% of ad revenue after switching from Vbulletin to Discourse :frowning:

I was wondering whether it would be possible to extend the advertising plugin with an advertising slot in the first post. I inject it after the cooked post, and I think that would be an obvious candidate, and simply adding that spot would be sufficient in my idea (although the Linkunit is also a fairly good performing unit). I wonder what happens when the unit is properly integrated with the advertising plugin, will Adsense report less invalid clicks? Only one way to find out :wink:

I ask it, because I think it would be a simple addition to the plugin, I hope that is correct and that it can become reality :wink:

<script type="text/discourse-plugin" version="0.1">

var inArticle=""; // Define AdUnits in string
inArticle += "<ins class=\"adsbygoogle\"";
inArticle += "     style=\"display:block; text-align:center;\"";
inArticle += "     data-ad-layout=\"in-article\"";
inArticle += "     data-ad-format=\"fluid\"";
inArticle += "     data-ad-client=\"ca-pub-xxxxxxx\"";
inArticle += "     data-ad-slot=\"xxxxxx\"><\/ins>";
inArticle += "<script>";
inArticle += "     (adsbygoogle = window.adsbygoogle || []).push({});";
inArticle += "<\/script>";

var linkUnit="";
linkUnit += "<!-- Discourse - Desktop & Mobile - 2nd post Link Unit -->";
linkUnit += "<ins class=\"adsbygoogle\"";
linkUnit += "     style=\"display:block\"";
linkUnit += "     data-ad-client=\"ca-pub-xxxxx\"";
linkUnit += "     data-ad-slot=\"xxxxx\"";
linkUnit += "     data-ad-format=\"link\"><\/ins>";
linkUnit += "<script>";
linkUnit += "(adsbygoogle = window.adsbygoogle || []).push({});";
linkUnit += "<\/script>";

var linkUnitPost25="";
linkUnitPost25 += "<ins class=\"adsbygoogle\"";
linkUnitPost25 += "     style=\"display:block; text-align:center;\"";
linkUnitPost25 += "     data-ad-layout=\"in-article\"";
linkUnitPost25 += "     data-ad-format=\"fluid\"";
linkUnitPost25 += "     data-ad-client=\"ca-pub-xxxxxxxx\"";
linkUnitPost25 += "     data-ad-slot=\"xxxx\"><\/ins>";
linkUnitPost25 += "<script>";
linkUnitPost25 += "     (adsbygoogle = window.adsbygoogle || []).push({});";
linkUnitPost25 += "<\/script>";

if(Discourse.User.current()== null){  // if null, the user is not logged in


        if (t.post_number === 1) {  // check if we're in post #1 
           t.cooked = t.cooked + inArticle;        // append our advertising div
        if (t.post_number === 2) { // check to see if we're in post #2
            t.cooked = t.cooked + linkUnit;
        if (t.post_number === 25 || t.post_number === 50 || t.post_number === 75){
            t.cooked = t.cooked + linkUnitPost25;


Don’t we have this @neil?

We have a few placements around posts. I’m not clear where this one goes. Is it inside a post? Can you show a mock-up?

There’s no end of places where people might want to show an ad, so we need to draw the line somewhere. Theme components are also an option.


I think the placement is in post, as most of the blogs are doing right now. It might be nice to have, but very difficult to implement nicely in all the setups. As not all post have enough text and content to make the ad look natural there

This may be an occasion where the concept of the “offset” might work, placing the ad AFTER, not inside, the first post, then on 25th, 50th, etc.

I don’t think that’s what the op is asking for.

@DoMiN8ToR if you show us what you want to achieve with a mock-up, instead of how you think it needs to be implemented we will probably be able to help figure this out.

1 Like

Sorry, I was down for most of the day upgrading my laptop with a new SSD and double the RAM, when a screw got stuck, grrrr :wink:

Attached an image of how it’s currently implemented already, due to my Javascript fiddling.

I hope the distinction between the advertisement and the post is clear. The current one is of the ‘in-article’ type and it’s one of the top performers, so it could boost revenues for many Discourse webmasters. Obviously it could also be some other type.


That ad looks too like it’s part of the posters post for my liking. I’d prefer to see some sort of separation.

1 Like

That’s why inline adverts are more effective. We’ve trained ourselves to tune out visual elements which are too jarring. Advertisers have had to adapt.

The ‘AD’ note is quite standard, not dissimilar to the way Google notates ads in search:

Either way, the ad styling is controlled by the ad code, what we’re trying to figure out here is if an outlet exists to insert adverts into this space.


The outlet I used is right after the cooked post. The advertisement I use is also a format that Google actually markets as InArticle, which would be the first post. There are also the infeed ones, I guess I could use to between nth post as well.

The same position could also be used for any other Adsense format such as responsive one, rectangle, leaderboard etc.

I was wondering if there was any update on this?

I guess a better question initially would be why your existing Javascript implementation isn’t adequate?

It looks as though you’ve said “I need a thing” and then later “this is what I’ve built already” - you’ve said Google doesn’t like the way you inject JS, but are you sure?

Usually Google objects to any ads they can’t ‘see’ themselves from their crawler processes, you told us that:

Which would support that - do you have any evidence to suggest that Google would be any happier with a different implementation?

Out of curiosity why is it only registered users see adverts? Are you trying to give users the impression they won’t be bombarded with adverts only to find out otherwise once they go to the trouble of registering?


Good questions :wink:

I don’t really have a way to test whether Google dislikes my Javascript, it’s an assumption. But it’s also not the main reason I’m asking. My own numbers show that the advertisement in the first post generates 2.5x more revenue than the other banners (I use the same Adsense Responsive Unit on all slots currently, so I can’t further distinct between locations).

The LinkUnit in the second post, which is outside the scope of this post, but might be interesting to other readers, even generates 4x more revenue.

Regarding the “only shown to registered users”, my apologies I made a mistake there, it should say, only to unregistered users (c.q. guests), this is also what the code shows (it checks whether the current Discourse user is null, and if so, it injects the Adsense code)

I’ve previously tried to understand the Discourse plugin system, but unfortunately I haven’t really had time to get Discourse up and running locally and fiddle with the code myself. With my current knowledge, and that could be totally wrong, I would think the plugin maintainer could also hook to something like the post.cooked part and add that to the plugin, but maybe it’s much harder than that.

Any updates on this In Article In Post Feature? This one feature looks good.


It’s not on our roadmap right now.


Hi, Did you find a solution ?