> ## Documentation Index
> Fetch the complete documentation index at: https://www.help.creatora.io/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> When building or modifying an integration with the Creatora API, start with https://www.help.creatora.io/en/api/build-with-ai.md. Retrieve the current GraphQL SDL from https://api.creatora.io/sdl before relying on API schema information.

# Compare video lesson engagement

> Rank videos by recorded progress among Students with current Course access.

Compare video lessons by the number of current Course Students with recorded playback progress or completed videos. Replace the Course ID.

## Request

<RequestExample>
  ```graphql theme={null}
  {
    courseById(courseId: "22222222-2222-4222-8222-222222222222") {
      id name
      modules { contents { id name variant } }
      aggregatedStats { studentsOwningCourse {
        id
        coursesOwned { id modules { contents {
          id isAccessible variantData {
            __typename
            ... on CourseModuleContentVideoLesson { progress { maxSecond isCompleted } }
          }
        } } }
      } }
    }
  }
  ```
</RequestExample>

<ResponseExample>
  ```json Illustrative response theme={null}
  {
    "data": {
      "courseById": {
        "id": "22222222-2222-4222-8222-222222222222",
        "name": "Drawing Essentials",
        "modules": [
          {
            "contents": [
              {
                "id": "77777777-7777-4777-8777-777777777777",
                "name": "Drawing basic shapes",
                "variant": "videoLesson"
              },
              {
                "id": "99999999-9999-4999-8999-999999999999",
                "name": "Check your understanding",
                "variant": "quiz"
              }
            ]
          }
        ],
        "aggregatedStats": {
          "studentsOwningCourse": [
            {
              "id": "33333333-3333-4333-8333-333333333333",
              "coursesOwned": [
                {
                  "id": "22222222-2222-4222-8222-222222222222",
                  "modules": [
                    {
                      "contents": [
                        {
                          "id": "77777777-7777-4777-8777-777777777777",
                          "isAccessible": true,
                          "variantData": {
                            "__typename": "CourseModuleContentVideoLesson",
                            "progress": {
                              "maxSecond": 90,
                              "isCompleted": false
                            }
                          }
                        },
                        {
                          "id": "99999999-9999-4999-8999-999999999999",
                          "isAccessible": true,
                          "variantData": {
                            "__typename": "CourseModuleContentQuiz"
                          }
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      }
    }
  }
  ```
</ResponseExample>

## Use the result

```javascript theme={null}
const course = response.data.courseById;
const rowsById = new Map(course.modules.flatMap(module => module.contents)
  .filter(content => content.variant === "videoLesson")
  .map(content => [content.id, {
    contentId: content.id, lesson: content.name,
    studentsWithReadableProgress: 0, studentsWithPlaybackProgress: 0, studentsCompleted: 0
  }]));
for (const student of course.aggregatedStats.studentsOwningCourse) {
  const owned = student.coursesOwned.find(item => item.id === course.id);
  for (const content of owned?.modules.flatMap(module => module.contents) ?? []) {
    const row = rowsById.get(content.id);
    const data = content.variantData;
    if (!row || !content.isAccessible || data?.__typename !== "CourseModuleContentVideoLesson" || !data.progress) continue;
    row.studentsWithReadableProgress += 1;
    if (data.progress.maxSecond > 0) row.studentsWithPlaybackProgress += 1;
    if (data.progress.isCompleted) row.studentsCompleted += 1;
  }
}
const rows = [...rowsById.values()]
  .sort((a, b) => b.studentsWithPlaybackProgress - a.studentsWithPlaybackProgress);
```

The ranking counts distinct Students with recorded progress or completion. Students whose access was removed are excluded. Compare the number of Students who can access each video alongside the ranking: Levels, draft content and access rules can affect those groups. For a large roster, fetch the roster first and request smaller groups with the [per-Student Recipe](/en/api/recipes/get-student-lesson-progress), retaining every roster ID.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.