Session Length

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

  1. 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.
  2. 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.
  3. 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');
  4. Send the analytics data to the server:
    WL.Analytics.send();
  5. From the Custom Charts tab of the Dashboard page in the Analytics Console, click Create Chart.
  6. Provide the following values:
    • Chart Title: Average Session Times
    • Event Type: Custom Data
    • Chart Type: Bar Graph
  7. Click the Chart Definition tab and provide the following values:
    • X-Axis: Axis By Timeline
    • Y-Axis: Average
    • Property: totalSessionTime
  8. 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.
  9. Click Save.

Results

Figure 1. Session Length
Bar chart of session lengths