Classroom Teacher

Hide Google Ads based on Geographic Location (Country or City)

We’re thinking about starting an entrepreneurial (Make Money Online) extra-curricular computer club at school: applying critical reading, writing and thinking skills while trying our hand at online fundraising for our school.

We’ll probably start with making niche-websites that are monetized by contextual ads (i.e. Google Adsense). Google has a zero-tolerance policy when it comes to click fraud (i.e. clicking on your own ads.) And while making money online ethically will be the corner-stone of our club, it’s hard to believe that students won’t be tempted to click on the ads on their own at home.

So, we need a way to hide the google ads from showing up to students in our city so they can’t click on their own ads, but still show google ads to the rest of the world.

Background information about Google Ads for Teachers

There seem to be two types of people on the internet. People who are trying to make money online (MMO), and people who don’t. Teachers, as a general rule, fall into the second category.

Since this blog is directed towards helping teachers use classroom technology, we’ll need to spend some time going over some background information which is common knowledge to the MMO world.

Briefly, there are two parts to Google’s contextual ads: Google AdWords and Google Adsense.

1. Google AdWords

Google AdWords is for the people buying the ads. Companies (and individuals) bid on specific keywords related to their product. If they pay enough money (per click), then Google will serve up their ads, either beside the search results, or on content websites (i.e. see Google AdSense).

With AdWords, you can control where in the world your ads are served, how much you’re willing to spend on the keywords, as well as what you want the ads to say. The more people click on your ads and the more relevant your ads are to the landing page (where the visitor goes after they click on your ad), the better rates you’ll get per click.

2. Google AdSense

Many people show Google Ads on their blogs and websites as a way to make money and off-set webhosting costs. This is the Google AdSense part of the equation. Everytime a visitor clicks on a google ad, you make money. (Of course, Google doesn’t pay out until you get $100, but you get the idea.)

You can decide the size of the Google ad box, as well as where on your blog you want the ads. You can choose the colours of the ads, the type of font, the number of ads, but not the content of the ads. (There are certain restrictions imposed by Google basically to prevent you from misleading visitors into clicking the ads.)

Google’s algorithm reads your website, figures out what it’s about, and then delievers ads that Google thinks are appropriate. (It’s a computer, so sometimes it can match your website content well, and sometimes it doesn’t.)

Interestingly, Google doesn’t currently have an option to hide Google ads based on certain criteria (like IP address or the geographic location of the visitor.)

Google makes money by charging the people running the AdWords ad campaigns more than what they pay the people running AdSense on their websites. Of course, the actual formula is a trade secret and it’s against Google’s AdSense and AdWords policies to disclose specific information about clicks and the amount you have to pay, etc. So while we never know how much of a mark up Google is taking, it’s clearly a profitable model for them. (Of course, it helps that most people using Google Ads are small time and never reach the $100 minimum.)

Overall, it’s in Google’s best interest to keep click fraud to a minimum and to provide quality search traffic so the AdWords publishers will continue to advertise with them.

There are several other ad networks out there, but Google is a tier 1 search engine. You don’t want to have your Google AdSense account banned.

How to put Google Ads in your WordPress blog

There are several excellent WordPress plugins that let you place Google Ads into your WordPress blog. (Note, you can’t do this in the free version of WordPress.com. You can only do it on a self-hosted blog using the free version from WordPress.org)

AdSense Manager by Martin Fitzpatrick (now Advertising Manager) is a simple way to manage the code that Google generates and get it into your WordPress blogs. (I’m not sure if Martin is in education, but lately he’s been working on spenglr, a site to help students conduct their own learning. Hats off to him.)

We’re trying out Ozh’ Who Sees Ads WordPress plugin because it allows you to set up a list of rules that decides when your Google Ads should be displayed.

(We really would have prefered to use the No Adverts for Friends plugin by Donncha O Caoimh because it’s compatible with his WP Super Cache plugin, but we prefer the click and drag interface of Ozh’ plugin better. Ozh’ Who Sees Ads plugin doesn’t work with WP Super Cache out of the box, but when we get the chance we’ll look at Donncha’s and Thaya Kareeson’s post on adapting WordPress plugins to work with WP Super Cache.)

How to hide your Google Ads from certain countries.

