User activity time


#1

Dear All,

I want to ask, is there anyway to know how long a user stay on the website?

The idea that cross my mind is to calculate between last event that sent by that user (distinct by domain_userid and domain_sessionid) substract it with the first event that the user sent.

I can do that at redshift (for analytical purpose) but I can’t do that at elasticsearch (for real time purpose).

Is there any other way to do that?

Thank you


#2

Hello,
I would suggest to try adding a window.addEventListenter(‘unload’, {customEvent}). It’s maybe not 100% reliable, so provide some fallbacks.

Otherwise there are page pings built in snowplow, which you can configure to send a request f.i. every second, to know that the user is still on the page


#3

Hello,

Thank you for your reply.

Page ping can be used on 1 page, but what I need it is the activity for whole website which has many pages of course.

For example, how long a customer from visiting website until finish buying. I want to calculate the average time of activity from start to end.


#4

Hypothetically, If you control for session cookie expiration time and always set it to something like 10 minutes or an hour (depending on what you’re willing to call a session) then:
group by session, calculate min(timestamp) and max(timestamp), then calculate period of time between min and max timestamps. Now you may want to aggregate by user to report findings to the exec team and then spend some time actually researching the core problem.

  1. Are sessions drastically different in length for same user or not.
  2. How many single, short sessions
  3. What portion of users come from external referral sources to immediately leave. What did they want. What did they find. What else they have looked at. Why they left.
  4. If you have repeat sessions, how many people come back? do they come back to look for same/similar things? Do they come back to look for other things. Do they spend more time per session when they come back? Less? Are repeat interests generally in the same things or very different?
  5. Think of experiments you can perform to engage users for longer periods of time.
    The more they click through the site, the better is your understanding of what is going on in their heads.
    What are the classes of your users: A. Those who come and go never to come back, what percentage? B. Those who stick around, what percentage?
  6. How much money did you spend on class A user acquisition? B class? How much revenue did A class generate? B class? Who should you be acquiring A or B? Who should you be funneling out to your partners A or B ?

Big list of things you might be looking at, but it all starts with time spent - on page, on site, on class of pages. Good KPI to have a lock on.


#5

If you want to do it in real-time Elasticsearch (which I don’t highly recommend as Elasticsearch isn’t the most robust when doing more complicated aggregations) it depends on which version of ES you are on as well as whether it is hosted on AWS or not.

In Elasticsearch 2 on AWS ES you can use something similar to the below which will give you epoch milliseconds for each users session start time and latest event time. In Elasticsearch 5 the preferred way would be to use scripted metric aggregations.

GET _search
{
    "query": {
        "match_all": {}
    },
    "aggs": {
        "user": {
            "terms": {
                "field": "domain_userid"
            },
            "aggs": {
                "session": {
                    "terms": {
                        "field": "domain_sessionidx"
                    },
                    "aggs": {
                        "session_start": {
                            "min": {
                                "field": "dvce_created_tstamp"
                            }
                        },
                        "session_end": {
                            "max": {
                                "field": "dvce_created_tstamp"
                            }
                        }
                    }
                }
            }
        }
    },
    "size": 0
}

#6

Thank you for your reply.

Currently, I’m using 30m as a session cookie lifetime. As I estimate, that is the average time of user to spend on my time (from browsing through payment)

And Yes, I want to benchmark my website, like when I create a promo page, how is it perform, does the promo lead the user to other pages or they just left after open the promo page. So, I want to know how long they are on my website.

Thank you for your suggestion. I think I need to breakdown the event first like you suggested.


#7

I use ES 5. I’ll try for ES 2 version first and I try the scripted metric aggregations. Thank you for your help.