I am to track who viewed a specific document in a document library, I found out that there is no Item Viewed event or similar event in the SPEventReceiver class. SO I developed a spfx solution that attaches event listeners to html elements. I attached the event listeners on the links to a file I was able to call a function regarding this however I need to log those who viewed the event in a database.


You can create a list named logs, and you can add to it a new item every time a user is viewing your specified document.

Creating a new item you can achieve by javascript REST call:

// item = { __metadata: {type: SP.Data.xxxListItem }, ....} 
PostListItem = function (listName, item) {
  return jQuery.ajax({
    url: encodeURI(_spPageContextInfo.webServerRelativeUrl + "/_api/web/lists/getbytitle('" + listName + "')/items"),
    type: "POST",
    data: JSON.stringify(item),
    headers: {
        "Accept": "application/json; odata=verbose",
        "Content-Type": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val(),
        "X-HTTP-Method": "POST",


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.