Solved

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

Posted on 2010-09-23
8
415 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now