Introducing time-on-site Analytics For Businesses And High-end Applications

Saleem
The Startup
Published in
8 min readJun 12, 2018

Timeonsite analytics can be used in web pages and applications to measure users time spent on site, critical metric for measuring user response. It’s part of web analytics to understand users and business applications. It is made possible with timeonsite-tracker.js, the time metrics tracker responsible for measuring accurate page visit duration in web applications.

Timeonsite-tracker features

This picture describes timeonsite tracker features. It can track and generate tons of analytics from page visits in your application data. In this article, we are going to mine timeonsite(tos) analytics from a single source of data collected with it and try to visualize rich analytics data all dealing with users’ time on site.

You may be interested in timeonsite tracking real-time demo for a minute or two before proceeding with this article.

Ever wondered how to answer following questions that help you derive intelligent analytics from your site/application?

  • what is the time spent by users on single a page/post for a given month?
  • Is my blog post that I wrote last week really getting any attention from users?
  • Is it worth investing money on a specific blog section (E.g. medicine), which is a huge collection of articles by writing new articles/updating existing ones?
  • What is the overall time spent by users in my application on a given day/week/month?
  • What is the proportion of anonymous users to authenticated users that visit and consume information in my site?
  • I would like to depend on an analytics software that tracks user visit duration accurately. Is there one I can rely on?
  • Can I learn about recent user sessions and their page visit duration?

If you are someone like me willing to answer these questions with great clarity, Timeonsitetracker.js can give answers to these questions with exceptional details. Let’s explore what information we can mine from our application to better understand our users and site usage.

We use the word “mine” a lot here to describe querying data. Why? we mine time since time is gold, to find measurable insights by tracking time, right?

For this article, we’ll consider mining insights from an imaginary Wordpress application which is a collection of posts and pages. We are going to run queries against MySQL database comprising 100k records. Let’s first explore the schema of “tos” table holding time on site information.

DB name: tosdata
Table name: tos
Table sample data: https://github.com/saleemkce/tos_dump/tree/master/php

Timeonsite analytics hub: https://github.com/saleemkce/timeonsite_analytics

Let’s start looking at the schema of “tos” table that holds all timeonsite analytics data with DESC tos statement

tos schema in MySQL, most popular open source RDBMS

As you could see, it is a very simple table in which “tos_session_key” uniquely identifies user sessions. Nothing is mandatory and columns are used to store time on site with related data; one column for holding page title, one for url, one for page entry time, one for page exit time, one for user type etc. All other fields are self-explanatory. Please check documentation that describes each field with type information.

tos table records count -MySQL

* Querying a record set for single tos_session_key

record set for single tos_session_key -query
record set for single tos_session_key; top row in timeonsite column contains final timeonsite for given session-results

* What could you expect by using timeonsite-tracker and its analytics?

  • Full control over data; you own all data hence privacy is guaranteed
  • Data accuracy
  • Build simple to complex SQL queries, find insights and generate custom reports
  • Understanding user behavior on specific pages and application usage

Let’s explore a few queries in timeonsite analytics here…..

* Let’s take a look at 10 recent sessions…

Recent sessions SQL query
Recent sessions SQL query -results

Full query at timeonsite_analytics page

We queried for recent tos_session_key and took its maximum timeonsite entry from the result set. Then we ordered the result by entry_time. So, we got most recent sessions first; then we applied LIMIT to filter only 10 records from user sessions.

Here, we used TOS_GET_DURATION function to convert seconds to user-friendly format which is overall time spent duration.

* Let’s find unique posts by overall time spent duration…

All posts overall duration -query
All posts overall duration -results

Full query at timeonsite_analytics page

This is a pretty big query but simple (nested sub-queries) one comprising of two parts. One for finding recent posts visited and store its order in variable. Another one is actual query that finds the pageviews of each post and computes the overall time spent of individual posts.

Let’s briefly explain the main query i.e., the second one. We query for unique title i.e., posts along with entry_time in recent order. Then, we query for timeonpage from result set along with title. Finally we use COUNT function on records to find pageviews and SUM function on timeonpage to compute overall time spent on each post. We also applied TOS_GET_DURATION for converting to desired output format.

* Let’s find single post’s overall time spent duration last month…

Single post overall duration last month -query
Single post overall duration last month -results

Full query at timeonsite_analytics page

This query is very similar to last one we saw now because it captures pageviews of required post and overall time spent on the same post except that we don’t need any additional query here to find recent posts order since we query for single known post at hand i.e., we query for single page title (WHERE title=”Nature’s beauty in Amazon forest).

* What’s the short and long visit of posts?

Short & long visits duration -query
Short & long visits duration -results

Full query at timeonsite_analytics page

This is another simple query to find shortest & longest visit duration of all posts in our application. It helps us compare posts/pages and inquire why certain pages don’t get expected attention from users and find which posts turned to be most popular visits.

This query is damn simple and self-explanatory since we haven’t used any sub-queries as in previous scenarios. We apply MIN and MAX function on each timeonpage and group the results by title to find Short & Long visit for each post

* What’s user type `time spent` by duration?

user type time duration -query
user type time duration -results

Full query at timeonsite_analytics page

* Filtering data & modifying result sets

In most of the queries above, we can apply filtering as we wish to customize data and find interesting record set. For example, you can usually filter by applying SQL conditions like,

WHERE entry_time=’2015–07–22’

WHERE title=’Home page’ && entry_time=’2010–07–22’

BETWEEN entry_time=’2015–07–22’ AND entry_time=’2016–07–22’

ORDER BY timeonsite DESC LIMIT 50

Analytics gets more interesting only when you apply required filters and add customized queries.

* Note on performance

This post is not about optimizing SQL queries/MySQL table to increase query performance. Instead, it is just an illustration of what data & insights we can mine from timeonsite analytics with timeonsitetracker.js

We used MySQL table holding around 100k records for this article. In most cases it took around 2 to 8 seconds in querying this valuable data in local machines. You need to create necessary index, optimize queries and fine-tune database for drastically improve performance when dealing with millions of records and creating analytics dashboards in real-time.

* Build & share your own queries in timeonsite analytics

We have only scratched the surface in timeonsite analytics. There are many key queries readily available that provide more insights about site usage. This queries list might be very small for now. Also, this is just a starting point for this way of analyzing data and finding insights. More valuable queries will be added in this analytics hub so that businesses can consume this and get ready-made custom reports for their applications.

You may build more interesting queries that suits your applications and share it with analytics hub so that others get to know new ways of querying timeonsite data & page visit duration. Definitely, the existing queries may be written in better way. Improvements are really appreciated.

* Who is most benefited by using timeonsite analytics?

  • Banking sites
  • Academic sites
  • Travel services
  • News websites and publications
  • Financial services
  • Analytics applications
  • Real-time applications & time-critical systems
  • Consumer sites and a lot more…

* Started Integrating timeonsite-tracker.js in your app?

If you have not started using it, you are likely missing key insights that help you take informed decisions about users and site usage. Start using it today and find key measures that drive your business and help you invest in areas that maximize profit. Though there is a small yearly charge for using tracker, it’s worth checking it once. Otherwise, you may use it in non-production domains where it’s free to test and use.

If you found this article to be interesting and valuable, feel free to hit a star on project page and share this page on social media.

*References for timeonsitetracker.js

Timeonsite-tracker.js

Documentation & real-time demo

Timeonsite Analytics

Related article on Medium

This story is published in The Startup, Medium’s largest entrepreneurship publication followed by 333,853+ people.

Subscribe to receive our top stories here.

--

--