0

Good day, I have SP list. I must get this list items usage data for 2020 year. This is 2020 year statistics about list items viewing. I can show popularity trends on page by managed properties ViewsLastMonths1, ViewsLastMonths2, ViewsLastMonths3 https://tantumpoint.wordpress.com/2017/10/03/sharepoint-search-get-usage-data-from-search/ But how can I get information about views last 6 months or 12 months ? Is it possible to create managed property ViewsLastMonths6 or ViewsLastMonths12 ? My script

<script type="text/javascript">
$(document).ready(function () {
 
 var titleLabel=[];
 var titleView=[];
 
 $.ajax({
 url: "<MY SITE>/_api/search/query?querytext='Path:<MY SITE>/Lists/1/+ContentClass:STS_ListItem+ContentClass:STS_ListItem_DocumentLibrary'&selectproperties='Title,path,ViewsLifeTime,ViewsLastMonths3,ViewsLastMonths3Unique'&rowlimit=5000",
 
 type: "GET",
 headers: {
 "Accept": "application/json;odata=verbose"
 },
 success: function(data) {
 //log the json to analyze and visualize

 var items=data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results;

 //log the actual 10 items that is going to be displayed
 //console.log(items);
 
 var i=0;
 
    var data = [];
 
 $.each(items, function(index, item) { 
 
 var ret= items[index].Cells.results[6].Value;
 
 var title = keyValue(this, 'Title');
 
  var ViewsLastMonths3 = keyValue(this, 'ViewsLastMonths3');
  
   var ViewsLastMonths3Unique = keyValue(this, 'ViewsLastMonths3Unique');
 
 
 //replacing any spaces in the URL
 var itemlinks= ret.replace(/ /g,"%20");

            data.push({title: title, ViewsLastMonths3:ViewsLastMonths3, ViewsLastMonths3Unique:ViewsLastMonths3Unique, itemlinks:itemlinks});
 });
 
 
 // To show 10 most popular items last 3 Months
 data.sort(function(a, b){  
    return b.ViewsLastMonths3-a.ViewsLastMonths3
    })
  $.each(data, function(i,v){
      if (i<10){
             titleLabel.push(v.title);
         titleView.push(v.ViewsLastMonths3);
         $('#popular tr:last').after('<tr><td><a target="_blank" class=itemtitle href='+v.itemlinks+'>'+v.title+'</a></td><td>'+ v.ViewsLastMonths3 +'</td><td>' + v.ViewsLastMonths3Unique + '</td></tr>');
         i++;
      }
});
 
}
 });
 
 
    function keyValue(row, fldName) {
        var ret = null;
        $.each(row.Cells.results, function () {
            if (this.Key == fldName) {
                ret = this.Value;
            }
        });
        return ret;
    } 
 });
 
</script>
2
  • Which version of SharePoint are you using? Commented Feb 1, 2021 at 12:53
  • SharePoint 2016
    – Anonymous
    Commented Feb 1, 2021 at 13:27

1 Answer 1

0

Those statistics are only kept for 90 days by default. You can update the value with PowerShell.

https://social.technet.microsoft.com/Forums/office/en-US/1cd8d0e1-82f7-4472-be77-de02ded1ebf0/sharepoint-2013-audit-log-and-max-period-for-retention?forum=sharepointgeneral

1
  • Thanks for reply, but then I don't understand, how can SharePoint create Audit Log Report for custom Date range if it keeps statistics 90 days only? I say about Site Collection Administration -> Audit Log Reports -> Executing a custom report. For example, I can create this Audit Report for May 2020. I must show this information on Sharepoint Page for all users.
    – Anonymous
    Commented Feb 2, 2021 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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