This article contains steps for resolving the “ViewsAnalyticsRestricted” PermissionException that can be thrown when querying the ViewsAnalytics and ViewersAnalytics Views once a connection to Confluence has been established.
The exact error message appears as follows when querying these Views:
s403] com.atlassian.confluence.api.service.exceptions.PermissionException: {"reason":"ViewAnalyticsRestricted"}
The error comes directly from the User configured in the connection not possessing Analytics Permissions for a specific space in the Confluence organization. Even if the configured User is registered as an Org Admin in Atlassian and present on all spaces with Analytics Permissions, it may still not have the appropriate permissions for viewing the analytics data in one or more Confluence spaces.
Note that Analytics Permissions of a Confluence space can only be configured in the Premium and Enterprise plans of Confluence. This feature is not available in any other Confluence plans.
This error may be resolved by locating the space in Confluence and reconfiguring its permissions for viewing analytics, which can be accomplished in two ways. The more direct method is to identify directly which space is causing the error by enabling logging and observing the page that the failing HTTP request attempts to query. Alternatively, the error can also be resolved by manually going through each space on Confluence and ensuring that the configured User has the permission to view analytics. In this article, I will first outline the more direct method, since it provides helpful insight on carrying out the alternative method.
Locating the Confluence Space Directly by Reading Log Files
To start, configure logging in the edition of the Confluence connector/solution being used, and ensure that Verbosity is set to 3. Next, execute the query that creates the failure to generate log files.
Open the generated log files and search for the “ViewAnalyticsRestricted” error message. Generally, the error is found at the very end of the log file.
Once the error has been located, the HTTP headers of both the failure request and response can be seen. Below is an example of this in my log files opened in Notepad++:
Here, the ID of the page can be found by observing the endpoint in the GET method within the HTTP headers of the request. The endpoint will always be either of the following, depending on which View is being queried:
/wiki/rest/api/analytics/content/<PageID>/views?fromDate=<CurrentDate> (if querying ViewsAnalytics)
/wiki/rest/api/analytics/content/<PageID>/viewers?fromDate=<CurrentDate> (if querying ViewersAnalytics)
In my example, I am querying the ViewsAnalytics View. My endpoint appears as follows:
/wiki/rest/api/analytics/content/2294025/views?fromDate=2024-07-06
This means that the page ID causing the failure in my example is 2294025.
Now that the page ID is found, the space that the page is tied to can easily be located by visiting the following page information link:
https://<YourSiteName>.atlassian.net/wiki/pages/viewinfo.action?pageId=<PageID>
The space that the page is under can be found by viewing the sidebar on the left, as shown in the screenshot below (note that I have blurred the name of my example space):
This means that the appropriate space has been located that has restricted Analytics Permissions.
An Alternative Method to Locating the Confluence Space Directly
The alternative method to locating the space directly is to simply look through each space on Confluence and ensure that the User account configured in the connection has the appropriate permissions for viewing analytics. This can be ensured by following the steps outlined below.
Configuring Permissions of the Confluence Space
Regardless of the method chosen of identifying the space, the permissions settings of the space will need to be modified. To do this, click Space settings on the left sidebar, then scroll down to find the Space permissions card under the Settings section and click Analytics Permissions.
From here, choose whether viewing analytics should be restricted for the specific space. Should it be chosen to be restricted, ensure that the User account configured in the Confluence connection has permission to view analytics by typing its account name in the search bar and selecting it.
The below screenshot shows the viewing analytics restricted on my example space with permission granted to view the analytics for my account:
The configured User account should now have access to view analytics, thus resolving the error.
I hope that this helps! Please feel free to reach out to [email protected] if further assistance is needed.