Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I add an invisible hit counter to a site?

Status
Not open for further replies.

pommoz

Programmer
Nov 12, 2002
3
AU
I want to add a hitcounter (in the background) to every page with information about the user ie ip address, browser etc. I am sure I can do this with the application.cfm and <cflock> but am a little unsure. The information I gain from this I want to add to 2 databases. The first will show hits to individual pages on a daily basis. The second will show types of users and watch how they went through the site. If anyone can help that would be great.

Cheers

pommoz :)
 
It'd probably be easier to parse your web server's log files... all the information you're after is already there.

But, that being said, you could accomplish it your way by doing exactly what you've said. Build an Application.cfm at the of your server... capture all the information you want... and put it in whatever database(s) you like.

A structure something like:
Code:
-get page name (#GetBaseTemplatePath()#)
-get user information (#CGI.HTTP_USER_AGENT#, #CGI.REMOTE_ADDR, #CLIENT.CFID#, #CLIENT.CFTOKEN#, etc)

-query page log table for hit qty where pagename = name of page
-add one to hit qty
-update page log table where pagename = name of page

-insert into click path table a new row with unique click id (unique primary key), page name, and all user information you need or want

That's about it. No real need for CFLOCK, as you aren't really dealing with Application, Server or Session variables (unless you want to).

Or, better yet, just do the insert into the click path table. With some imaginative querying, you should be able to build a report that shows both views (individual page clicks, and user path) from a single database table... no need to have two.

So just do:
Code:
-get page name (#GetBaseTemplatePath()#)
-get user information (#CGI.HTTP_USER_AGENT#, #CGI.REMOTE_ADDR, #CLIENT.CFID#, #CLIENT.CFTOKEN#, etc)

-insert into click path table a new row with unique click id (unique primary key), page name, date/time, and all user information you need or want

then, in it's simplest form, do a query like:
Code:
<cfquery name=&quot;pageviews&quot; ...>
SELECT * FROM clickpath WHERE pagename = '/[URL unfurl="true"]wwwroot/path/file.cfm'[/URL]
</cfquery>

and #pageclicks.RecordCount# now contains the raw number of views for the page
and then do a query like:
Code:
<cfquery name=&quot;userpath&quot; ...>
SELECT * FROM clickpath WHERE userid = 1234 ORDER BY timestamp
</cfquery>

and the result set &quot;userpath&quot; now contains a full blow-by-blow list of how user 1234 traveled through your site.

Same table.
Hope it helps,
-Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top