O'Reilly logo

Facebook Cookbook by Jay Goldman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Google AdSense and Facebook

Problem

I’m using Google AdSense on my websites to run ads, and I really like the system. Can I use it inside Facebook?

Solution

You can, but it’s a little more complicated than just dropping your AdSense code into place. Facebook’s FBJS parser won’t allow straight JavaScript through without adding all kinds of funky namespace and sandbox security to your code, which prevents Google’s insertion script from working at all.

The generally accepted technique is to embed an fb:iframe tag in your Canvas page, which will load the AdSense ads inside your Canvas. Since AdSense works by selecting ads that are relevant to the content on the page, it’s important that you create that context by passing some parameters to the page for use in the meta keywords, description, and page title:

<fb:iframe
src="http://www.someserver.com/adsense.php?title=My%20Encoded%20Title&keywords=My%2
0endcoded%20keywords&desc=My%20encoded%20desc"/>

Discussion

AdSense still pays out some of the best cost-per-click (CPC) rates around and has bigger reach than anyone else. However, it should be noted that the system isn’t tailored to social networks, so you might get more relevance running ads from something like SocialMedia or Cubics.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required