A Simple Script to Geotarget YPN Ads
Introduction
Yahoo Publisher Network , Yahoo’s answer to AdSense, only pays for US clicks and impressions. Furthermore, they are banning publishers whose sites get too much international traffic. Therefore, if you are using YPN ads, it is absolutely critical that you target them so they display only to US visitors. Banner advertising programs often only pay well for US impresions, and show default or public
service ads for international visitors, so it is always a good idea to target your ads. Other geotargeting solutions include complicated
steps that involve installing an IP database, but there is a much simpler way to target your advertisements. I have written a PHP script that checks the visitor’s language, and serves ads accordingly. It is not 100% accurate, but it is easy to install, and, unlike an IP database, does not put a heavy load on your server.
Installation
There are two versions of the script, depending on whether you are more willing to accept false positives or false negatives. This is necessary due to the way different browsers report their language.
1. You will need to create two text files in the home directory of your server, usads.txt and otherads.txt . Paste in ad code you want to show to US visitors(ex. YPN) in usads.txt and paste in ad code you want to show international visitors(ex. AdSense) in otherads.txt .
2. Paste one of the following script versions to the place in your template where you want to insert ads. For US visitors the Safari and Opera browsers report their language only as “en”, while Firefox and Internet Explorer report it as “en-us”. The More Restrictive version of the script will only show US ads to browsers reporting “en-us”- thus, Safari and Opera visitors will only be shown International ads, regardless of location. However, you can be sure that no ads intended for US visitors are shown to international visitors. The Less Restrictive version shows US ads to any browser reporting “en”, so American users of all browsers will be shown ads intended for Americans- but so will anyone else in an English-speaking country, primarily Great Britain and Canada. Wordpress won’t let me put php code into posts, so you will need to put < ?php (without the space) at the beginning of the script and ?> (without the space) at the end.
More Restrictive:
$language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
if (substr($language,0,5)=="en-us"){
include "usads.txt";
}
else {
include "otherads.txt";
}
Less Restrictive:
$language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
if (substr($language,0,2)=="en"){
include "usads.txt";
}
else {
include "otherads.txt";
}
If you are using the WP-Cache plugin, you will need to mark the code as executable by enclosing it in –mfunc tags: put < !--mfunc-->(without the space) at the beginning and < !--/mfunc-->(without the space) at the end.
Because the ad code is included in a separate text file, and seamlessly written into the page upon execution, you are not modifying the actual ad code, and are thus fully compliant with their TOS.
Let me know if this script works for you- I have installed it on this blog to test it.
Related Posts:
What’s Yahoo’s Advertising Strategy?
Reddit hacked
Generating the Perfect Password
The Digg vs. Reddit Experiment Deconstructed
How to Read TechCrunch


Wow I did not know there even was YPN I am new to blogging and just use adsense because my site is Spanish. Does YPN do Spanish?
Thanks
Xoxana
No,YPN is only for US publishers. As you can see,I went back to AdSense anyway- YPN’s targeting is awful.
I didn’t know they were banning for international traffic. I havent gotten accepted for ypn anyway for some odd reason.
Ya thats ridiculous from YPN to bann publishers …..the best they can do is not to pay for international traffic…Thats what makes Adsense THE BEST…
I tried YPN not long after it came out. At first, it worked well. CPC was high, and the targeting was better. Now? A tech blog produces ads for mortgages, vonage, and other non-targeted ads. Like you, I went back to Adsense. I hope YPN’s issues will eventually be resolved, but I fear they’ll be in Beta until my hair turns gray.
[…] Ilya Lichtenstein of Neomeme has created a script that will only allow YPN ads to be shown to US IP addresses. This technique is also known as […]
I was recently approved for the YPN beta and was quite excited until I read the TOS. When I saw the paragraph about U.S. traffic only I scrapped the whole idea of YPN. My sites gets 65% of it’s traffic from the U.S. which means I would be throwing away 35% of my user base. Hello Yahoo WAKE UP PLEASE! The internet is a global medium and by targeting only the U.S. you’re driving away your publishers. Or maybe YPN was never meant for the masses?
Well therefore yahoo ads are limited. I know a friend who got banned few months ago because he was getting international traffic to his site. Strange but true. If they really want to have a piece of the online ad revenue they need to cater to the web not by regions.
[…] AdSense, is a steaming pile of crap, with poor targeting, excessive restrictions requiring complex workarounds, and lower payouts. But there is a much bigger market out there, one that brings in much more money […]
I was looking for something like this since long time. Are there any other paid/free programs that allow to gro-target ads?
[…] to Neomeme for providing this excellent […]
Lotensin….
Lotensin….
Thanks, I was looking for something like this. I love that YPN doesn’t use smart pricing, and I’ll probably make good use of this script.
Hello. That’s interesting. Actually, is it possible to combine More Restrictive and Less Restrictive by inserting the latter with ‘else if’ into the former?
We don’t use YPN ads. If I remember correctly, they are exclusive. So they don’t let you use other ad networks. That’s why we decided not to sign up a long time ago.
good script i have to say
Thanks for the post. YPN fancy scripts not even any better = why switch??? There’s a lot of ad companies out there. If they don’t allow any international visitors they are really shooting themselves in the foot. Like xoxana i’ve never even heard of YPN…
Thanks for the post.