YPN is still in BETA, so they are still only paying out for US traffic. A great way to show YPN ads to US visitors and other ads (such as AdSense) to foreigners is by using MaxMind.
To use MaxMind, just upload the geoip.inc and GeoIP.dat files to your server and insert the following code to the file you wish to Geo-target:
< ?
$ip = $_SERVER['REMOTE_ADDR'];
include("geoip.inc");
$gi = geoip_open(dirname(__FILE__)."/GeoIP.dat",GEOIP_STANDARD);
if (geoip_country_code_by_addr($gi, $ip) != US) {
$from = "INT";
}
else {
$from = "US";
}
geoip_close($gi);
?>
Of course, the easiest way is to create a new page called geoip.php and insert the code, then whenever you want to check if the visitor is from the US or not, call an include:
< ?
include('geoip.php');
?>
Then within the page you would have:
if ($from == 'US') {
echo 'YPN ad';
}
else {
echo 'Other advertising';
}
The reason why I didn’t stick the ad code inside the geoip.php file was because I use different formats of ads on different pages so it is easy for me to call this file, then create separate php files for each type of advertising.
In fact, I use something like this on a typical page:
index.php
<html>
<head>
</head>
<body>
<?php
include('geoip.php');
?>
content content content content
<?php
include('content-ads.php');
>
content content content
<?php
include('footer-ads.php');
>
</body>
</html>
Then within content-ads.php:
<?php
if ($from == 'US') {
$rand = mt_rand(0,1);
if ($rand == 0) {
include('ad-format1.php');
}
if ($rand == 1) {
include('ad-format2.php');
}
}
else {
$rand = mt_rand(2,3);
if ($rand == 2) {
include('ad-format3.php');
}
if ($rand == 3) {
include('ad-format4.php');
}
}
>
And then do the same thing for footer-ads.php
Written: Sep 28, 2007
0 Responses to "How to Geo-target for YPN"
No comments yet.
Sorry, the comment form is closed at this time.


















