You can plot average session lengths and define a threshold
to visualize how often the sessions lengths exceed your threshold.
About this task
In this example, you take all the values that are recorded
in a single day, calculate the average, and plot them on a graph.
Procedure
- Define what you consider a session. A session can be defined
as the time interval that starts when the user logs in until the user
logs out. Another way to define a session is to start the session
when the user begins a process and end the session when the process
is complete. For this example, a session starts when the application
enters the foreground and ends when the application goes into the
background.
- The application lifecycle callback methods depend on which
environments you want to support. You can use the native versions
of Analytics API for those environments. For simplicity, this example
logs the amount of time that is spent on the session that uses the JavaScript API.
- Add this code to your application:
function getSessionTotalTime(currentTime, startTime) {
return currentTime - startTime;
}
// startTime and endTime can be retrieved through app lifecycle event listeners
WL.Analytics.log({'totalSessionTime’ : getSessionTotalTime(endTime, startTime)}, 'totalSessionTime');
- Send the analytics data to the server:
WL.Analytics.send();
- From the Custom Charts tab of the Dashboard page
in the Analytics Console, click Create Chart.
- Provide the following values:
- Chart Title: Average Session Times
- Event Type: Custom Data
- Chart Type: Bar Graph
- Click the Chart Definition tab and
provide the following values:
- X-Axis: Axis By Timeline
- Y-Axis: Average
- Property: totalSessionTime
- Click the Chart Properties tab and
add a threshold line with the following values:
- Threshold Label: SessionTimeGoal
- Threshold Value: 300
This threshold creates a line at the value that is specified
with the label. The goal is to show the daily average session time
that is greater than 300 units of time.
- Click Save.