I have an asp.net web app that has Session state stored in sql server. I need to keep track of the time spent by a user on each page. How can i do that using cookies?
Couldn't you use a cookie to store the time when the user navigated to the page and then when they navigate to another page calculate the time spent on the previous page, enter that into the database or something and then repeat the process?
If you can get away with tracking time for all users collectively rather than individual users, I would install Google Analytics.
http://www.google.com/analytics/
Tracking user time across a site isn't ideally done in the cookies, which are more for providng things back to the user.
That said, you'd need to store the intermediate data in the cookie if you're going to store the true 'time per page' per user rather than faking it at the server by counting the gap between page requests per session. You could do this by setting the load time at the page load, then comparing that to the current time in the onUnload event hander. Save that to the cookie and it should be available to the server in the request body of the next page it sends.
Related
I want to know how e-commerce sites(e.g Amazon) remember my shopping cart list even though I didn't login at all before.
It still showing my cart list even I close all browser and revisit it.
Do they make session not to expire even after closing its browser?
I'd like to implement this in Django and need your advices.
Thanks :)
One way: With Cookies that don't expire on session end, but after a given time (for example one day or one month)
Try to open the URL with a different browser...
This is done by storing data in the session and keeping the session active for a period of time.
Django includes a very handy session framework that makes doing that rather easy - https://docs.djangoproject.com/en/1.10/topics/http/sessions/
Is it possible to use data from Google Analytics when someone visits my web page?
I would like to get information about the visitor, eg:
location
how many times he visited the page
from where he comes
time spent on website
etc
And depending on those informations display proper content. Or even add them (silently) to the contact form.
Is it possible to use the data collected by Google Analytics or should I create my own mechanism based on cookies? Maybe any other solution?
This isn't possible. Universal Analytics uses a cookie with an ID for the user and handles the rest on the server, so there's no data available to you. However, all of the info that Google is tracking is accessible to you.
location you can get via the users IP
visits you can get by setting a cookie on each user and tracking sessions
referrer should be in the request headers
time spent can be tracked the same way that ga does, but keeping track of the time everytime the user creates another hit
I am creating a testing app in django. I want to be able to store the start time (when the page loads) and the end time (when the student hits submit) on every question. I realize that I could do something in the view function, however I am afraid that the latency between server and client would make any calculation meaningless. I would ideally like to calculate the start and end times on the client and send them back to the server using django's tag system.
I am not sure the server-client latency is really meaningful for your app, but you could shoot two calls, initiated by the client in Javascript, one when the document is ready and one when the user submits the answer. You would send the current timestamp in those calls.
You would then analyse those calls on the server's side with django views.
You can use hidden form fields. Just initialize start time on page load and end time before page submit using javascript.
in a django view it will be accesable under request.POST
With Sitecore DMS you can create Profiles and show specific pages based on the user's visiting habits. This information is stored using a cookie so whenever the user comes back they have the same visitor profile. But if they delete their cookies or switch browsers that information is gone. Now what I want to do is save this visitor information to a sitecore user, in that they can log in and their visitor profiles will be the same as when they left, no matter where they are or what browser they are using. I've been trying to figure this out for a while now but without success. Whenever I login with a user and create a specific profile, that profile is deleted as soon as i log out. Is this even possible for Sitecore, because it seems rather silly to only have profiles based on cookies when cookies are deleted constantly.
With Sitecore Analytics, you have two tracking cookies, one is for Session--the other for GlobalSession (which doesn't expire across normal asp.net sessions). Unfortunately, Sitecore doesn't track profile key scores based on GlobalSession, but by a single asp.net session. The entire system is based around this, and it's very disappointing. '
To get around this, I was using OMS and use Reflector to disasssemble and rewrite some of the analytics code to record by global session. It also required a couple of schema changes as well as new rules... pretty extensive work. At the end of the day, because of the size of the database and our need for a very limited number of features, I ended up creating a single table and recording profile key values in that by globalsession.
From what I understand, the schema has changed from OMS to DMS, but the single most important factor, that data is recorded by session, has not changed.
With regard to storing the User's id, you can associate this with a 'tag' which is stored, I believe, with the globalsessionid, at least in OMS. However, Sitecore doesn't update the tag records, so you'll end up with multiple records per global session. If you're storing this value on every request, that table will bloat quickly.
There are a couple of reasons for this... not the least of which is that in many cases, you don't have a logged in user to correlate this information with. The profile data isn't stored in cookies... it's stored in the Analytics table. But it's associated with a cookie that has a unique ID and once that has been deleted, the ID (hopefully!) won't be used again.
A suggestion for how to get around this here in this StackOverflow answer.
I have an application where I would like to display the number of users that are logged into the system. Im trying to determine the cleanest way to do this that will not create a large load on the system.
I know that the system keeps track of the "last logged in time" So I could do a query and aggreate the number of users whose last login is within a given time?
Are there better solutions??
Any thoughts are welcome!! Please.
Using the last logged in time doesn't work. Your sessions can last for days/weeks so you won't know the amount of active users that way.
One solution would be to create a table with login sessions where you store that session id in a session cookie. Session cookies expire once the user has closed his/her browser window so it should give you quite an accurate estimation of when people logged in. If you actually want to store the entire session duration, than you will also have to update the table with every page view to store the time that the user was last active. This would be slightly heavier for your database ofcourse.