Jump to content

Recommended Posts

Sorry if this is a vague Original Post, but I'm not entirely certain what I want or how to go about getting it?!  :confused:

 

I have grown weary of the "Site Analytics" software I am using, and would like to track User behavior on my own.

 

Ideally I would like to track things like...

 

- Time on Each Page

- Log of All Pages Visited

- Total Time on Website

- Data by User

- Data in Aggregate

 

I am most interested for now logging the "Time per Page" and "Listing of All Pages Visited"

 

Right now I have a script called "last_activity.php" which is required by all pages and it runs an UPDATE query that logs the Date/Time when the page is opened.

 

That is a good start.

 

Now  just need a way to log when the User leaves the Page so I have a "Time per Page" number.

 

I have some ideas on how to tackle this, but am wondering if I am trying to solve something that has already been solved.

 

And, again, things like Google Analytics are not what I want.

 

Any suggestions?

 

Thanks,

 

 

Debbie

 

Link to comment
https://forums.phpfreaks.com/topic/259184-calculating-time-on-pages-and-site/
Share on other sites

I have grown weary of the "Site Analytics" software I am using

As a web analytic specialist, I have to ask if is there a specific reason you feel this way?

 

Because the service I'm paying GoDaddy for every month seems to be way off.

 

It will show things like User #1 at some IP Address was on a certain page for 12 minutes and then show that the same User was on my site for 2 seconds?!

 

The numbers never seem to match up.

 

And I think what Google Analytics offers is crap.

 

The things I mentioned in my OP are important to me - along with other things. 

 

GoDaddy offers the metrics I want, but isn't reliable.  And Google does not offer the metrics I want.

 

Besides, what I was asking about in my OP is part of Debbie's journey into learning how things work!!

 

 

Debbie

 

What you want to calculate will never be accurate due to the request/response nature of HTTP.  When a browswer requests a page, it opens a connection sends the request, the webserver figures out a response and sends you that response, connection is closed.  That's it.  So figuring out how long a user had a particular web page open will always be an estimate.  For instance, user goes to a website in which the index page is requested, user knows what they want on your website, so they quickly click on "login", fills in a form, "submit"s, gets redirected to a user page, clicks on messages-list link and so on.  In this example we can extrapolate the time at the login page by calculating the time at which the request for the login page was made and the time the form was submitted.

 

In a strive for more accuracy there have been some tricks made over the years.  Lately the trend has been to setup a heartbeat javascript to constantly make requests to an XML-RPC/AJAX controller.  So while a user has a particular page open, every N seconds a request is made to a controller which records the activity.  You can also track mouse clicks in the same manner.  Also be aware not all browsers reliable support javascript, lots of mobile users nowadays in which this solution doesn't pan out.  There is also the problem that if minimized some browsers will pause or throttle everything in that particular window/session which may cause you problems.

 

To my knowledge there is no reliable way to tell exactly when a user has left, closed, or exited.  With PHP we can set a callback to run when a session expires, but session expiration times are usually long as not to annoy users too much.

 

Due to the limitations I've mentioned you'll see variations in the calculations between tracking implementations, between which browser clients are using, between same browser on different platforms and other various situations. 

 

Google Analytics was written with the intention of tracking trends with less focus on finite numbers, you're not the first person I've encountered that dislikes it, though I find what it does offer very telling.  You might not have to write a tracking and analytics from scratch, piwik is FOSS, check the demo out it may be more to your liking.

Hippy,

 

Thanks for the thoughtful response.  (Nice to see there are some of you still out there!)  :)

 

Here are my thoughts on this topic and your response...

 

1.) I don't "do" JavaScript.  Yuk!

 

 

2.) It is my belief that if you use some logic, you can tell with a reasonable level of certainty what your users are doing.  I know when a User lands on a page with almost complete certainty, right?  And if a User goes from page to page, then I also know when the User leaves the previous page, right? That means I should be able to tell how long a User is on every Page except the last one, right?

 

 

3.) Last week I created a "last_activity.php" script that is "required" by most pages on my site.  When it is "required" (i.e. User lands on a new page), it runs an UPDATE query which puts in a Date/Time in the Member's "last-activity" field in their record.  So, as a *logged in* User navigates my website, I am keeping track to some extent.

 

