dealsopoly
Power Member
- Feb 12, 2012
- 526
- 279
Hey fellow Balckhatters! Here's my first share. I'm still learning SEO and IM in general, but I'm up to 100 posts and I figured I'd share what I could to give back to this great community and learning center.
I have a website that gets a ton of traffic from US, CANADA and UK and it doesn't convert well with Adsense. I decided to go with affiliate marketing, the issue is that many affiliate programs are country specific. So I had to come up with a way to geo target my affiliate ads depending on the country.
I use wordpress, here's what I came up with so far and it does the trick for now.
INSTRUCTIONS:
-------------
1) Dowload ip2nation plugin from: http://ip2nation.com/
2) Create a PHP file with the following code: (I called it geoads.php)
3) In your WP header theme, somewhere between the head tags, put in the following
4) You can now call the DisplayAd() function anywhere in your templates to display a country specific ad. You could also install Exec-PHP plugin and call the function directly within your posts if you don't want to modify the theme templates directly.
You can create as many functions as you want just like the DisplayAd() function for different ads. Ex. I've got one for TopAd(), MiddleAd(), SidebarAd(), FooterAd(), etc...
My next goal is to set up some kind of ad rotation so it will display one of 3-4 Ads. Otherwise, the site gets pretty ordinary with the same ad showing up all the time.
Anyways, I'm in no means an expert coder, I just learn as I go along and thought this might be useful to someone. Have a great weekend all.
I have a website that gets a ton of traffic from US, CANADA and UK and it doesn't convert well with Adsense. I decided to go with affiliate marketing, the issue is that many affiliate programs are country specific. So I had to come up with a way to geo target my affiliate ads depending on the country.
I use wordpress, here's what I came up with so far and it does the trick for now.
INSTRUCTIONS:
-------------
1) Dowload ip2nation plugin from: http://ip2nation.com/
2) Create a PHP file with the following code: (I called it geoads.php)
Code:
function GetCountry()
{
$server = ''; // MySQL hostname
$username = ''; // MySQL username
$password = ''; // MySQL password
$dbname = ''; // MySQL db name
$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$sql = 'SELECT
country
FROM
ip2nation
WHERE
ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
ORDER BY
ip DESC
LIMIT 0,1';
list($country) = mysql_fetch_row(mysql_query($sql));
if($country == 'ca') //CANADA
return 1;
else if($country == 'us') //USA
return 2;
else if($country == 'uk') //UK
return 3;
else //REST OF THE WORLD
return 4;
}
function DisplayAd()
{
$country = GetCountry();
if($country == 1)
{
?>
// DISPLAY YOUR CANADA AD
<?php
}
else if($country == 2)
{
?>
// DISPLAY YOUR USA AD
<?php
}
else
{
?>
// DISPLAY AD FOR THE REST OF THE WORLD
<?php
}
}
3) In your WP header theme, somewhere between the head tags, put in the following
Code:
<?php require("geoads.php"); ?>
4) You can now call the DisplayAd() function anywhere in your templates to display a country specific ad. You could also install Exec-PHP plugin and call the function directly within your posts if you don't want to modify the theme templates directly.
You can create as many functions as you want just like the DisplayAd() function for different ads. Ex. I've got one for TopAd(), MiddleAd(), SidebarAd(), FooterAd(), etc...
My next goal is to set up some kind of ad rotation so it will display one of 3-4 Ads. Otherwise, the site gets pretty ordinary with the same ad showing up all the time.
Anyways, I'm in no means an expert coder, I just learn as I go along and thought this might be useful to someone. Have a great weekend all.