Ozh’ Who Sees Ads plugin lets you display (or not display) your ads to visitors based on a number of user-defined criteria: if they come from the search engines, if they’re a regular reader (i.e. click on several posts on your site), if the post is old or new, if the ad has been displayed a certain number of time, etc.

One of the ways you could prevent students from seeing Google Ads is by setting up your ads so they are only displayed to search engine traffic (which is arguably good anyways).

If you type in the website address directly, or got referred there through a link on someone else’s site, the ads won’t display.

This might work, but students who arrive on your site by looking for it in Google will be able to see the Google ads and click on their own ads. (Even if students are given the website address directly, many of them type it into Google and then try to click on the correct website. Apparently, not everyone who is born in this digital age is actually net-savvy.)

The beauty of Ozh’ Who Sees Ads plugin, however, is that you can set up some very complex rules in the advanced mode if you know php. (Or, if you can copy in php code from the examples below.)

If you want to only show your ads to visitors from a certain country only (or if you want to hide your Google Ads from visitors from a certain country), you can install Ozh’ IP to Nation plugin as well and then use something like this:

This will display Google ads only to visitors who are from the United States. (The IP to Nation code for US, Canada, and England are ‘us’, ‘ca’, and ‘gb’ respectively.)

To block Canadian visitors, the condition would be wp_ozh_getCountryCode(0)==’ca’ and then choose, don’t display.

While this would certainly prevent your students from seeing or clicking on their own Google ads, it might also cut out a significant source of traffic and online income.

How to hide your Google Ads from certain cities or regions.

We wanted a way to block our Google ads from displaying to specific cities or provinces and not just specific countries.

The IP country data used by Ozh is free and is compiled by ip2nation but it doesn’t include city data.

MaxMind provides IP geographical data and offers both commercial and free solutions. For example, they offer GeoLite City data (for free) that is accurate for over 99.5% on a country level and 79% on a city level for the US within a 25 mile radius.

In comparison, the GeoIP city data costs $370 initially with an additional $90 for the monthly updates. With the paid version, you get over 99.8% accuracy on a country level and 83% on a city level for the US within a 25 mile radius.

For our purposes, the free GeoLite data will be fine. The geographic information contained in an IP address is actually the location of your internet service provider, and not your actual home, so student privacy shouldn’t be an issue.

You can use javascript to load geographical information about your visitors but we couldn’t get this to work with Ozh’s Who Sees Ad plugin.

We did, however, get the PHP code to work. The majority of the PHP code you need to use this data is provided by MaxMind. (The library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public. They also provide sample code to pull out the city data for a specific IP address.)

The data (in binary format) along with installation instructions can be downloaded from here.

In the end, we created a function that looks like this:

function wpip_func($type) { $dir = str_replace("", "/", dirname(__FILE__)); include_once($dir.'/geoipcity.inc'); include_once($dir.'/geoipregionvars.php'); $gi = @geoip_open($dir.'/GeoLiteCity.dat', GEOIP_STANDARD); $ip = strip_tags($_SERVER['REMOTE_ADDR']); $record = geoip_record_by_addr($gi,$ip); geoip_close($gi); if ($type == "country_code") { return $record->country_code; } elseif ($type == "country_code3") { return $record->country_code3; } elseif ($type == "country_name") { return $record->country_name; } elseif ($type == "region") { return $record->region; } elseif ($type == "city") { return $record->city; } else { return ""; }; };

While we’re not professional webdesigners, it works, and that’s good enough for us. If you know a better way to do it, please let us know.

We put the following condition into Ozh’s Who Sees Ads and all of a sudden, the ads don’t display for our city, but do display for everyone else.

We’re using the condition, wpip_func(“city”)==”YourCity” to hide google ads from being displayed to computers visitng our website in our city. But you could also use wpip_func(“region”)==”YourRegion” to hide google ads from displaying to visitors in your province or state.

Is it foolproof? Of course not. There are ways to surf the internet “anonymously” without showing your actual IP address. (That’s one of the ways we tested our plugin.)

I’m sure it’ll look very suspicious to Google if people with masked IP addresses are clicking on the ads. But surfing the net anonymously is a little harder for your average student to do.

The code above should be enough for the programmer types to tweak their websites. If you want to download our WordPress plugin that sends back the city or region geographic information for your visitor, leave a comment below and we’ll get it to you.

Have you tried to show your students how to make money online? How did it go? How did you prevent click fraud by the students?

Exit mobile version