cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
kj460
Community Participant

Getting the title of the page that students viewed

Is there any API function that returns the title or URL of the page that students viewed?

The number of page_views can be achieved by making this call (Analytics - Canvas LMS REST API Documentation ), but it only returns the page_view counts and its timestamp.

5 Replies
bneporadny
Community Champion

Hi Kevin,

I'm not aware of a way to pull this information via an api call, but if you are using canvas data‌ you can look at the requests table and be able to pull #url of the pages that the student viewed. 

kj460
Community Participant

Hi  @bneporadny ‌,

Thank you for the information!

Yes, I was able to get the URL of the page that the students viewed, but I need title of the page that students visited for the application that I'm working on.

Do you know if there is a way to retrieve page title via page URL through an API call?

Thank you

bneporadny
Community Champion

Hi Brian,

I haven't really used this table very much just because it is extremely large, but included in the table is the "ID" for the assignment, quiz, etc. that you should then be able to use to tie back to the appropriate table to get the title of said request. 

Request table documenation

281953_pastedImage_1.png

282017_pastedImage_2.png

Hope this helps. 

Brian

 @kj460 ,

 

I don't think you want to do this with the API, see API Call: User Page Views/Submissions within Date Range 

 

For Canvas Data, you can JOIN tables together.

 

I just pieced this together from some of my samples. This will return:

  • Course Name
  • If the Request/URL is associated to an assignment or quiz will show the name
  • If not, it attempts to parse the title of the wiki page from the URL
-- mssql
-- join requests to course, assignments, quiz and display the title...
-- WHEN the request is associated to those records
SELECT *
FROM (
     SELECT
          r.user_id,
          CONVERT(DATETIME, CONVERT(VARCHAR(20), r.timestamp, 100)) timestamp,
          r.url,
          --r.course_id,
          c.canvas_id AS canvas_course_id,
          c.name AS course_name,
          --r.quiz_id,
          q.canvas_id AS canvas_quiz_id,
          q.name AS quiz_name,
          --r.assignment_id,
          a.canvas_id AS canvas_assignment_id,
          a.title AS assignment_name,
          CASE
               WHEN PATINDEX('/courses/%/pages/%', url) >= 1 AND PATINDEX('%?%', url) >= 1
                    THEN SUBSTRING(LEFT(url,CHARINDEX('?',url)), CHARINDEX('/pages/',url,0)+7,(CHARINDEX('/', REVERSE(url), 1)-CHARINDEX('?', REVERSE(url), 1))-1)
               WHEN PATINDEX('/courses/%/pages/%', url) >= 1 AND PATINDEX('%?%', url) = 0
                    THEN SUBSTRING(url, CHARINDEX('/pages/',url,0)+7,1000)
               WHEN PATINDEX('/courses/%/pages', url) >= 1
                    THEN 'pages-list'
               ELSE ''
          END AS wiki_url
     FROM dbo.requests r
          LEFT JOIN dbo.course_dim c ON (c.id = r.course_id)
          LEFT JOIN dbo.quiz_dim q ON (q.id = r.quiz_id)
          --LEFT JOIN dbo.discussion_dim d ON (d.id = r.discussion_id)
          LEFT JOIN dbo.assignment_dim a ON (a.id = r.assignment_id)
     WHERE
          user_id IS NOT NULL -- AND user_id = 
          AND PATINDEX('%ping%',url) = 0
          AND PATINDEX('%page_views%',url) = 0
          AND PATINDEX('/api/v1/%',url) = 0
          AND PATINDEX('%edit%',url) = 0
          AND PATINDEX('%.json%',url) = 0
          AND web_application_controller NOT IN ('files','folders')
          AND web_application_action NOT IN ('backup')
) x
GROUP BY user_id, timestamp, url, canvas_course_id, course_name, canvas_quiz_id, quiz_name, canvas_assignment_id, assignment_name, wiki_url
ORDER BY timestamp‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
  • You can continue to append the user_dim, enrollment_dim, etc.
  • There will be duplicate-type rows caused by variations in similar URLs over a short time period, you can add more grouping or trimming things like query strings.
  • If you want assignment/submission dates vs due dates, that should be done without the requests table.

 

I will warn you that every clause or join you create on the requests table starts to slow down your results. Also check out Requests TableCanvas Data Page Views 

James
Community Champion

 @kj460 , 

I'm responding to this specific question

Do you know if there is a way to retrieve page title via page URL through an API call?

The answer is yes, this can be done using the Show pages endpoint of the Pages API.

Let's say the URL (without the host) was this

/courses/896851/pages/followup-page?module_item_id=23210019‍‍

You would make an API call to 

GET /api/v1/courses/896851/pages/followup-page‍

It returns an object like this ( I deleted the last edited by and removed the body)

{
  "title": "Followup Page",
  "created_at": "2016-06-05T04:03:26Z",
  "url": "followup-page",
  "editing_roles": "teachers",
  "page_id": 6988007,
  "last_edited_by": {
  },
  "published": true,
  "hide_from_students": false,
  "front_page": false,
  "html_url": "https://richland.instructure.com/courses/896851/pages/followup-page",
  "updated_at": "2016-06-05T04:03:58Z",
  "locked_for_user": false,
  "body": "<p> ... </p>"
}

Right there at the top is the title of the page.

If you anticipate a lot of URLs from the same course, you can make the call to without specifying the page name at the end and it will give you all the pages in a course.