Tracking Static HTML Pages with Stats

My blog has a considerable number of pages of static HTML pages which were migrated from a previous version of the site. As these pages have their own distinct style per topic, I didn’t want to import them into my blog proper but aimed to maintain them on their own.

Since they sit outside of WordPress, how then to use Stats to track visits to them? In this post, I’ll explain what I did to achieve this goal in two simple steps.

I’m pretty much going to re-hash Jeffrey D Allen‘s post on the same subject. His post dealt specifically with tracking visits to the WordPress-generated category pages. I’m looking at tracking static HTML pages (as opposed to WordPress pages). Stats is a simply plugin which tracks all the info about visitors to that I’m interested in. It’s neither fancy nor comprehensive but what it does, it does well. The simplest explanation of what it does is that each time a visitor hits a page on your site, it runs a piece of javascript code which takes the details of the visit and tallies them with details of other visits. So, the solution to the problem is to add this piece of javascript to each static HTML page outside of WordPress that I wanted to track.

Create a Fake Pages

First, create fake pages within WordPress against which all the stats will be logged. This is a necessary evil. WordPress Stats cannot actually track visits to pages outside of WordPress so we trick it.  Fortunately, in my case, I can bundle all the legacy static HTML pages into half a dozen different categories and track hit on each category rather than on individual pages.

I suggest bundling less important pages into categories in this way and creating individual fake pages for any more important static HTML pages you want to track.

To do this, create a WordPress page and mark it as private. In this way, visitors to your site will never see it. The vital piece of information generated by this is the internal ID number of the page. You can find this by viewing the pages collection in the dashboard. Hover over the page title and the number appears in the status bar as something like ‘?p=921’. Note this down.

Edit the HTML Pages

The second step is the most tedious – editing the HTML pages to add the javascript code. On each page your want to monitor, add this code:

<script src="" type="text/javascript">
<script type="text/javascript">
st_go({blog:'yourBlogID',v:'ext',post: 'yourPageID'});
var load_cmc = function(){linktracker_init(yourBlogID, yourPageid,2);};
if ( typeof addLoadEvent != 'undefined' ) addLoadEvent(load_cmc);
else load_cmc();

Make sure that you replace yourBlogID with the ID of your blog which can be found by looking at the source code of any page on your blog (view source) and finding the code above at the bottom of the page.

Make sure you replace yourPageID with the ID of the WordPress fake page you created in step one.

That’s it. You are ready to go. Visits a couple of your static HTML pages then check that they appear in the stats.

Note: this code does not appear when you are logged in to your blog so that your visits don’t confuse the stats.