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 » Mon Mar 12, 2007 4:51 pm

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 » Wed Sep 05, 2007 9:03 pm

yea it works.

Now cooooooooooool.
Image

Alwahsh
Posts: 292
Joined: Sat Aug 16, 2008 7:05 am

Post by Alwahsh » Sun Aug 17, 2008 8:21 am

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 » Sat Nov 29, 2008 8:26 pm

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

panakj

Post by panakj » Thu Jun 24, 2010 1:38 pm

thanks a lot, great to know this

Gebbo
Posts: 554
Joined: Tue May 16, 2006 3:22 pm
Contact:

google ads

Post by Gebbo » Tue Aug 17, 2010 11:15 pm

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 » Tue Jun 19, 2012 11:32 am

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 » Thu Aug 09, 2012 9:40 am

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 » Sun Apr 27, 2014 5:16 pm

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