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.
-
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 -
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. -
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
-
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>
Note: You will need to make sure that your iframe is the correct size.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
Next Lesson → SocialMedia
Comment Section for Google Adsense


David Clementsden 23 oktober 2008
Facebook-användareden 23 oktober 2008
Ken Schroederden 12 augusti 2008
David Clementsden 2 juni 2008
Thanks...
Facebook-användareden 1 juni 2008
David Clementsden 29 maj 2008
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
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
Alan Carl Brownden 24 april 2008