Solved

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

Posted on 2010-09-23
8
413 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
If possible, did you try Google Analytics ?
http://www.google.com/analytics/

Check this article : http://www.15seconds.com/issue/021119.htm
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…

772 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

14 Experts available now in Live!

Get 1:1 Help Now