We get requests every once in a while to only log data from certain countries. We don’t currently offer a way to filter out traffic other than by IP address. But there is a way to do this by adding a few extra lines of javascript to your site.

The service we use for geolocation is called Maxmind. They have a free javascript file you can put on your site that includes a few functions to determine that visitors location. You can use these functions to either call our tracking code only for certain countries, or only NOT for certain countries.

Say you only want to track US visitors. In the example below is our standard tracking code, with the additional code highlighted in red to only track US visitors. We’re using [] in place of HTML tags:

[script src=”http://j.maxmind.com/app/geoip.js”][/script]
[script src=”http://static.getclicky.com/js”][/script]
if( geoip_country_code() == “US” ) clicky.init( YOUR_SITE_ID );

This can be used with any country of course, you just need to replace US with the appropriate 2-letter country code (in capital letters). You can view a list of standard 2-letter codes here.

If you want to do more than one country, say only US and Germany, you can do like this:

if( geoip_country_code() == “US” || geoip_country_code() == “DE” ) clicky.init( YOUR_SITE_ID );

You can also track all countries except the ones you specify. Say you wanted all traffic except US and Germany:

if( geoip_country_code() != “US” && geoip_country_code() != “DE” ) clicky.init( YOUR_SITE_ID );

That’s all there is to it!