Blog Post

Microsoft SharePoint Blog
3 MIN READ

How to retrieve analytics information for Pages in the "Site Pages"? using Graph Get itemAnalytics?

SPDev_Support's avatar
SPDev_Support
Icon for Microsoft rankMicrosoft
May 18, 2021

Making calls with just analytics endpoint /sites/{site-id}/lists/{list-id}/items/{item-id}/analytics will return null data as shown below:

 

{'@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.itemAnalytics',

'allTime': None,

'lastSevenDays': None}

 

Please make calls and request 'alltime' and 'lastsevendays' separately as shown below:

  • /sites/{site-id}/lists/{list-id}/items/{item-id}/analytics/alltime
  • /sites/{site-id}/lists/{list-id}/items/{item-id}/analytics/lastsevendays
 
Step 1: Retrieve all the internal SharePoint ids of the all Pages in the "Site Pages" 
 

 

Note: '190b9516-0000-0000-0000-90fe7360d416' This is the actual list GUID of your "Site Pages" library.
 
Sample Output:

{

            "@odata.etag": "\"6967cfed-0000-0000-0000-b480c1764375,3\"",
            "sharepointIds": {
                "listId": "190b9516-0000-0000-0000-90fe7360d416",
                "listItemId": "1",
                "listItemUniqueId": "6967cfed-0000-0000-0000-b480c1764375",
                "siteId": "df6ba610-0000-0000-0000-ba2733d0182e",
                "siteUrl": "https://spotenant.sharepoint.com/sites/TestSite105",
                "tenantId": "d6f932a7-0000-00000-0000-b27004970776",
                "webId": "e0dbcdc6-0000-0000-0000-49aaa1ce4d37"
            }
        },
 
Step 2: Select any Pages "listItemUniqueId" retrieved in Step 1 and make following call:
 
Note: You need to make sure the site you are requesting has the "Sharepoint Viewers" feature enabled: https://support.microsoft.com/en-us/office/allow-people-to-see-who-views-their-files-or-pages-ee26dde0-c30e-4eca-b1c3-38922c450967. This is required to give you expanded actors or users information. Please see sample out put below:
 
 
Data returned below:
 
{
    "aggregationInterval""None",
    "startDateTime""0001-01-01T00:00:00Z",
    "endDateTime""0001-01-01T00:00:00Z",
    "isTrending"false,
    "access": {
        "actionCount"345,
        "actorCount"6,
        "timeSpentInSeconds"0
    },
    "incompleteData": {
        "missingDataBeforeDateTime""2018-09-21T19:20:43Z",
        "wasThrottled"false,
        "resultsPending"false,
        "notSupported"false
    },
    "activities": [
        {
            "id""00000",
            "activityDateTime""2021-04-12T17:59:12Z",
            "location": {
                "address": {
                    "city""",
                    "countryOrRegion""",
                    "postalCode""",
                    "state""",
                    "street"""
                }
            },
            "access": {},
            "actor": {
                "user": {
                    "displayName""Admin SPOTenant",
                    "email""admin@spotenant.onmicrosoft.com",
                    "id""faaa2e55-0000-0000-0000-c774a83bbbde",
                    "userType""Internal"
                }
            }
        },       
{
            "id""00001",
            "activityDateTime""2020-12-12T01:03:30Z",
            "location": {
                "address": {
                    "city""",
                    "countryOrRegion""",
                    "postalCode""",
                    "state""",
                    "street"""
                }
            },
            "access": {},
            "actor": {
                "user": {
                    "displayName""Alex Darrow",
                    "email""alexd@spotenant.onmicrosoft.com",
                    "id""e81cac19-0000-0000-0000-4c938b101a33",
                    "userType""Internal"
                }
            }
        }
    ]
}
Updated May 18, 2021
Version 10.0
  • vpatilkop's avatar
    vpatilkop
    Copper Contributor

    We have requirement, To check if document/page is viewd by particluer user or not. I'm expanding activities & using filter on actor/user/email, It give expected result, but problem is, it only give result from top 25 records only. filtering is not working on alltime records.

     

    We know this API has limitation only return top 25 records,  But at least this API should apply filter on all time records & give records if condition satisfy.

     

     I tried both V1 & Beta. But this does not satisfy our requirements.

     

    Is there any way to achive this requirement.

  • kylebigelow's avatar
    kylebigelow
    Copper Contributor

    this is awesome! however, alltime?$expand=activities seems to only return the first 24? i do not see an odata next page link, either. this would be helpful in gaining more visiblity into the SP page analytics feature which does return accurate counts for 7,30,90 days but does not include user identity info that this endpoint does 

    any other actions available here? SPDev_Support im using graph explorer beta and v1

  • Update: API only supports top 25 currently. 


    Note that the API only only returns one activity per user per type, if user accessed the document multiple times, only the latest access activity is returned. So the Action count and viewer count may not be exactly the number of activities expected to be returned by the API. 

    To include user identity info you have to turn on this feature "Sharepoint Viewers".

  • ved-leachim's avatar
    ved-leachim
    Brass Contributor

    Hello there

     

    If you need to get the analytics data for a specifig time periode (max 90 days) you have to use the getActivitiesByInterval API.

     

    If you're looking for a full-featured PS Script that takes as input a time span and a list of sites, and then outputs the UsageReports of the pages it contains as a CSV, check out the following Scritp on GitHub.