# Adsense advertisement (inarticle) in first post

**URL:** <https://meta.discourse.org/t/adsense-advertisement-inarticle-in-first-post/99720>\
**Category:** Product Support\
**Tags:** advertising\
**Created:** [17 באוקטובר,‏ 2018,‏ 12:23pm UTC](https://meta.discourse.org/t/adsense-advertisement-inarticle-in-first-post/99720 "2018-10-17T12:23:40Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![DoMiN8ToR](https://avatars.discourse-cdn.com/v4/letter/d/b2d939/32.png) [@DoMiN8ToR](https://meta.discourse.org/u/DoMiN8ToR)\
**Post date:** [17 באוקטובר,‏ 2018,‏ 12:23pm UTC](https://meta.discourse.org/t/adsense-advertisement-inarticle-in-first-post/99720/1 "2018-10-17T12:23:41Z")

</div>

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 ☹

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 😉

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 😉

```
<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

    api.addPostTransformCallback((t)=>{   

        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;
        }
        
    });
}    

</script>

```

---

_[View the full topic](https://meta.discourse.org/t/adsense-advertisement-inarticle-in-first-post/99720)._
