Measure time spent on page accurately with AJAX? Might be an extensive problem


#1

Hello,

First, I am not sure if this belongs to general questions forum as it probably requires a bit of editing of the piwik internal code, so if I am posting this into a wrong section of the website I am sorry and redirect me kindly.

My problem is that I need to measure the time spent on a page by a visitor, or the whole time spent on website for the start (that should be easier).

Piwik in its current version doesn’t do that properly, it only measures the time passed between two actions, however I need it to measure the time even if the visitor displays only one page and leaves right after. There is no need for extreme accuracy though, an interval of 10 seconds would do fine.

I was thinking about accomplishing this by a workaround cosisting of editing the piwik tracking javascript code using an AJAX request which updates the time value in database record in intervals, however the code seems a bit complicated and I don’t know how (and whether is it even possible) to get the ‘piwik_log_visit’ table’s ID of the current record in the tracking code for that? It is actually the only thing I need to make this work, the PHP script updating the time value in the database would not be a problem then.

I’ve naturally done some research so I know (and I hope I am right) that actions time is stored in ‘piwik_log_link_visit_action’ table under time_spent_ref_action, whole time spent on the website of a visit is in ‘piwik_log_visit’ table under ‘visit_total_time’ as a difference between ‘visit_first_action_time’ and ‘visit_last_action_time’ so I guess these two are the values I need to update manually to achieve this.

So the question is, how do I get the current record ID in the javascript? Is it even possible? I believe it shouldn’t be very complicated, but I don’t feel like I understand the tracking javascript enough and don’t want to experiment with the code too much.


(Matthieu Aubry) #2

See discussion in ticket: Propose Page speed reports, Load time analytics · Issue #1700 · matomo-org/matomo · GitHub


#3

Sorry, this is not what I want at all, I need time spent on the page by a visitor (how long was he browsing the contents etc), not the page loading speed…


(Matthieu Aubry) #4

Sorry I meant: Support Ping requests to report a better 'time on page' · Issue #2041 · matomo-org/matomo · GitHub