How to add Google AdSense for Mobile to your Ruby on Rails site
In September, Google announced AdSense for Mobile, which allows the monetization of mobile sites through AdSense ads.
However, AdSense for Mobile currently only officially supports PHP, CGI, JSP, and ASP web pages, not for any deep technical reason but because Google doesn’t supply code snippets for other languages.
To address this shortcoming in the case of Rails, I’ve translated the code to create _adsense.rhtml.
To use AdSense for Mobile with your Rails site, do the following:
- Copy_adsense.rhtml into one of your view subdirectories in your Rails tree.
- Edit the value of client_id on line 8 of _adsense.rhtml to include your actual client ID. Your client ID can be copied from line 4 of the PHP script provided by Google.
- Insert this line to include the adsense partial in one of your views: <%= render :partial => "adsense" %>
- Sit back and watch the money pour in.
Note that by default Adsense for Mobile will return a HTTP 400 error if you attempt to display ads on a non-mobile browser. To bypass this check for testing purposes, you can pass in a user_agent query string parameter to pretend to be a particular mobile browser; e.g. http://example.com/controller/action?user_agent=Blackberry8800
4 Comments so far
Leave a comment
[…] Go here to read the rest: How to add Google AdSense for Mobile to your Ruby on Rails site ppc […]
By How to add Google AdSense for Mobile to your Ruby on Rails site | Advertiser Guide on 10.30.07 8:40 pm
Google Adsense Tips Blog
Just read your post and though that there is some more information in my blog related to the topic.
By Google Adsense Tips Blog on 11.17.07 12:13 pm
Dont Get Caught With Google Adsense Click Fraud
Occasionally, you will get bogged down by the titanic amount of website adsense analysis intelligence at hand.
By Dont Get Caught With Google Adsense Click Fraud on 12.02.07 12:21 am
=)thanks for code!what’s the _adsense.rhtml for non-mobile/laptop browsers?
By l on 03.20.08 5:42 pm
Leave a comment