Page 1 of 1

Google Adsense Ads Rotated by Country

Posted: Mon Mar 12, 2007 4:51 pm
by frisky168
redit goes to some one scripttutorial.com

Google Adsense and YPN (Yahoo Publisher Network) Ads Rotated by Country


I have never liked using IP addresses to sort ads mainly because of the wasted space (Not to mention the Countless people using Proxy's) So I created a simple script to rotate my ads Based on Language and Country.

By now anyone using YPN (Yahoo Publisher Network) knows they only pay for US Traffic - and you can lose a good bit of income by using their ads alone.

So you could include in your Header , Footer , or Body the files named for the size and type ads you want shown :



Code :



Code:
<?php
include("728x90.php");
?>





For this Example - I've created a file named 728x90.php



Code for 728x90.php :



<?php

$locales = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
if ( $locales == "" ) {
include("google-728x90.php");
} else {
$semicolon = array(";");
$lesssemicolon = str_replace($semicolon, ",", "$locales");
$breakdown = explode(",",$lesssemicolon);
$lang_count = strtolower("$breakdown[0]");
}
if ( $lang_count == "en-us" ) {
include("ypn-728x90.php");
} else {
include("google-728x90.php");
}

?>

The reason for the "$lesssemicolon" is due to the fact Locales may be separated by either semi-colons or commas.

Of Course you would have to create mini php pages named "ypn-728x90.php and google-728x90.php" which simply contain your ad code(s) - Depending on size and type of ad programs you use.

The only problems I've seen so far with this method - Is that a lot of FireFox / Opera users have never set their location on their browser , But it doesn't bother me too much seeing the Script will still show Google ads to anyone not in the US or with no locale set.

This might actually be a good thing seeing you'll still be giving Google some US traffic as well - Thus not making them upset at you for sending them only non-US or Foreign Web Traffic.



Hope it Helps

Posted: Wed Sep 05, 2007 9:03 pm
by Gyanu
yea it works.

Now cooooooooooool.

Posted: Sun Aug 17, 2008 8:21 am
by Alwahsh
Thanks for sharing that but does it work with yahoo only or google too

Posted: Sat Nov 29, 2008 8:26 pm
by sobkisu
Thank you for your sharing, Its working

Posted: Thu Jun 24, 2010 1:38 pm
by panakj
thanks a lot, great to know this

google ads

Posted: Tue Aug 17, 2010 11:15 pm
by Gebbo
frisky168 wrote:redit goes to some one scripttutorial.com

Google Adsense and YPN (Yahoo Publisher Network) Ads Rotated by Country


I have never liked using IP addresses to sort ads mainly because of the wasted space (Not to mention the Countless people using Proxy's) So I created a simple script to rotate my ads Based on Language and Country.

By now anyone using YPN (Yahoo Publisher Network) knows they only pay for US Traffic - and you can lose a good bit of income by using their ads alone.

So you could include in your Header , Footer , or Body the files named for the size and type ads you want shown :



Code :



Code:
<?php
include("728x90.php");
?>





For this Example - I've created a file named 728x90.php



Code for 728x90.php :



<?php

$locales = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
if ( $locales == "" ) {
include("google-728x90.php");
} else {
$semicolon = array(";");
$lesssemicolon = str_replace($semicolon, ",", "$locales");
$breakdown = explode(",",$lesssemicolon);
$lang_count = strtolower("$breakdown[0]");
}
if ( $lang_count == "en-us" ) {
include("ypn-728x90.php");
} else {
include("google-728x90.php");
}

?>

The reason for the "$lesssemicolon" is due to the fact Locales may be separated by either semi-colons or commas.

Of Course you would have to create mini php pages named "ypn-728x90.php and google-728x90.php" which simply contain your ad code(s) - Depending on size and type of ad programs you use.

The only problems I've seen so far with this method - Is that a lot of FireFox / Opera users have never set their location on their browser , But it doesn't bother me too much seeing the Script will still show Google ads to anyone not in the US or with no locale set.

This might actually be a good thing seeing you'll still be giving Google some US traffic as well - Thus not making them upset at you for sending them only non-US or Foreign Web Traffic.



Hope it Helps
Intertesting.. thanks for that will keep it in mind.

Posted: Tue Jun 19, 2012 11:32 am
by ArunNayak
Actually this will be something of a guide on how a site using Online Systems as the primary resource of income and other promotion resources to circular things off can set up Search engines Ad Administrator to make sure the Online ads are given the most important.

Posted: Thu Aug 09, 2012 9:40 am
by miketyson
Hey thank you for this valuable post. I haven't tried this but i am gonna try.

Re: Google Adsense Ads Rotated by Country

Posted: Sun Apr 27, 2014 5:16 pm
by Juniper
You could advance this to use the browser locate function from html5 so that it picks up their location (not based on browser, but based on where they currently are). That way if someone travels to another country, it takes it from their geo-cordinated position and not what they have set on the computer - like if a US person goes to the UK, it would say they're in UK, while doing it this way (the way the code is now) it would say the person is US which is false.