Hi,
I initially posted a reply to the thread #2503 but I think it deserves its own thread
I have some requirements for a custom development, and I need to fetch the count of views of a modern page in my SPFx WebPart. I did some search but haven't found anything relevant so far...
Does anyone know if there is any official API to fetch this value, or at least can anyone tell where (or how) it should be fetch (maybe using the search API ?)
Best regards,
Yannick
It should have not specific official API for your requirement.
https://some-SharePoint-online-tenant.sharepoint.com/_api/search/query?querytext='*'&rowlimit=10&sortlist='viewsrecent:descending'
_api/search/query?querytext='ContentType:News*+path:YourSiteURL/'&selectproperties='Title,path,ViewsLifeTime,ViewsLifeTimeUniqueUsers'Hi @Seiyasu,
A great THANK YOU, exactly what I am looking for, I admit I am not an expert in Search API, I've seen this when googling but only with the ViewsLifeTime property that its value didn't match the number of views displayed in the modern page ! I was really confused !
You rock, thanks again !
[EDIT] Just out of curiosity where did you find the "ViewsLifeTimeUniqueUsers" property ?
Even the Search Query Tool only gives me the ViewsLifeTime...
Hi @Seiyasu, Can you please provide more info on below ?
a. Why do we need to enable ‘Queryable’ and ‘Searchable’ for ViewsLifeSpan. I believe 'Retrievable’ should suffice ? Also, settings for this managed property are greyed out.
b. Why full crawl ? Continuous crawl wouldn't update this ?
Thank you for your time
@jashwanthreddyn
a. Why do we need to enable ‘Queryable’ and ‘Searchable’ for ViewsLifeSpan. I believe 'Retrievable’ should suffice ? Also, settings for this managed property are greyed out.
If you set a managed property to be searchable, the content is added to the index. This means that a simple query for "Smith" returns items that contain the word "Smith" and also items whose "author" property contains "Smith". If you want users to be able to "only search for items that have this specific author", set the author property to be queryable. Then, to find only items that have an author named Smith, users can query for "author:Smith".
If you want to prevent the content in a managed property from showing up as search results, you can disable the retrievable setting for the managed property.
https://docs.microsoft.com/en-us/sharepoint/manage-search-schema
For some case, you just use Retrievable is OK too.
b. Why full crawl ? Continuous crawl wouldn't update this ?
I haven't try just use the continuous crawl. Just my understand, the continuous crawl is called too often, use the full crawl with rules when we need to crawl, then update the index is enough, there is no need to run the continuous crawl in many case. https://social.technet.microsoft.com/wiki/contents/articles/15571.sharepoint-2013-continuous-crawl-and-the-difference-between-incremental-and-continuous-crawl.aspx
Hi guys,
Allow me to reopen this issue, actually yesterday morning the number seemed to match but then in the afternoon any value I could fetch from the Search API (that seem to relate to page views) don't match the value displayed in the modern page !!


I don't know if the Modern Page uses some caching or uses another property to display...
Anyway, the information displayed to the user would be inconsistent between my custom dev and the modern page...
Does anyone know further about it? another property to use? another technique to fetch or compute the value displayed in the modern page ?
Best regards,
Yannick
Hi Yannik,
I had done some analysis on this as we had the same need as you (and I created #2503).
We had also open Microsoft ticket. Below is the details got from Microsoft support,
You created/edited a modern web part using the managed properties ViewLifeTime, ViewLifeTimeUniqueUsers and ViewsRecent, are not the same properties used within the Social bar, that is using a different source. The reason of this behavior is that, classic usage and modern (on the social bar) are from two different sources and we cannot make any comparison between each other.
So, technically its stored or processed from different places. Search query gets it from Search index,
But In Social bar Page view, it basically uses Microsoft Internal api (based on fiddler traces ) to fetch Page views (not sure where/how it is being processed).
As per the information received by Microsoft support, Microsoft api which fetches Social bar Page view count is not Public api (at least for now), so there is no Official documented api present yet. I am yet to add a User voice for this (I will do it soon).
Another Interesting fact is that, OOTB News web part also shows Page view count. When I checked the fiddler traces, It basically uses Search query to fetch News pages, but to fetch View count it uses Microsoft internal api again. So OOTB news web part apparently not use Search Managed property (ViewLifeTime, ViewLifeTimeUniqueUsers).
Thanks,
Guru
Hi @gurubn,
Exactly what I supposed and why I initially posted this issue...
I suppose I (and my customer) will have to wait for an officially supported API to meet this need.
I voted the UserVoice :)
Many thanks for your help and feedback !
You should also take a look at these new Beta Microsoft Graph APIs that will likely be what you want long term:
https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/itemanalytics_get
Hi Jeremy,
Thanks for the info, unfortunately it doesn’t help on immediate term since it is beta, but a least I know what to watch for my customer’s needs :)
Thanks a lot!
Closing as an entry which has now a user voice entry and also upcoming API from Graph.
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues
Most helpful comment
You should also take a look at these new Beta Microsoft Graph APIs that will likely be what you want long term:
https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/itemanalytics_get