Convert IP Address to Country

One exercise that you’d like to do is find out which countries your visitors are coming from. There are several reasons for doing this:

1) You might want to tailor your content to that particular demographic.

2) If you have lots of visitors from a particular country, you might want to consider adding a version of your website in that particular language.

3) If your site has IP-based targeting for ads (programs such as Adsense have an IP-targeting component), this will help you understand why, or why not, your users are clicking on your ads.

The way I did it was to download a flat file that include IP-to-country mapping data from the link found here. This is a free database. There are other versions that claim to be more accurate, but they charge a fee. For my purposes, the free version is sufficient.

I first loaded this file into a database and then use a table join to lookup the country code from the IP number. This turned out to be a time-consuming exercise. Then, I remembered that in data warehousing, you want to do as much of your data transformation outside of the database as possible. Applying that principle, I moved the country lookup portion into the perl processing routine prior to loading the data into the database. This move proved to be an excellent time-saver.

Below I show the perl code for matching IP address with country code. There are 3 basic steps:

1. Read IP/Country mapping file.

2. Convert IP address to IP number.

3. Find country code based on IP number

The code for each step is shown below:

1. Read IP/country mapping file

open (IN1,’ip2country.txt’);
## ip2country.txt is the file that stores the
## IP number/country mapping data. Assuming the
## following format: IP_START,IP_END,COUNTRY_CODE.

$i=0;
while (<IN1>) {
chomp;
@ips = split (“,”);
$ip_start[$i] = $ips[0];
$ip_end[$i] = $ips[1];
$ip_country2[$i] = $ips[2];
$i++;
}

2. Convert IP address to IP number.

Assume IP address is already stored in the variable $ip_address

@ipp = split (/\./,$ip_address);
$ip_number = $ipp[0]*256*256*256+$ipp[1]*256*256+$ipp[2]*256+$ipp[3];

3. Find country code based on IP number

## We want to find the country code where $ip_number is between $ip_start and $ip_end.

while ($ip_number > $ip_end[$j]) {
$j++;
}
if ($ip_number > $ip_start[$j]) {
$country = $ip_country2[$j];
} else {
$country = ‘NA’;
}

Pimp My Blog in 8 Steps – Steps 7 & 8: Header Tags and Enable Auto Discovery

This post talks about the final two steps in pimping my blog.

7. Change template for header tags

You’ll want to make sure the most important elements of your blog, such as your blog title, are in the <h1> tag. Other elements, such as the date of your posting, should be de-emphasized and not be in <h1> or <h2>. For example, in the Blogger template I chose, the default tag for the blog title was <h3>, while the default tag for the date of the blog was <h2>. That was changed to make sure search engines see what’s really important.

8. Enable auto discovery

Auto discovery enables your readers one-click subscription to your blog. If your readers have an auto discovery-enabled browser such as Firefox, or use a RSS reader, they’ll see a feed icon feed icon when they visit your blog. They can then subscribe to your block by simply clicking on the feed icon.

This step simply requires adding a line of code into the template:

<link rel=”alternate” type=”application/rss+xml” title=”[your blog’s title]” href=”[your blog’s feed URL]” />

For my case, it’s <link rel=”alternate” type=”application/rss+xml” title=”TopCat Blog” href=”http://feeds.feedburner.com/TopCatBlog” mce_href=”http://feeds.feedburner.com/TopCatBlog” />.

You will want to add this line between the <head> … </head> tags. In Blogger, make sure this is above the <$BlogMetaDate$> line.

Summary

You are set! Now you should have all the ammunication you need to reach out. Just monitor your audience via Feedburner, Technorati, or your own web analytics, and keep blogging.

Pimp My Blog in 8 Steps: Steps 5 & 6 – Make it easy to bookmark/share and subscribe

This post talks about steps 5 and 6 in pimping my blog.

5. Add del.icio.us, digg, and reddit links for people to easily bookmark and share your blog

Bookmarking and bookmark sharing services allow users to keep their bookmarks on the web, as well as sharing these bookmarks with their community. As such, it is very important for a blog to make it as easy as possible for readers to accomplish such tasks. I’ve implemented links to del.icio.us, digg, and reddit for my blog.

