SharePoint / sp-dev-docs

SharePoint & Viva Connections Developer Documentation
https://docs.microsoft.com/en-us/sharepoint/dev/
Creative Commons Attribution 4.0 International
1.24k stars 1k forks source link

Page analytics not working #8973

Open TGiersberg opened 1 year ago

TGiersberg commented 1 year ago

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

other (enter in the "Additional environment details" area below)

Developer environment

Windows

What browser(s) / client(s) have you tested

Additional environment details

Microsoft Edge Version 113.0.1774.42

Describe the bug / error

Target scenario: Read SharePoint page analytics via graph api Approach: call /analytics/, /analytics/lastSevenDays and /analytics/allTime on site page list item, see https://learn.microsoft.com/en-us/graph/api/itemanalytics-get?view=graph-rest-1.0&tabs=http

Error: Running in graph explorer https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items/{id}/analytics with list-id being the Site Pages (retrieved via /sites/{site-id}/lists?$filter=displayName eq 'Site Pages'&$select=id)

gives null response

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#microsoft.graph.itemAnalytics",
    "allTime": null,
    "lastSevenDays": null
}

/analytics/lastSevenDays,/analytics/allTime gives itemNotFound

https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items/{id}/analytics/lastSevenDays
{
    "error": {
        "code": "itemNotFound",
        "message": "Item not found",
        "innerError": {
            "date": "2023-05-17T11:56:00",
            "request-id": "210d0197-3baa-4045-8ab5-cd71d3700441",
            "client-request-id": "c5c6d732-d977-9be4-6317-48f9c4c97597"
        }
    }
}

I have double checked permissions (delegated Sites.Read.All) and SharePoint permission levels. PageViews show up on the page itself - I must do something fundamentally wrong.

This issue came up in https://github.com/SharePoint/sp-dev-docs/issues/8947 and I was recommended to open a new issue.

Steps to reproduce

  1. Open Graph Explorer https://developer.microsoft.com/en-us/graph/graph-explorer/
  2. GET /sites/{site-id}/lists?$filter=displayName eq 'Site Pages'&$select=id to retrieve Site Pages list id (example call https://graph.microsoft.com/beta/sites/<company>.sharepoint.com:/sites/<site_name>:/lists?$filter=displayName eq 'Site Pages'&$select=id,displayName
  3. GET https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items/{id}/analytics (Example: https://graph.microsoft.com/beta/sites/<company>.sharepoint.com:/sites/<site_name>:/lists/76452593-cead-4f9e-33d2-33a18ef45a91/items/643/analytics

Expected behavior

Response something like

HTTP/1.1 200 OK
Content-type: application/json

{
    "allTime": {
        "access": {
            "actionCount": 123,
            "actorCount": 89
        }
    }
}
ghost commented 1 year ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

sangle7 commented 1 year ago

It seems the itemid should be a guid instead of the index number

TGiersberg commented 1 year ago

Provided list item identifer is not in an allowed format

finding the guid was actually a quest. Still no success.

TGiersberg commented 1 year ago

Tried this https://graph.microsoft.com/beta/sites/<company>.sharepoint.com,<guid>,<guid>/drives/<driveid>/items/<item-id>/analytics

(looking something like this in real life [I made up the guids etc]) https://graph.microsoft.com/beta/sites/mycompany.sharepoint.com,33831234-451a-4826-b9b5-4212cb64c000,c25cebb1-9f04-41d2-b2a3-d9e44489790d/drives/b!VBKCWRqZJiL5tUIcK2TAQLHrXMIEn9JBsqPJ9Caaaa0jhw73Rj84T7VxssCxIOBS/items/02FIESFL452Z6OXQB7FBF2CDZQNFF6QARX/analytics

and it still gives

HTTP/1.1 200 OK
Content-type: application/json

{
    "allTime": {
        "access": {
            "actionCount": 123,
            "actorCount": 89
        }
    }
}
sairao77 commented 9 months ago

@TGiersberg -

Try the guid value of etag for list item id in SharePoint site pages. an example https://graph.microsoft.com/v1.0/sites/$siteid/lists/$listid/items/use etag guid/analytics/lastSevenDays

I don't think this is a fix but a workaround that I have found.