Click Through Counting

Here's a click-thru counter you can use to count how many times a link and/or graphic has been clicked. What you need are three things:

  • A text file to hold the counts.
  • A redirect file.
  • A counter.

Here's the code:


Open up a text editor or whatever you use to code, and paste the below code and save it as click_counter.asp

<%
Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
 HitsFile = Server.MapPath ("/counter") & "\click_hits.txt"
Set InStream= FileObject.OpenTextFile (HitsFile, 1, false )
 Oldclick_hits = Trim(InStream.ReadLine)
 Newclick_hits = OldClick_hits + 1
Set OutStream= FileObject.CreateTextFile (HitsFile, True)
 OutStream.WriteLine(NewClick_hits)
%>

Now create a text file called click_hits.txt and type "0" in the file as the initial hit. The Server.MapPath is the directory under your root where this text file is saved. For example, a folder called counter directly under the root directory where my click_hits.txt is stored (/counter) The codes above read the number in the text file, add it with 1, overwrite the old hit, and display it.
click_hits.txt must have write rights given to it either for everyone or at the very least IUSER_MachineName

Now create the redirect file. Paste the following code and name it count_redirect.asp
<% Response.Buffer = True%>
<!--#include file="click_counter.asp"-->
<% Response.Redirect "http://www.example.com" %>

Now use the below html tag for the link or graphic you want to show a click-thru count for:

Instead of having <a href="http://www.example.com">
use
<a href="www.example.com/count_redirect.asp">Click Here</a>


click through counting advertising clicks counter hits visits hitcount


Back To Top
© 1998 - 2024 psacake.com
Version 7.21 | Advertise on this site