user7680924
user7680924

Reputation: 11

How to Access Number of Views for Pages on Data Center (On-prem) Confluence?

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

Answers (1)

Dr.CKYHC
Dr.CKYHC

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:

https://confluence.atlassian.com/confkb/retrieve-all-pages-with-last-view-date-with-total-view-count-1167703041.html

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):

https://jira.atlassian.com/browse/CONFSERVER-76071?focusedId=3450180&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-3450180

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):

https://community.atlassian.com/t5/Confluence-questions/Tell-me-the-query-syntax-that-track-confluence-page-views-of-a/qaq-p/1977437

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

Related Questions