Calculate duration of the last session on website

Published November 17, 2021
Modules
Difficulty

You can calculate the duration of the last session of a customer on a website by creating aggregates and expressions.

Prerequisites


Process


In this use case, you will go through the following steps:

  1. Create an aggregate that return the timestamps of the session start and session end events.
  2. Create an expression that deducts the time of session start from the session end.

Create aggregates


As the first part of the process, create aggregates that return the timestamps of the session start and session end events.

Session start time

In this part of the process, create an aggregate that collects session start times.

  1. Go to Analytics icon Analytics > Aggregates > New aggregate.
  2. Enter the name of the aggregate.
  3. Set Aggregate to Last.
  4. From the Choose event dropdown list, select session.start.
  5. Click + where.
  6. On the modal, click Three dot icon and select Specials.
  7. From the dropdown list, select TIMESTAMP.
  8. In the date range, select Lifetime.
  9. Save the aggregate.
The configuration of the start session aggregate
The configuration of the start session aggregate

Session end time

In this part of the process, create an aggregate that collects session end times with a condition that the end time is later than the start time.

  1. Go to Analytics icon Analytics > Aggregates > New aggregate.

  2. Enter the name of the aggregate.

  3. Set the Aggregate to Last.

  4. From the Choose event dropdown list, select session.end.

  5. Click + where.

  6. On the modal, click Three dot icon and select Specials.

  7. From the dropdown list, select TIMESTAMP.

  8. Click + where.

  9. On the modal, click Three dot icon and select Specials.

  10. From the dropdown list, select TIMESTAMP.

  11. As the logical operator, select Date, and then select More than.

  12. Click the icon next to the logic operator and keep clicking until you get Choose value icon.

  13. Click Choose values.

  14. Use the search box to find the Session start aggregate you created in the previous part of the process.

  15. In the date range, select Lifetime.

  16. Save the aggregate.

    The configuration of the end session aggregate
    The configuration of the end session aggregate

Create an expression


In this part of the process, create an expression that deducts the time of session start from the session end.

  1. Go to Analytics icon Analytics > Expression > New expression.
  2. Enter the name of the expression.
  3. Leave the Expression option at default (Attribute).
  4. Build the following formula of the expression:
    Formula of the expression
    Formula of the expression
    Formula explanation

    The results of the aggregates used in the expression are converted to numbers. The time of session start is deducted from the session end and the result is divided by 1000 to show the session length in seconds.

  5. Save the expression.

What’s next


You can preview the results of the expression for individual customers in two ways:

  • Customer’s profile
    In a profile of a customer, if you enabled the Show in Profiles option in the expression.
    Expression on a profile of a customer
    Expression on a profile of a customer
  • Analytical dashboard
    By creating an analytical dashboard and adding this expression to the dashboard.
    Expression used in the dashboard
    Expression used in the dashboard

Check the use case set up on the Synerise Demo workspace


Check the session start aggregate and session end aggregate configuration in Synerise Demo workspace.

You can check also the configuration of the expression.

If you don’t have access to the Synerise Demo workspace, please leave your contact details in this form, and our representative will contact you shortly.

Read more


😕

We are sorry to hear that

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

😉

Awesome!

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

Close modal icon Placeholder alt for modal to satisfy link checker