Solved

How to do page tracking by javascript and/or C#?

Posted on 2010-09-23
8
423 Views
Last Modified: 2012-05-10
hi all,
our business requires us to track how many hits for each page in our website. it means, i have to record the PageName, the NumberOfHits in our database table.

p.s. most pages in our website are HTML not .aspx.

can anyone please help me? give me the sample code or points me to the right direction?

i want to use javascript and/or C# to achieve this.

thanks a lot
0
Comment
Question by:viola123
8 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 33750544
create a basepage, say myPage
add a property say pageid

on load event add some code, to connect to db and call sp, say addMyPage(pageid)

this sp in your db will do this
insert into PageLog(pageid, visitdate) values(pageid, getdate())
where PageLog is a table with two columns: pageid, visitdate (default=getdate)

inherit your all pages from this instead of default ui.web.page
and set pageid=26735 on pageinit event
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 33750557
or just create a class/module with one shared/statuc method AddPageLog(pageid) which calls the sp i explained above
and run this method on all pages init vent like

AddPageLog(36732)

also, create a Pages table in your db

Pages : PageID, PageName, Description, Path,....

0
 
LVL 2

Expert Comment

by:purquiz
ID: 33750558
Just a thought:

You can use Javascript to make a request to a c# page. You fire the javascript function when your html page loads; the c# page receives the request, saves the name of the html page in a db, or adds one to the visit counter if the record already exists. The C# page returns the number, and the javascript puts that into a DIV.

It's ajax.

A simple way to do it is using the JQuery Ajaxify plugin for making the request.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 250 total points
ID: 33750561
If possible, did you try Google Analytics ?
http://www.google.com/analytics/

Check this article : http://www.15seconds.com/issue/021119.htm
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 33750585
The server logs normally record all of this information already.  Do you have your own server and/or do you have access to the logs?
0
 
LVL 6

Author Comment

by:viola123
ID: 33751134
hi,
HainKurt: thanks a lot, but our most webpages are HTML not ASPX pages, so i think purquiz's idea is more suitable to me. is there any sample code you can show me?

purquiz: could you pls give me some reference link  or sample code?

leakim971: i know we can use third party tools, but we have to do it by ourselves,   this is a business decision.

DaveBaldwin: we already have a log file to log everything, but we don't wanna use it cos the file is big and messy.

thanks for all your answer

0
 
LVL 51

Accepted Solution

by:
HainKurt earned 250 total points
ID: 33754409
if it is asp/html, probably you have a footer.inc that you include in all pages...

what I think is, create a page, counter.asp, which creates a counter image (you can send 1x1 blank image if you wish). When called it will connect to db, run the sp, creates / sends the image to the page... from any page just use something like this

<img src="Counter.asp?PageID=234234&rt=<%= now() %>">

we are adding rt to make sure it is not cached...

if you wish you can use this

<link type=javascript src="Counter.asp?PageID=234234&rt=<%= now() %>"> and return nothing... or this
<script scr="Counter.asp?PageID=234234&rt=<%= now() %>"></script> if you do not use any image counter or blank images...
0
 
LVL 6

Author Closing Comment

by:viola123
ID: 34315393
not quite work for my issue. but i have to close this question, so i can ask another one. anyway, thanks you all.
by the way, the website is outsourced, so no need to worry about it now.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question