Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for fetching Modern Page views count #2808

Closed
1 of 4 tasks
ypcode opened this issue Oct 23, 2018 · 12 comments
Closed
1 of 4 tasks

API for fetching Modern Page views count #2808

ypcode opened this issue Oct 23, 2018 · 12 comments
Labels
area:other Category: unknown (does not fit any other category) type:question Question... if answered, will be tagged as such. type:uservoice-request Enhancements & feature requests should be posted: http://aka.ms/sp-dev-uservoice

Comments

@ypcode
Copy link
Contributor

ypcode commented Oct 23, 2018

Category

  • Question
  • Typo
  • Bug
  • Additional article idea

Observed Behavior

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

@VesaJuvonen VesaJuvonen added type:question Question... if answered, will be tagged as such. area:other Category: unknown (does not fit any other category) labels Oct 23, 2018
@Seiyasu
Copy link
Contributor

Seiyasu commented Oct 24, 2018

It should have not specific official API for your requirement.

  1. You can use SharePoint 2013 Search Query Tool to generate REST queries on the fly and refine searches

https://some-SharePoint-online-tenant.sharepoint.com/_api/search/query?querytext='*'&rowlimit=10&sortlist='viewsrecent:descending'

  1. You can you the search API to implement this too.
    _api/search/query?querytext='ContentType:News*+path:YourSiteURL/'&selectproperties='Title,path,ViewsLifeTime,ViewsLifeTimeUniqueUsers'
    ViewsLiftTime is a managed property in search service application, it will update after the search service application did a full crawl. Please enable the "Query" and "Search" property for the ViewsLifeTime managed property first.

@ypcode
Copy link
Contributor Author

ypcode commented Oct 24, 2018

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...

@ypcode ypcode closed this as completed Oct 24, 2018
@jnimmala
Copy link

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

@Seiyasu
Copy link
Contributor

Seiyasu commented Oct 25, 2018

@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

@ypcode
Copy link
Contributor Author

ypcode commented Oct 25, 2018

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 !!

image

image

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

@ypcode ypcode reopened this Oct 25, 2018
@gurubn
Copy link

gurubn commented Oct 25, 2018

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

@ypcode
Copy link
Contributor Author

ypcode commented Oct 25, 2018

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 !

@JeremyKelley
Copy link

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

@ypcode
Copy link
Contributor Author

ypcode commented Oct 25, 2018 via email

@VesaJuvonen VesaJuvonen added the type:uservoice-request Enhancements & feature requests should be posted: http://aka.ms/sp-dev-uservoice label Nov 20, 2018
@VesaJuvonen
Copy link
Contributor

Closing as an entry which has now a user voice entry and also upcoming API from Graph.

@msft-github-bot
Copy link
Collaborator

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

@SharePoint SharePoint locked as resolved and limited conversation to collaborators Jan 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:other Category: unknown (does not fit any other category) type:question Question... if answered, will be tagged as such. type:uservoice-request Enhancements & feature requests should be posted: http://aka.ms/sp-dev-uservoice
Projects
None yet
Development

No branches or pull requests

7 participants