This step is usually accomplished by modifying the template for your blog. Because you’ll want to bookmark individual posts in addition to the entire blog, it is necessary to use variables within the template to indicate what the title of each post is, as well as what is the URL for each post (called permalink). Below is the code I used for Blogger:

del.icio.us: <a href=”http://del.icio.us/post?url=<$BlogItemPermalinkUrl$>&title=<$BlogItemTitle$>” mce_href=”http://del.icio.us/post?url=<$BlogItemPermalinkUrl$>&title=<$BlogItemTitle$>” target=delicious title=”Bookmark <$BlogItemTitle$> to del.icio.us”>add to del.icio.us</a>

digg: <a href=”http://www.digg.com/submit?url=<$BlogItemPermalinkUrl$>&phase=2″ mce_href=”http://www.digg.com/submit?url=<$BlogItemPermalinkUrl$>&phase=2″Â target=digg title=”Submit <$BlogItemTitle$> to digg”>digg it</a>

reddit: <a href=”http://www.reddit.com/submit?url=<$BlogItemPermalinkUrl$>&title=<$BlogItemTitle$>” mce_href=”http://www.reddit.com/submit?url=<$BlogItemPermalinkUrl$>&title=<$BlogItemTitle$>” target=reddit title=”Submit <$BlogItemTitle$> to reddit”>reddit</a>

In the above Blogger example, The variable meanings are:

<$BlogItemPermalinkUrl$>: The URL of the individual posting.
<$BlogItemTitle$>: The title of the individual posting.

6. Make it easy for people to subscribe

As you can see under the Subscribe: heading in the left-hand panel, I have added the ability to subscribe from a variety of sources. Below I include the code that I added to my template for them (you’ll want to replace http://feeds.feedburner.com/TopCatBlog with your own feed):

My Yahoo:
<a href=”http://add.my.yahoo.com/rss?url=http://feeds.feedburner.com/TopCatBlog” mce_href=”http://add.my.yahoo.com/rss?url=http://feeds.feedburner.com/TopCatBlog” >
<img src=”http://us.i1.yimg.com/us.yimg.com/i/us/
my/addtomyyahoo4.gif” border=”0″ alt=”Add to My Yahoo” />
</a>

Google:
<a href=”http://fusion.google.com/add?feedurl=http://feeds.feedburner.com/TopCatBlog” mce_href=”http://fusion.google.com/add?feedurl=http://feeds.feedburner.com/TopCatBlog” >
<img src=”http://buttons.googlesyndication.com/fusion/add.gif” mce_src=”http://buttons.googlesyndication.com/fusion/add.gif” width=”104″ height=”17″ border=”0″ alt=”Add to Google”>
</a>

Bloglines:
<a href=”http://www.bloglines.com/sub/
http://feeds.feedburner.com/TopCatBlog”> <img src=”http://www.bloglines.com/images/sub_modern8.gif” mce_src=”http://www.bloglines.com/images/sub_modern8.gif” border=”0″ alt=”Subscribe with Bloglines” />
</a>

Netvibes:
<a href=”http://www.netvibes.com/subscribe.php?url=http://feeds.feedburner.com/TopCatBlog” mce_href=”http://www.netvibes.com/subscribe.php?url=http://feeds.feedburner.com/TopCatBlog” >
<img src=”http://eco.netvibes.com/img/add2netvibes.png” mce_src=”http://eco.netvibes.com/img/add2netvibes.png” width=”91″ height=”17″ border=”0″ alt=”Add to netvibes”>
</a>

Pluck:
<a href=”http://client.pluck.com/pluckit/prompt.aspx?GCID=C12286x053&a=http://feeds.feedburner.com/TopCatBlog
&t=TopCat+Blog”><img src=”http://www.pluck.com/images/pluck/pluspluck.png” mce_src=”http://www.pluck.com/images/pluck/pluspluck.png” alt=”Subscribe with Pluck RSS reader” border=”0″ /></a>

My AOL:
<a href=”http://feeds.my.aol.com/add.jsp?url=http://feeds.feedburner.com/TopCatBlog” mce_href=”http://feeds.my.aol.com/add.jsp?url=http://feeds.feedburner.com/TopCatBlog” ><img src=”http://o.aolcdn.com/myfeeds/vis/myaol_cta1.gif” mce_src=”http://o.aolcdn.com/myfeeds/vis/myaol_cta1.gif” alt=”Add to My AOL” border=”0″ /></a>

My MSN:
<a href=”http://my.msn.com/addtomymsn.armx?id=rss&ut=http://feeds.feedburner.com/TopCatBlog&
ru=http://www.1keydata.com/blog”><img src=”addtomymsn.gif” mce_src=”addtomymsn.gif” border=0 /></a>
(the image can be retrieved from http://rss.msn.com/publisher.armx)

You can also host the images on your own site. I recommend doing this to ensure that your page load time is fast.

Pimp My Blog In 8 Steps: Steps 3 & 4 – Sign Up For Feedburner and Technorati

This post talks about the next two steps in pimping my blog.

3. Sign up for Feedburner

Feedburner is a feed management service. Since all blog software already provide a feed, you might wonder why you would want to sign up for a separate feed management service provider. There are several reasons:

1) Tracking: Feedburner tells you how many subscribers your feed has, via which service they are subscribing from, as well as how many hits your feed has received. You can also upgrade to TotalStats Pro to view even more metrics about your feed.

2) Optimizing: Feedburner can add a footer at the bottom of each content item, allowing your readers to easily “email this item” or “add to del.icio.us”, among other capabilities. Another service is called “Link Spicer”, which can retrieve the bookmarks you have set in services such as del.icio.us and Furl, and include them as part of your feed.

