homepage Welcome to WebmasterWorld Guest from 23.22.97.26
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Yahoo / Yahoo Publisher Contextual Advertising Network
Forum Library, Charter, Moderator: open

Yahoo Publisher Contextual Advertising Network Forum

  posting off  
Script for displaying G when visitor is international
how?
Clark




msg:1575074
 7:11 am on Nov 14, 2005 (gmt 0)

Any coders familiar w/ geocoding know how to detect where the visitor is coming from and offer them G when they aren't in the US. I bet that would upgrade CTR for Y! immediately.

 

Receptional Andy




msg:1575075
 4:43 pm on Nov 14, 2005 (gmt 0)

Detecting location is not too difficult once you have an accurate database of IPs to locations. There's lot of them about - www.maxmind.com offer a free one which they claim is 97% accurate and I've used in the past. There are some paid ones with other useful info in them.

If you have this data in mysql, for instance, it's pretty straightforward to check the IP and then use if else code to show different ads.

dzcap




msg:1575076
 4:45 pm on Nov 14, 2005 (gmt 0)

Does anyone have a tutorial on how to do this?

Receptional Andy




msg:1575077
 4:55 pm on Nov 14, 2005 (gmt 0)

If we assume that you have a mysql IP to country database that contains the location of IP ranges in long format and corresponding country codes (this seems to be fairly typical) you could use something like the below (unchecked)


<?php
// display different content to non-US visitors

// this function converts normal IP address to long format, which IP country databases tend to use
function Dot2LongIP ($IPaddr)
{
if ($IPaddr == "") {
return 0;
} else {
$ips = split ("\.", "$IPaddr");
return ($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256);
}
}

// convert the visitors IP - there are better ways of getting the IP than checking REMOTE_HOST, but this is simplest
$lookup_ip=Dot2LongIP($_SERVER[REMOTE_HOST]);

// connect to your mysql database and get country info, you would need to configure this to reflect your setup
$db = mysql_connect("localhost", "database_user", "database_pass");
mysql_select_db("ip_to_country_database",$db);
$query = "SELECT country FROM ip_to_country_table WHERE $lookup_ip BETWEEN begin_ip AND end_ip"; $result = mysql_query($query) or die (mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$country=$row['country'];

// now we know the visitor's location, so display code based on that
if ($country!="US") {

// visitor was not from the US - display alternate ads

}
else {

// visitor was from the US - display YPN ads

}
?>


Clark




msg:1575078
 6:54 pm on Nov 14, 2005 (gmt 0)

I wrote something similar last night after seeing a post giving some ranges of non-US IPs. It is much simpler. No database. Probably not that accurate but if I get 80-90% and don't need to add a database call it's worth it.

dzcap




msg:1575079
 7:19 pm on Nov 14, 2005 (gmt 0)

Can you send me a copy of that script?

Clark




msg:1575080
 7:24 pm on Nov 14, 2005 (gmt 0)

It's all embeded in my system but I'll dig it up within the next day or so and post what I got. No idea if it's effective or not.

perldiver




msg:1575081
 7:53 pm on Nov 14, 2005 (gmt 0)

Here's how I do it on my sites in perl. The IPs are from a list posted here recently.

-------------------------------------------

sub isinus{

my $isinus=1;
my $user=$ENV{REMOTE_ADDR};

$isinus=0 if $user=~/^62\./;

$isinus=0 if $user=~/^80\./;
$isinus=0 if $user=~/^81\./;
$isinus=0 if $user=~/^82\./;
$isinus=0 if $user=~/^83\./;
$isinus=0 if $user=~/^84\./;
$isinus=0 if $user=~/^85\./;
$isinus=0 if $user=~/^86\./;
$isinus=0 if $user=~/^87\./;
$isinus=0 if $user=~/^88\./;

$isinus=0 if $user=~/^193\./;
$isinus=0 if $user=~/^194\./;
$isinus=0 if $user=~/^195\./;
$isinus=0 if $user=~/^196\./;

$isinus=0 if $user=~/^200\./;
$isinus=0 if $user=~/^201\./;
$isinus=0 if $user=~/^202\./;
$isinus=0 if $user=~/^203\./;
$isinus=0 if $user=~/^212\./;
$isinus=0 if $user=~/^213\./;
$isinus=0 if $user=~/^217\./;
$isinus=0 if $user=~/^218\./;
$isinus=0 if $user=~/^219\./;
$isinus=0 if $user=~/^220\./;
$isinus=0 if $user=~/^221\./;
$isinus=0 if $user=~/^222\./;

return($isinus);
}

-------------------------------------------

Then you do something like:

routineThatShowsYPNad() if isinus();
routineThatShowsAlternateAd() if!isinus();

(note for some strange reason this system will not allow me to type "if space not-symbol something"...)

Clark




msg:1575082
 8:05 pm on Nov 14, 2005 (gmt 0)

Thanks perldiver. My code is almost identical except I pull out the first subnet and do ranges instead of one line per subnet.

How's that working for you?

perldiver




msg:1575083
 9:10 pm on Nov 14, 2005 (gmt 0)

Yes, sometimes I sacrifice "pretty" for "maintainability"...

How's it working? Dunno. I'm doing it just to be on the safe side, but I haven't put YPN on any of my big traffic sites yet so I'm still making zilch...

asp4bunnies




msg:1575084
 9:18 pm on Nov 14, 2005 (gmt 0)

I use countryhawk. Pretty innacurate though.

Clark




msg:1575085
 7:39 am on Nov 28, 2005 (gmt 0)

Is this code achievable in javascript?

Receptional Andy




msg:1575086
 9:32 am on Nov 28, 2005 (gmt 0)

I'd have to say no, because there's no way to check a visitors IP with javascript alone. The only possible method I can think of would be using something like the browsers language setting, but this would be very unreliable since many browsers run as the default.

Still, depends on what level of accuracy you need - you should be able to detect browsers with the language set to english with some level of success.

FTFlash




msg:1575087
 6:42 am on Nov 29, 2005 (gmt 0)

Doesn't PHPAdsNew have a geotargetting feature? Is anyone experimented with it? Is it good?

ksoper78




msg:1575088
 2:11 pm on Dec 3, 2005 (gmt 0)

Does anyone have thsi code in ASP?

Thanks!

garyr_h




msg:1575089
 4:43 pm on Dec 3, 2005 (gmt 0)

"Doesn't PHPAdsNew have a geotargetting feature? Is anyone experimented with it? Is it good?"

Their geotragetting feature is MaxMind. It's just integrated into the system... phpadsnew is good, it's just very hefty. Much less resources are taken if you just download the software and make your own code.

FTFlash




msg:1575090
 7:05 pm on Dec 3, 2005 (gmt 0)

I think I'll download MaxMind. Thanks for the help.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Yahoo / Yahoo Publisher Contextual Advertising Network
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved