Google Adsense Ads Rotated by Country

Tips, Tricks, How-To and complete support for Search Engine Optimisation

Moderator: Lixas

Post Reply
frisky168
Posts: 28
Joined: Sun Mar 11, 2007 11:44 am

Google Adsense Ads Rotated by Country

Post 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


Gyanu
Posts: 338
Joined: Mon Jul 30, 2007 2:03 pm
Contact:

Post by Gyanu »

yea it works.

Now cooooooooooool.
Image
Alwahsh
Posts: 292
Joined: Sat Aug 16, 2008 7:05 am

Post by Alwahsh »

Thanks for sharing that but does it work with yahoo only or google too
sobkisu
Posts: 132
Joined: Wed Nov 26, 2008 9:53 pm
Contact:

Post by sobkisu »

Thank you for your sharing, Its working
Life is only one. so don't make it complex:)
panakj

Post by panakj »

thanks a lot, great to know this
Gebbo
Posts: 554
Joined: Tue May 16, 2006 3:22 pm

google ads

Post 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.
.............................:: Spirit of Fire ::..................................

Image
ArunNayak
Posts: 62
Joined: Tue Jun 12, 2012 11:49 am

Post 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.
miketyson
Posts: 19
Joined: Wed Aug 08, 2012 12:05 pm

Post by miketyson »

Hey thank you for this valuable post. I haven't tried this but i am gonna try.
User avatar
Juniper
Posts: 17
Joined: Sat May 18, 2013 1:56 pm
Location: Purgeville
Contact:

Re: Google Adsense Ads Rotated by Country

Post 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.
Post Reply