3) Publicizing: Feedburner can help you ping the most important services automatically when you publish new content. In addition, feed content can be published as regular HTML. There are several other gadgets that would allow you to promote your feed on a web page.

4) Monetizing: Once you reach a certain threshold, Feedburner can start putting ads in your feed, allowing you to monetize your blog content.

Setting up with Feedburner is easy. First, you enter the blog or feed address, then you provide a feed title and specify what feed address you want to use (this will be in the form of http://feeds.feedburner.com/[YourBlogName]). That’s it. Then going forward, you can start using your Feedburner feed as your regular feed to the world.

4. Sign up to Technorati

Technorati is a blog search engine. Upon creating your account, you’ll want to claim your blog in Technorati. To do so, you’ll be required to authenticate that you are the owner of the blog — Technorati offers 2 ways of doing this: you can either insert a special link to your Technorati profile in a new post, or add a short javascript code to your template. If you use this method, you’ll have the option to display certain Technorati links on your blog.

Claiming your blog allows you to get link counts, add your profile/branding to your blog, and set up tags for your blog. In your posts, you can also put in Technorati tags (examples are at the bottom of this post). This allows you to tell Technorati about tags for each one of your posts, in addition to tags about your blog in general.

As a side note, you cannot claim a feed in Technorati, as Technorati has no way of verifying you are the feed owner. So, for those of you who have set up a feed in Feedburner, you’ll need to give Technorati your blog URL rather than the Feedburner feed code.

Pimp My Blog In 8 Steps: Steps 1 & 2 – Domain Name and Blog Software

This post talks about the first two steps in pimping my blog.

1. Decide what domain name to use

For domain names, the easiest solution is to use the domain name of your blogging host. An example of this is myblog.blogspot.com (for Blogger). For someone who is a casual blogger, this is probably the way to go. However, if you are serious about generating traffic to your blog, you should consider using a separate domain for your blog. SEOmoz has a good discussion on this topic. In that article, they recommend the following order (from least recommended to most recommended):

1. Using the domain name of your domain host.
2. Use your own domain name (but not your main domain name).
3. Set up a subdomain for your main domain name.
4. Set up the blog as a directory of your main domain.

I went with the advice offered in this article and set up my blog at www.1keydata.com/blog. I decided to go with my own domain name at http://www.topcatblog.com.

2. Decide on a blogging software / host

Next is to determine what blogging software to use. The most prominent ones are Movable Type, Word Press, Blogger, and Typepad. Each one has its strengths and weaknesses. Some of the solutions allow you to download and do your own hosting. Two of them, Movable Type and Word Press, both have a number of plugins, which allow the blogger to add some bells and whistles to their posts. I decided at the end to go with Blogger, because that’s the host I am already using, and it appears that moving hosts would not be worth the trouble for my blog.

The next task is to point my Blogger account to my main domain. Dave Taylor had an excellent tutorial on how to use a custom domain with a Blogger account for those who are currently using Blogger. The process was not as straightforward as I hoped, and it did take me a bit of time to get it to work right. But don’t skip out on this step, as it is definitely worth the trouble down the road.

Pimp My Blog in 8 Steps

Blogging is fun, and you obviously want others to read your blogs (otherwise you wouldn’t want to make it public, would you?) But in the vast worldwide web, how do you get other people to even know that your blog exists? This is the question I faced when I started looking into blogging recently. In this post, as well as the next few posts, I will discuss all the things I did to pimp my blog.

At the high level, my goals are as follows:

  • Easy feed management.
  • Make it easy for people to subscribe.
  • Make it easy for people to bookmark / tag.
  • Account for all SEO best practices for a regular web site.Below are the 8 steps for pimping my blog:

    1. Decide what domain name to use.

    2. Decide on a blogging software / host.

    3. Sign up for Feedburner.

    4. Sign up for Technorati.

    5. Make it easy for people to bookmark and share.

    6. Make it easy for people to subscribe.

    7. Change template for header tags.

    8. Enable auto discovery.

    In the next few posts, I will discuss each step in detail. By reading through this series, you’ll be able to get the world to notice and start reading your blog as well.

  • Summary: Firefox extensions for SEO

    After reviewing the 5 Firefox extensions for SEO, we find that there are basically two different categories of extensions: 1) one that adds SEO-related information to search results, and 2) one that shows SEO metrics for the page you are currently on. Extensions built by SEO Book and SEO Quake fall under the first category, and extensions built by Rank Quest, SearchStatus, and SEOpen fall under the second category.

    Because the two categories of extensions are very different (first category is for people doing serious SEO research, second one is for people who are interested in the site they are looking at), I decided I will recommend one extension from each category:

    Category 1: Adding SEO-related information to search results

    I think both tools are excellent, as evident from both getting a total score of 25. SEO Book’s information on query terms is countered by SEO Quake’s ability to show information on the page you are visiting. At the end, the difference was that I just did not like SEO Quake’s display under the sponsored search section in the search results pages. Therefore, I will go with SEO Book’s tool.

    Category 2: Showing SEO metrics for the pages you are currently on

    For this category, the winner is SearchStatus. The fact that it shows the information at the status bar at the bottom of Firefox rather than eating up real estate by showing a toolbar is the differentiating factor.

    Summary

    I recommend that people use the extension from SEO Book for serious SEO research, and the extension from SearchStatus for getting SEO information for a particular site.

    SEOpen Firefox Extension

    Today let’s take a look at the SEOpen Firefox extension. This extension can be downloaded from https://addons.mozilla.org/firefox/570/. This extension adds a toolbar on Firefox, from where you can view SEO-related information from Google, Yahoo!, MSN, Alexa, and several other resources on the page you are at.

    Below is a screenshot of what the extension looks like when clicking on “Other Tools”.

    seopen  Â

    Below is the score for each category:

    Ease of installation: 5
    Ease of use: 3
    Amount of time for the information to appear: 4
    Usefulness of information presented: 3
    Amount of real estate taken up: 3
    Documentation: 3
    Total: 21

    Ease of installation: Installation was quick and problem free.

    Ease of use: There was a problem with one of the links (page size, which returned a 404).

    Amount of time for the information to appear: It takes two clicks to get to the desired information. Once the metrics are selected, though, information does appear quickly.

    Usefulness of information presented: Good for getting info on the page you are on. A minus is that it shows backlinks info from Google, and it is known that the link: command in Google returns incorrect numbers.

    Amount of real estate taken up: An additional toolbar appears on the browser.

    Documentation: Adequate documentation is available at http://seopen.com/firefox-extension/index.php.

    Wish List

    Make sure all links are valid.

    Take out information that is known to be highly inaccurate (such as backlinks from Google).