One of the things I think is cool about BlogCFC is that "out of the box" it tracks article views and shows that count in the administration panel. But I was bummed that each time I viewed the page it got counted. I figured it would be no big deal to add an IP Exclusion list and just not add those views. Then I noticed something peculiar. As I write this, I have no delusions about how many people are reading my words. So why did it seem that those views were going up by 2 when I viewed them?
I decided to go ahead and look at the code and put in some user-info gathering. Before I dove into the code, I created a table that stores IP, User Agent (browser), HTTP_Referrer, the internal blog ID and a date/time stamp. I know Google Analytics can track this for me, but so is more direct and if I want to change things later, I can. Data repository created, I started walking through the code. From the beginning, I knew the code had to be in or called from one of 3 files: application.cfm, index.cfm, or blog.cfc. So I started with index.cfm. It wouldn't make sense to be in application.cfm and I know the layout module is called from the index.cfm.
It took just a minute to find what I was looking for:
set views = views + 1
where id = <cfqueryparam maxlength="35" cfsqltype="CF_SQL_VARCHAR" value="#arguments.entryid#">
I quickly added a new cfquery to insert my user-information values into my awaiting table. The logView function receives the article ID as a parameter and everything else I want exists in the CGI scope. I'm thinking this is so easy! Before I get to filter my home IP out, I want to test my new feature. I save the code, open my SQL Server Management Studio and query the tables to establish a baseline so I can make sure everything is updating as it is supposed to. Since I am SO popular right now, I see what the views are for one of my articles and note that the new logging table is empty. Then I load an the article. My brilliant words appear on screen, as before. I refresh my query results and become confused. The information was logged but the number of views went up 3 and the user-info showed 3 entries. The first I recognized as my IP address, starting with '74.'. But the other 2 entries were from 126.96.36.199. That IP is not the IP of my machine nor of the server. And weirder, the user_agent is blank where the one from my machine showed a valid agent.
I tried clicking a new article and got the same result from the same IP. I spent a couple of hours walking line-by-line through things and not seeing any way that this was possible. I did a reverse IP lookup, but as I expected, it came back as owned by a major hosting service. After taking a break I thought about looking for domains that traced back to that IP. That's when the big break in this mystery came.
Thanks to www.yougetsignal.com/tools/web-sites-on-web-server I found out that 2 domains use that IP address. The first was moourl.com. So I searched the BlogCFC source code and viola! MooUrl is included as a service checked for Tweetbacks! Each time an article loads it checks for tweetbacks and I guess MooUrl does a reverse lookup for verification. I figure I can live with it so I removed MooUrl from the Tweetback service list. This immediately stopped the additional views and the additional IP entries. Now to get back to what I originally wanted: excluding my home IP Address! In blog.cfc I added the following line to the init function. Of course, even though I removed MooUrl, I also excluded that IP from logging here.
Now if I view my own article from my home PC, the view count does not increase. I also can see some real-time analytics. Still left to finalize this enhancement is a section in the admin panel to manage that exclusion list. But that can wait for now.