Solved

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

Posted on 2010-09-23
8
424 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 53

Expert Comment

by:Huseyin KAHRAMAN
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 53

Expert Comment

by:Huseyin KAHRAMAN
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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 53

Accepted Solution

by:
Huseyin KAHRAMAN 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

752 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