Fbtt Facebooker Tutorial

Next Lesson → SocialMedia

4.1) Google Adsense


This lesson explains how to integrate Google ads into your site.
As you can see here the tutorial application uses Google adsense in the layout below. Google ads are typically very straight forward however when integrated into Facebook you will need to create and iframe for the ad unit. Some people are concerned that Google won't be able to provide context relevant ads, I have done this type integration on another Facebook app and it appears to work just fine and within about 20 minutes of a page being created the ads becomes relevant to the content.

  1. Sign up for Google Adsense and configure an ad form your site. Get ready with the Adsense code to paste into your application.
    Note: Google will require that your site is up and running before they will give you an adsense account
  2. Now create a controller that will serve up your google ads. This is necessary because our ad will be served through an iframe.
    ruby script/generate controller ads.
  3. Create an action on your 'ads' controller called adsense and have it render you adsense code directly.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    
    #File: app/controllers/ads_controller.rb Method: adsense
    def adsense
      
      advert =      '<script type="text/javascript"><!--
         google_ad_client = "pub-6979873404821820";
         /* 468x60, created 4/17/08 */
         google_ad_slot = "9553164414";
         google_ad_width = 468;
         google_ad_height = 60;
         //-->
         </script>
         <script type="text/javascript"
           src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
          </script>'
       
      render :text => "<html> <body> #{advert} </body> </html>"
    end
    
    
  4. Render an iframe anywhere you like for your ad.
    1
    2
    3
    4
    
    #File: app/views/layouts/application.fbml.erb
    <div id="adspace">
            <%= google_ad()%>
     </div>
    
    1
    2
    3
    4
    5
    6
    7
    
    #File: app/helpers/application_helper.rb Method: google_ad
    def google_ad
      content_tag("fb:iframe",nil ,  :scrolling => "no", :frameborder => 0 , 
        :width => 500, :height => 64, 
        :src => url_for(:controller => "ads", :action => "adsense", 
                   :canvas => false, :only_path => false))   
    end
    
    Note: You will need to make sure that your iframe is the correct size.
Next Lesson → SocialMedia
Peepcodead
Comment Section for Google Adsense

Säkerhetskontroll

Skriv in båda orden nedanför, avgränsade med ett mellanrum.
Kan du inte läsa orden här nedanför? Pröva olika ord eller en ljud-captcha.
Laddar ...

David Clementsden 23 oktober 2008

This is allowed. Canvas pages are yours to do what you want. This is the only way currently to monetize your application.
 

Facebook-användareden 23 oktober 2008

is this allowed ? can i put google ads on ? by doing it am i violating facebooks TOS
 

Ken Schroederden 12 augusti 2008

Any tips on getting resizable Iframe to work? The social media section is straight foward but I have the resizeable iframe issue. I've read the facebook wiki on the topic but can't get it to work I feel I'm missing something but can't figure out what. Are you using FB.CanvasClient.startTimerToSizeToContent if so where in retorspect to your <%= social_media_ad %> any examples you have woudl be welcome.
 

David Clementsden 2 juni 2008

If you are up for it message me directly, perhaps your ways is easier to understand and I can change this page.

Thanks...
 

Facebook-användareden 1 juni 2008

It's still a little confusing. Thanks anyway. I'll just do it the way I am currently doing it but just plugging the code into an iframe.
 

David Clementsden 29 maj 2008

Yeah, the tutorial assumes a basic understanding of Ruby on Rails. The controller piece is the beginning of the request cycle for you application. In this case there are two pieces of rendering code.

The First is where you render the Iframe, this takes the URL of the Iframe Content.

The second is the Iframe content itself, in this case a block of google adsense code.

Does that make sense?
 

Facebook-användareden 29 maj 2008

Thank you for providing this page which helps with adding adsense to applications but being a novice at creating these applications I am confused about a few things:

I am assuming that the controller is a separate file with the code for the ad.

I am confused about why there are two segments of code for rendering the iframe and where each of them go.
 

David Clementsden 24 april 2008

Thanks Alan, that code come directly from the file system. Must be a problem with my parsing of the ruby method, I'll fix it.
 

Alan Carl Brownden 24 april 2008

slight typo in closing tag of ApplicationHelper.google_ad.
 
Visar alla 9 inlägg