Display AdSense Ads Efficiently to Maximize Revenue and Conditionally Show Alternative Ads


As a blogger, we try to provide unique and quality content. At same time, we also try to make some money from it. The first choice is AdSense, as it does pay well in all ads network. 
As AdSense only allows 3 standard ad units and 3 link units in one page, one way to try to make more money is to always show maximal allowed ads.

We are writing programming related posts at lifelongprogrammer.blogspot.com.
We show 3 standard ad units: one at one at header,one inside the post body, and one at left-sidebar,
It's easy: just add 2 Adsense widget or HTML/JavaScript widget in Layout setting, and add the ad in appropriate place in the post.

But what about the homepage, archive page, label page? 
What We Got
Adsense shows at most 3 standard ad units in order of the ads in the page. In blogspot, the order is like below: center blog post, left side bar(if any), right side bar(if any).
<div class="columns-inner">
 <div class="column-center-outer"/>
 <div class="column-left-outer"/>
 <div class="column-right-outer"/>
</div>
Adsense will always fill the first ad at header, for the remaining 2 ads, Adsense fill 2 ads in the first 2 posts, and leave blank area in left side bar.

This is not we want:
1. We want to show ads "above the fold" - where user can read without scrolling. 
Ads "above the fold" will have a better click-through rate than ads below the fold.
Place ads near where visitors eyeballs naturally go to in order to get the best CTR (top left, near titles, near site navigation, etc).
Read more at 5 Simple Adsense Layout Examples for Increasing Click Through Rates
2. Blank space in left side bar makes blog look ugly and unprofessional.
What We Want
For homepage, archive page, label page, we want Adsense always shows the 3 standard ad units above the folder: the ad at header, the ad in the first post, the ad in left side bar.
Also for other posts, in the ad slot, I want to display alternative da, for example chitika: anyway, Less is better than Nothing.

Also in the first post, we want to display one link ad unit below title, one link ad at the end of post.

With the following change, we see immediate change in Adsense revenue.  
Solution
Edit Template
We edit the template: define one variable firstAds, it's true by default, at the end of post <data:post.body/>, change its value to false.
<script src='//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'/>
<!-- define firstAds = true -->
<script>var firstAds = true;</script>
</head>

<div class='post-header'>
 <div class='post-header-line-1'/>
 <script>
 <!-- display one link ad below title if it's first post -->
 // <![CDATA[
 if(firstAds){
 document.write("<br><ins class='adsbygoogle' ></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});<\/script>");
 }
 // ]]>
 </script>
</div>
<div class='post-body entry-content' expr:id='"post-body-" + data:post.id' itemprop='articleBody'>
 <data:post.body/>
 <!-- display one link ad after the first post, and set firstAds to false -->
 <script>
 // <![CDATA[
 if(firstAds){
 document.write("<br><ins class='adsbygoogle' ></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});<\/script>");
 firstAds=false; // change its value to false
 }
 // ]]>
 </script>
Use firstAds to Conditionally Display Ad in Post
When add ad in post, we will use the firstAds variable: if it's true(means this is the first post in homepage, archive page or label page), display Adsense ad, otherwise display alternative ads.
<script>
//<![CDATA[ 
if(firstAds){
document.write("<ins class='adsbygoogle' ...></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});<\/script>")
}  else {
 // javasctipt to show alternative ads.
}
//]]>  
</script>
Resources
How To Insert Adsense Ads In Blogger Post
7 Blogger Page Types: Analysis, Code Snippets, Data Matrix
5 Simple Adsense Layout Examples for Increasing Click Through Rates

Labels

adsense (5) Algorithm (69) Algorithm Series (35) Android (7) ANT (6) bat (8) Big Data (7) Blogger (14) Bugs (6) Cache (5) Chrome (19) Code Example (29) Code Quality (7) Coding Skills (5) Database (7) Debug (16) Design (5) Dev Tips (63) Eclipse (32) Git (5) Google (33) Guava (7) How to (9) Http Client (8) IDE (7) Interview (88) J2EE (13) J2SE (49) Java (186) JavaScript (27) JSON (7) Learning code (9) Lesson Learned (6) Linux (26) Lucene-Solr (112) Mac (10) Maven (8) Network (9) Nutch2 (18) Performance (9) PowerShell (11) Problem Solving (11) Programmer Skills (6) regex (5) Scala (6) Security (9) Soft Skills (38) Spring (22) System Design (11) Testing (7) Text Mining (14) Tips (17) Tools (24) Troubleshooting (29) UIMA (9) Web Development (19) Windows (21) xml (5)