I created this cript last week because I needed a fairly reliable way to change the User's Online Status icon where they are listed in the Comments secition.

 

The logic I used was as follows...

 

- If a User's "last_activity" occurred in the last 15 minutes they are "Online and Active". 

- If a User's "last_activity" occurred between 15 and 30 minutes ago, then they are "Idle". 

- If a User's "last_activity" has not occurred for over 30 minutes, then they are "Offline". 

 

For a User's "Online Status" I think that is sufficient.

 

But for what we are talking about, I probably need to tweak things and thus why I am here!

 

 

4.) So here is what I am playing around with in my head now...

 

I leverage what I described in #3 but do this...

 

** For simplicity let's say I just want to track Logged In Users for now **

 

Everytime a (logged in) User clicks on a page I call a new "last_activity.php" script that INSERTS the UserID, LandingPage, Start Date/Time into a table.  For example, "19", "members/my_account.php", "2012-03-18 11:43am"

 

Still trying to figure this part out...

 

Then when the user navigates off the current page, I somehow run an UPDATE on the record above and log the End Date/Time so now I have a database record that says...

script		arrived_on	left_on		user
----------	------------	---------	--------
index.php	18:00		18:05		debbie

 

 

I'm not sure how that can be done.

 

And I'm not sure if that would be of any value?!

 

But to me, it would give me, "Debbie" was on the "index.php" page for 5 minutes...

 

Thoughts??

 

 

Debbie

 

2.) It is my belief that if you use some logic, you can tell with a reasonable level of certainty what your users are doing.  I know when a User lands on a page with almost complete certainty, right?  And if a User goes from page to page, then I also know when the User leaves the previous page, right? That means I should be able to tell how long a User is on every Page except the last one, right?

 

You can use assumptions like that to some extent but that doesn't mean they are really accurate.  Some examples:

- I go to your your site and start reading an article.  I need to go so I bookmark it and come back a few hours later.  When I go back I just go straight to the article.  Depending on how you do your tracking, either you'll show me as having spent hours on the site or just two sessions of an unknown duration (since the article would be the last page in both cases).

 

- I tend to open a lot of links in new tabs, but will not read them right away.  Sometimes I can have a page open in a tab for 30+ minutes before I actually get to reading it.  Again depending on how you implement your tracking you'll either see me on that page for the full duration or it will timeout and you wont know.  Either way is not really accurate as I likely only really spent a minute or two looking at the page, there rest of the time it was just open in the background waiting for me to get to it.

 

 

Creating an analytics system with any kind of reasonable accuracy is actually a pretty complex task.  That is why many places will pay a good sum of money for a pre-fab solutions such as google's analytics package.

 

i have been working on a cms for a few months now, and i have come across this issue. Right now i am only logging the total online time of members, but this scenario might be helpful.

 

Example:

total_online_time = 0

request_uri = /index.php
last_request_time = time()  //1332122582
request_time = time()  //1332122582

##this is the first page our guest has visited, this is all the info we can get (not ALL, but i get my point).

========================

request_uri = /page2.php
request_time = time()  //1332122807
time_spent_on_last_page = request_time-last_request_time //  1332122807-1332122582 = 225
total_online_time = total_online_time+time_spent_on_last_page // 0 + 225 = 225
last_request_time = time()  //1332122807

##this is the second page our guest has visited, we can get alittle bit more information for this page, and all other pages out guest visits (excluding the last page)

========================

request_uri = /page3.php
request_time = time()  //1332123020
time_spent_on_last_page = request_time-last_request_time //  1332123020-1332122807 = 213
total_online_time = total_online_time+time_spent_on_last_page // 225 + 213 = 438
last_request_time = time()  //1332123020

========================

request_uri = /page4.php
request_time = time()  //1332123046
time_spent_on_last_page = request_time-last_request_time //  1332123046-1332123020 = 26
total_online_time = total_online_time+time_spent_on_last_page // 438 + 26 = 464
last_request_time = time()  //1332123046

 

hope this helps alittle :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.