Calculate duration of the last session on website
You can calculate the duration of the last session of a customer on a website by creating aggregates and expressions.
Prerequisites
- Implement tracking code on your website.
Process
In this use case, you will go through the following steps:
- Create an aggregate that return the timestamps of the session start and session end events.
- 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.
- Go to Analytics > Aggregates > Create aggregate.
- As the aggregate type, select Profile.
- Enter the name of the aggregate.
- Set Aggregate to Last.
- From the Choose event dropdown list, select session.start.
- Click + where.
- On the modal, click and select Specials.
- From the dropdown list, select TIMESTAMP.
- In the date range, select Lifetime.
- Save the 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.
-
Go to Analytics > Aggregates > Create aggregate.
-
As the aggregate type, select Profile.
-
Enter the name of the aggregate.
-
Set the Aggregate to Last.
-
From the Choose event dropdown list, select session.end.
-
Click + where.
-
On the modal, click and select Specials.
-
From the dropdown list, select TIMESTAMP.
-
Click + where.
-
On the modal, click and select Specials.
-
From the dropdown list, select TIMESTAMP.
-
As the logical operator, select Date, and then select More than.
-
Click the icon next to the logic operator and keep clicking until you get .
-
Click Choose values.
-
Use the search box to find the Session start aggregate you created in the previous part of the process.
-
In the date range, select Lifetime.
-
Save the aggregate.
Create an expression
In this part of the process, create an expression that deducts the time of session start from the session end.
- Go to Analytics > Expression > New expression.
- Enter the name of the expression.
- Leave the Expression option at default (Attribute).
- Build the following 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.
- 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. - Analytical dashboard
By creating an analytical dashboard and adding this expression to 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.