Reputation: 11
I am working with Confluence Data Center in an on-premises environment and I'm looking for a way to access the number of views for specific pages programmatically. I've been searching through the Confluence documentation, and even though there is an API endpoint for the Cloud version, I haven't found a clear solution for Data Center installations.
I appreciate any insights or code snippets that can point me in the right direction. Thank you!
Upvotes: 1
Views: 232
Reputation: 99
I was also searching for solution, but could find only one with SQL-query on server-side (see the description linked below), which is however not usable in my case because I need something similar with REST API:
Update 1: The way described in comment linked below is useful with Rest-API (it gets statistic for a confluence-space), but the access to this interface might be restricted for certain user(s) (it was a case by me, so I can't get the statistic in this way):
Example of the REST-API url (replace the values starting with YOUR_ there with correct ones):
https://YOUR_SERVER/rest/confanalytics/1.0/space/paginated/contentViews?spaceKey=YOUR_SPACE&fromDate=%222001-01-01%22&toDate=%222050-01-01%22&type=total&period=month&timezone=%22CET%22&content=page&limit=100&sortField=VIEWED_COUNT&sortOrder=DESC
Update 2: A way of getting statistic for single page was shown in comment linked below (however also here the access to the interface might be restricted by usual user):
Example of REST-API link to get total count of views by single page (defined by its ID):
https://YOUR_SERVER/rest/confanalytics/1.0/content/viewsByDate?contentId=YOUR_PAGE_ID&contentType=page&fromDate=%222000-01-01%22&toDate=%222050-01-01%22&type=total&period=month&timezone=%22CET%22
Update 3: Finally I found solution, which works in my case. It retrieves the count of total page-views in a pretty small request/reply. I assume - the "page-tracking-services" should be enabled/active by the Confluence instance:
https://YOUR_SERVER/rest/page-tracking-services/1.0/page-tracking/update-view?pageId=YOUR_PAGE_ID&skipCount=True
The count being returned as value of v parameter in the reply.
Note: The skipCount should be set to True (see above), otherwise the count of page-views will be incremented by each call of the url.
Upvotes: 0