12.6 PageCounter

The Page Counter component creates a PageCounter object that counts and displays the number of times a Web page has been opened. At regular intervals the object updates the number of hits so that in the event of a server shutdown, the data is not lost.

NOTE:Courtesy Microsoft documentation for some of the information used in this section.

12.6.1 Object Diagram

Describes  the hierarchy of various objects in the Pagecounter component

Object Name

Properties

Methods

PageCounter Object

None.

Hits method

PageHits method

Reset method

12.6.2 PageCounter Object

Counts and displays the number of times a Web page has been opened. This count is updated at regular intervals. PageCounter object does not get updated until a page hit event occurs. You need to call PageHits method to increment the page counter.

12.6.3 Hits method

Returns the number of times a specified Web page has been opened.

Syntax

 object.Hits([
   WebPagePathInfo As String])
 

Parameters

WebPagePathInfo
Optional parameter. Path (virtual path) of the Web page whose hit count is to be calculated.

Return Values

Long. Indicates the number of times the specified Web page has been opened.

Remarks

If no parameter is specified, the hit count for the current page is displayed.

Example

This example displays the number of times the specified page has been opened.

 <% Set MyPageCounter = CreateObject("MSWC.PageCounter")
 MyPageCounter.PageHit
 This Web page has been viewed <%= MyPageCount.Hits %> times.<P>
 Page Myscript.asp has been viewed <%= MyPageCounter.Hits("/VirtualDir1/Myscript.asp") %> 
 

12.6.4 PageHits method

Increments the hit count for the current Web page.

Syntax

 object.PageHits()
 

Parameters

None.

Return Values

Long. Indicates the new hit count value of the current Web page.

Example

The following example increments the number of times the current Web page has been opened.

 <%   Set MyPageCounter = CreateObject("MSWC.PageCounter")   MyPageCounter.PageHits%>This Web page has been viewed <%= MyPageCount.Hits %> times.
 

12.6.5 Reset method

Sets the hit count for a specified Web page to 0.

Syntax

 object.Reset(
   WebPagePathInfo As String)
 

Parameters

WebPagePathInfo
Location of the Web page whose hit count has to be reset.

Return Values

None.

Remarks

If no parameter is specified, the hit count of the current page is reset.

Example

This example resets the counters for the current Web page and the page MYPAGE.ASP.

 <%  
   Set MyPageCounter = CreateObject("MSWC.PageCounter")    
   MyPageCounter.Reset
   MyPageCounter.Reset("/VirtualDir1/mypage.asp")
 %>(The following two values should be 0) <BR>
 Hits to this page = <%= MyPageCount.Hits %> <BR>
 Hits to mypage.nsn = <%= MyPageCount.Hits("/VirtualDir1/mypage.asp") <BR>