These VQL examples include only charts and metrics about the length of time that students spent. Each of the widgets represents either out-of-the-box (OOTB) metrics built-in to the LRS, or practical metrics our customers asked for. You can find the OOTB metrics in the Activity Overview dashboard of your LRS. For some of these examples, you can often use the regular Chart Builder to assemble an approximately similar widget.
We've collapsed some of the whitespace in the JSON in this article, to make it easier to read.
Average Session Duration, for All Courses
Average session duration, from initialized to terminated. This widget filters all statements on two verbs for starting and ending any course, finds the length of each session, and then calculates the average length of all sessions. Be careful reading this value! “Session” length is an unreliable xAPI metric: courseware seldom ends sessions correctly, which can lead to deceptively “multi-day” sessions.

{ "title": "Average Session Duration",
"subtitle": "All Courses",
"filter": {
"verb.id": {
"$in": [
"http://adlnet.gov/expapi/verbs/initialized",
"http://adlnet.gov/expapi/verbs/terminated"]}},
"process": [{
"$frequentValues": {
"path": "context.registration",
"limit": 1000,
"metrics": {
"start": {"$min": "timestamp"},
"end": {"$max": "timestamp"}}}}, {
"$addFields": {
"duration": {"$divide": [{"$subtract": ["$end", "$start"]}, 3600000]}}},
"$group": {
"_id": 1,
"average": {"$avg": "$duration"}}}, {
"$notice": {
"icon": "clock",
"title": "${(value.average).toFixed(0)} hours",
"subtitle": "Average duration, initialized to terminated is ${(value.average)} hours"}}]}
Average Session Duration, for a Single Course
This simple-looking widget uses complex logic and math. Duration extrapolated from “session” length is a popular metric. Unfortunately, courseware sometimes doesn’t send it as a discrete metric, so the LRS must calculate it. Here is a typical work-around using differences in session timestamps. In this widget, five process stages extract the extreme timestamps for each context registration, calculate the ratio, convert the value from milliseconds to hours, re-group the separate values, compute the average, and then show the final value. Averages can conceal distributions and trends. However, the average duration of a course or lesson is a useful metric for comparing against similar units of instruction, or against the budgeted amount.

{ "title": "Average Session Duration",
"subtitle": "Deep Learning",
"filter": {
"meta.relatedActivities": "https://www.coursera.org/specializations/deep-learning"},
"process": [{
"$frequentValues": {
"path": "context.registration",
"limit": 1000,
"metrics": {
"start": {"$min": "timestamp"},
"end": {"$max": "timestamp"}}}}, {
"$addFields": {
"duration": {"$divide": [{"$subtract": ["$end", "$start"]}, 3600000]}}},
"$group": {
"_id": 1,
"duration": {"$avg": "$duration"}}}, {
"$notice": {
"title": "${ value.duration.toFixed(0)} hours",
"subtitle": "Average duration is ${value.duration} hours",
"valuePath": "$"}}]}
Average Session Duration, per Lesson (Ignoring Outliers)
Vibe-coded
using our LRS MCP (note the lack of a
$frequentValues stage), this widget originally charted median values, but the outliers were too great. If a student pauses a lesson, then the “session” doesn’t stop: its duration can include
hours or days away from the keyboard. Manually adding a
$match stage filters-out sessions longer than 1 hour. Even so, if you have only a few students, then use caution when assuming a “typical seat time”, per lesson.

{ "title": "Average Session Duration",
"subtitle": "Deep Learning (ignoring sessions longer than 1 hour)",
"filter": {
"meta.relatedActivities": "https://www.coursera.org/specializations/deep-learning"},
"process": [{
"$group": {
"_id": "$statement.context.registration",
"lesson_iri": {"$first": "$statement.object.id"},
"min": {"$min": "$statement.timestamp"},
"max": {"$max": "$statement.timestamp"}}}, {
"$addFields": {
"duration": {"$divide": [{"$subtract": ["$max", "$min"]}, 60000]}}}, {
"$match": {
"duration": {"$lt": 60}}}, {
"$group": {
"_id": "$lesson_iri",
"count": {"$count": {}},
"average_duration": {"$avg": "$duration"}}}, {
"$addFields": {
"lesson_name": {"$switch": {"branches": [{
"case": {
"$eq": ["$_id", "https://www.coursera.org/specializations/deep-learning/1"]},
"then": "Lesson 1"}, {
"case": {
"$eq": ["$_id", "https://www.coursera.org/specializations/deep-learning/2"]},
"then": "Lesson 2"}, {
"case": {
"$eq": ["$_id", "https://www.coursera.org/specializations/deep-learning/3"]},
"then": "Lesson 3"}, {
"case": {
"$eq": ["$_id", "https://www.coursera.org/specializations/deep-learning/4"]},
"then": "Lesson 4"}, {
"case": {
"$eq": ["$_id", "https://www.coursera.org/specializations/deep-learning/5"]},
"then": "Lesson 5"}],
"default": "?"}}}}, {
"$barChart": {
"categoryPath": "lesson_name",
"valuePath": "average_duration",
"sortCategory": true}}, {
"$addFields": {
"chart.yAxes.0.title.text": "Minutes",
"chart.xAxes.0.renderer.labels": null,
"chart.yAxes.0.min": 0,
"chart.yAxes.0.strictMinMax": true,
"chart.series.0.bullets": [{
"type": "LabelBullet",
"label": {
"text": "{valueY.value.formatNumber('##.')}m",
"y": "20",
"fill": "#fff",
"fontSize": "20",
"fontWeight": "bold"}}],
"chart.series.0.columns.template.tooltipText": "{categoryX}: {count} sessions, \n
{valueY.formatNumber('#.')} minutes.",
"chart.theme": {
"graphColors": [{"value": "#00BBBB"}]}}}]}
We're constantly receiving requests for new charts and metrics: check back often. Or, click the Follow button in the right menu to get email alerts when we update this article.