[How-To] Implement Adsense Search Only ads (AFS Ads-only) on your vB 3.x Forum.
UPDATE: New Format 2/2011, jump to:
[How-To] Implement Adsense Search Only ads (AFS Ads-only)
Google Adsense has recently introduced a new ad program targeting search results pages. It is currently by invite only.
If you were lucky enough to get an invite to the private beta, this article will help you get set up as it's not 100% clear how to integrate.
https://code.google.com/apis/afs-ads-only/
Note, This article is written for vb 3.8.5. I have not tested on any other version, and do not plan to release a vb4.x version any time in the near future (as i haven't upgraded my personal sites yet). It may work on other versions, but they will not be supported in any way and the answer to any questions will simply be "I don't know" as I haven't done it
Using this new service, you will be able to implement some keyword targeted search results page ads.
I have not had this integration approved by Google. Use at your own risk of getting your account terminated. I believe it to be ok and run it on my own site, but use at your own description.
On my site, I incorporated it into the main table of the search results just under the header cell. I think this is the best placement, but you may wish to play with your template a bit.
This works based on the keywords put into the search box by the user. vB by default adds some underline and bold html markup to these words in processing, so it is necessary to clean it up.
Step 1
Make a new plugin
vB ACP -> Plugins and Products -> Add New Plugin
Product: vBulletin
Hook: search_complete
Title: "Clean up keywords to pass to adsense" (or anything you want)
Exe Order: 5
Php Code:
Active: YesCode:$displayWords_clean = str_replace('<b><u>', '', $displayWords); $displayWords_clean = str_replace('</u></b>', '', $displayWords_clean);
Save the plugin
Step 2
Edit the search_results template
find:
Add after:Code:<if condition="$displayCommon"> <tr> <td class="thead" style="font-weight: normal" colspan="$threadcolspan">$vbphrase[words_very_common]: $displayCommon</td> </tr> </if>
Of course, enter in your adsense Pub Id and you may style to fit your needs and colors of your skin. There are many more optional variables you can use to format the text and display available here:Code:<!-- begin adsense for search --> <if condition="$search['showposts']"> <!-- no ads --> <else /> <if condition="$starteronly"> <!-- no ads --> <else /> <if condition="$action == 'getnew' OR $action == 'getdaily'"> <!-- no ads --> <else /> <tr> <td colspan="$threadcolspan" class="alt1"> <script src="http://www.google.com/jsapi" type="text/javascript"></script> <script type="text/javascript" charset="utf-8"> google.load('ads', '1', {packages: ['search']}); </script> <div id="adcontainer"></div> <script type="text/javascript" charset="utf-8"> var options = { 'pubId' : 'pub-xxxxxxxxxxxxx', 'query' : '$displayWords_clean', 'container' : 'adcontainer', 'format' : 'wide', 'number' : 4 }; dynamicAd = new google.ads.search.Ad(options); </script> </td> </tr> </if> </if> </if> <!-- end adsense for search results -->
https://sites.google.com/a/google.co...nal-Parameters
A Tip, if you copy/paste anything from the google optional params page, you will have errors. The single quotes copy in as "curly quotes" instead of straight quotes, and cause JS errors, so make sure you replace all the tick marks with a fresh one in the text area of the style manager for anything you copy/paste.
The IF statement keeps the New Posts and Posts from the past 24 hours as well as "show your threads" and showing posts by member out of the keyword search, and thus out of the ads pull. You likely won't get any ads by search for "JoeQUsername" anyway, so it's best to just leave it off for these.
Known Bugs:
Advanced searches for "Unanswered" (ie, search.php?do=process&replyless=1&replylimit=0&don tcache=1) Will return a result set with a small tiny blank TD cell at the top.
There doesn't seem to be an available condition to block this from loading the widget, thus it shoves a keyword of '' (blank) into the adsense code which returns no ads. As this is not a default search param, i don't think it's a big deal and shouldn't violate any TOS to the best of my knowledge.
Also, The nested IF's are a bit bulky and can probably be better nested or combined than how I have them. The singular commands (ones that do not equal anything) don't tend to work will within an If or OR multiple conditional, so i left them on their own lines.
There also seems to be a small display bug issue with IE. I have a question in to google support awaiting feedback. It appears to be their inline iframe styling that is causing the issues.
Let me know how it does for you! Should make a quick couple bucks I think.


LinkBack URL
About LinkBacks







Reply With Quote
