Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,365,162
Community Members
 
Community Events
168
Community Groups

Access page views from a groovy script

Edited

Hi,

I would like to add a label to all the pages which did not get any view in the past year. I intend to use scriptrunner to automate that process, which lets me access Confluence through the groovy API.

I have been digging in the javadoc to find out how to access the page views for a given page, but I have not been successful.

It seems, however, that this data would be available through the rest API, but I do not know how to invoke it from groovy (and I am afraid of the potential performance issues).

How can I achieve my goal? Is there a way to access the number of views through the groovy API? Is there a different, simpler way way to label those pages automatically?

Thank you!

1 answer

1 accepted

1 vote
Answer accepted

Unfortunately, view page data is not captured by Confluence itself, let alone is it available through the REST API.

You'd have to start capturing page views.

You can turn on Analytics, get another plugin, or do some fancy coding with database table updates.

If you've got Confluence capturing the page view data somehow, then:

Analytics has this Java API. You could start with that. Not sure if it'll give you all you need.

If you go to the Developer Tools Console in your web browser (hit F12) and visit a space's Activity page, you'll see a whole lot of mess. Perhaps you can interpret it, but good luck with that. There doesn't seem to be an easy, obvious API or code call there, other than this:

<myconfluence>/spaces/usage/report.action?key=ABC&period=week

which returns HTML and not even the data you want.

If you go the plugin route, it might have a REST API.

If you're doing fancy coding, then hats off to you.

One other thing you can try is the Confluence REST API Browser and see if you see anything analytic in there. Unfortunately, the version never seems to be the right fit for our instance, so I can't check for you. If you see CONFSERVER-76071, the REST API Browser does show the analytics REST API calls.

PS That REST API you linked to is for Cloud.

One more thing (promise), if you're a digger, you may want to explore this Java API: com.atlassian.confluence.api.impl.service.event.mau. Although the Impl one is, I think, only for Atlassian internal use, and it's a stretch at best, but that's what captures user activity and sends it to analytics.

Thank you for the extensive answer. It is a bit disappointing to discover that this data is not exposed to the api user... I will report here if I find a solution.

Like WW likes this

After digging down the rabbit hole, I have an idea that could work: Leverage scriptrunner to write my own page tracking.

I know it sounds crazy, but with a Custom Event Listener, it does not look too complicated: basically, one can listen for the PageViewEvent. The modified Page should be available through this event, and pages happen to be instances of ContentEntityObject, which Confluence lets you associate with arbitrary content. So I should be able to store the date of the latest view for a page directly in Confluence, the same way a regular plugin developer does.

Then I am unsure how to proceed yet:

  • A possible way would be to periodically run a script that lists all pages, and for each of them, retrieves the date of the last page view and labels those for which this date is too old. While it would work, I am not in love with the potential performance problem generated by looping over all the pages of our Confluence instance in a single batch, every time the script runs.
  • Another way could be to do this in 2 steps: first write a custom search extractor which adds an index for such pages, then use the builtin CQL escalation service to label those pages. This might be the better solution, since I suspect that Confluence is going to be more clever than me in the way it schedules its indexation.

I will post here if I implement anything.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events