How to count how many times aprticular link has been clicked using jsp and javascript

Showing Answers 1 - 4 of 4 Answers

YON

  • Feb 20th, 2006
 

Do u want the code .... please tell what exactly is needed....just writing a javascript it can be done ...or also a swing program will solve this problem

Just use the following code in jsp <%! int counter=0 %> // instance variable declaration <% counter++%> // incrementing the counter when ever jsp clicked then print the counter value where ever you required

  Was this answer useful?  Yes

C.R.Venkatesh

  • May 15th, 2006
 

Hi,Clearly, it depends on the level of details one needs to capture, let's say XYZ123.com wants to place a promotional ad on a frequently visited page. For simplicity, let's confine to one particular page (say XYZPage.jsp):(a) How many times users visit this particular page? (b) How many times each user visits this particular page?The former is quite simple, cache a numeric value in Servlet Context and increment it for every request that hits XYZPage.jsp and subsequently log this value for analysis.Example (log) : 10-10-2005 AppName SiteCounter:10010-10-2005 AppName SiteCounter:101The later is used to track the individual's interests in visiting a particular page in the site. Just cache a numeric value in Session and increment it for every request that hits XYZPage.jsp and subsequently log this value ALONG WITH SESSION ID for analysis. Important Note: Assumption here is, authentication is NOT enforced for accessing the site.Example (log) : 10-10-2005 SessionID:123498A12FAF NewSession10-10-2005 AppName:SessionID:123498A12FAF UserCounter:110-10-2005 AppName:SessionID:123498A12FAF UserCounter:210-10-2005 AppName:SessionID:123498A12FAF UserCounter:310-10-2005 SessionID:78649A12FAF NewSession10-10-2005 AppName:SessionID:78649A12FAF UserCounter:110-10-2005 AppName:SessionID:78649A12FAF UserCounter:2Tips: Use ServletContext's setAttribute(String, Object) method to cache a numeric value.There are opensource/freeware log analyzer available to analyse and report based on the criteria that you enforce or viable solution would be to write a shell-script. For example:(a) To fetch total number of times the page XYZPage.jsp has been visited on a particular day (say 10-10-2005): Extract all rows in the log that starts with "10-10-2005" and contains the data "SiteCounter" Print the last row.(b) To fetch total number of times the page XYZPage.jsp has been visited on a particular day (say 10-10-2005) by each user?* Extract all rows in the log that starts with "10-10-2005" and contains the data "NewSession"For Each SessionID Extract all rows in the log that: starts with "10-10-2005" contains the data "UserCounter" contains ${SessionID} Print the last rowEnd ForThis is a typical example most often employed in organizations for reporting on the visited links.

  Was this answer useful?  Yes

C.R.Venkatesh

  • May 15th, 2006
 

Hi,

Clearly, it depends on the level of details one needs to capture, let's say XYZ123.com wants to place a promotional ad on a frequently visited page.
For simplicity, let's confine to one particular page (say XYZPage.jsp):
(a) How many times users visit this particular page?
(b) How many times each user visits this particular page?

The former is quite simple, cache a numeric value in Servlet Context and increment it for every request that hits XYZPage.jsp and subsequently log this value for analysis.

Example (log) :
10-10-2005 AppName SiteCounter:100
10-10-2005 AppName SiteCounter:101
The later is used to track the individual's interests in visiting a particular page in the site. Just cache a numeric value in Session and increment it for every request that hits XYZPage.jsp and subsequently log this value ALONG WITH SESSION ID for analysis.

Important Note: Assumption here is, authentication is NOT enforced for accessing the site.

Example (log) :
10-10-2005 SessionID:123498A12FAF NewSession
10-10-2005 AppName:SessionID:123498A12FAF UserCounter:1
10-10-2005 AppName:SessionID:123498A12FAF UserCounter:2
10-10-2005 AppName:SessionID:123498A12FAF UserCounter:3

10-10-2005 SessionID:78649A12FAF NewSession
10-10-2005 AppName:SessionID:78649A12FAF UserCounter:1
10-10-2005 AppName:SessionID:78649A12FAF UserCounter:2

Tips: Use ServletContext's setAttribute(String, Object) method to cache a numeric value.

There are opensource/freeware log analyzer available to analyse and report based on the criteria that you enforce or viable solution would be to write a shell-script.

For example:

(a) To fetch total number of times the page XYZPage.jsp has been visited on a particular day (say 10-10-2005):
Extract all rows in the log that starts with "10-10-2005" and contains the data "SiteCounter"
Print the last row.

(b) To fetch total number of times the page XYZPage.jsp has been visited on a particular day (say 10-10-2005) by each user?
* Extract all rows in the log that starts with "10-10-2005" and contains the data "NewSession"

For Each SessionID
Extract all rows in the log that:
starts with "10-10-2005"
contains the data "UserCounter"
contains ${SessionID}
Print the last row
End For

This is a typical example most often employed in organizations for reporting on the visited links.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions