Using the Google Analytics Javascript API to show pageviews from Atlassian Confluence

Here’s a quick demo I wrote to test out the Google Analytics API.

It shows pageviews for an Atlassian Confluence wiki on a space by space basis.

You’ll need your own copy of Confluence hooked up to Google Analytics for the demo to work, so I’ve done a video demo too – no sound, sorry.

Confluence & Google Analytics Javascript API from David Simpson on Vimeo.

The main problem for listing data on a space by space basis with the Google Analytics API is that there isn’t an equivalent to the Content Drilldown report. My workaround was to get the 500 most popular pages, then using regular expressions, get the spacekeys, remove duplicates and sort alphabetically. Not particularly elegant, but hey.

Next Steps

It’s a nice proof of concept, but I’d like to display this information – without the authentication and authorisation step – to users without access to Google Analytics.
e.g. To the owners/administrators of Confluence spaces.

The next step will be to rewrite in Java and embed the data and some charts directly into Confluence with a custom written macro.

David is a senior developer and solutions architect at AppFusions based in Nottingham, England.

AppFusions solves mixed-technology integration problems. We bring engineering and business workflows together, you can work better, faster and smoother.

AppFusions is headquartered in San Francisco, California and works with enterprise vendors and partners such as IBM, Jive, Egnyte, DropBox, Box and Atlassian.

  • Ste Daniels

    Hi David,

    Did you ever get round to writing this up as a Java plugin for Confluence?

    Ste Daniels

    • David

      Ste: Not got there yet, but I’ve got the Confluence SDK installed and ready to go. Will hopefully make a start very soon.

  • Phil Wilson

    Not sure I understand why you need to convert it into Java? We embed the username and password for a non-admin account in our JS version of this. A macro would be more elegant but we’ve been bitten by API etc. changes before so use a user macro which calls some external JS which renders some PHP or Java and inserts that into the page. Goes around the houses some but is eminently portable between versions and doesn’t require specialist confluence knowledge to maintain.

    • David

      Phil: For sure, there is no need to write a custom macro. If your space owners are happy with Google Analytics or another reporting solution you’ve created, then that’s good.

      As a bit of a geek, I was really interested in getting to grips with the recently release Atlassian SDK. So I’ve created a Google Analytics reporting plugin. It gives space by space reporting, so adding the macro to the space is a very easy way to embed the usage stats for the current space without any in depth knowledge. The plugin will be documented and released very soon, but it’s already in Atlassian’s svn and Bamboo.

      Regarding changes between versions, I’m sure there are issues, e.g. in Confluence 3.1, Atlassian were talking about moving the Javascript to the end of the body for optimisation reasons. This would break a number of plugins and I think they’ve postponed doing it. No doubt I’ll become more aware of this kind of thing as future releases become available :)