Trigger EliteSofts Page View Macro through Scroll Viewport
The Page View Macro for Confluence from EliteSoft is a simple tool to track Confluence page views (including anonymous views) and can be setup to work alongside Scroll Viewport.
Implementation
The Page View Macro performs a REST Call to the following URL and hands over the ID of the current page to trigger a page view:
<base-url>/rest/page-tracking-services/1.0/page-tracking/page-view
Therefore, to track page views of visitors in your Viewport view, you need to add some code to your theme.
Firstly, you need the confluence-base-url and the ID of the current page in your theme so that you can execute the REST Call. You can save this information easily in a your HTML head like this:
XML<meta name="pageId" content="${page.id}"> <meta name="ajs-base-url" content="${baseUrl}">
Next, you need to do the REST Call to Confluence and the Page View Macro. To do this you need to grab the content of both meta-tags. The best way to do this, is to integrate the REST Call in an external JavaScript file with jQuery which is referenced in your theme:
JS$(document).ready(function() { var pageId = $('meta[name="pageId"]').attr('content'); var baseUrl = $('meta[name="ajs-base-url"]').attr('content'); var url = baseUrl + "/rest/page-tracking-services/1.0/page-tracking/page-view"; $.ajax({ url: url, type: 'PUT', data: {'pageId': pageId} }); });
This means we get the information of previously added meta-tags and save them into variables.
After this, you need to create the required URL and perform the REST Call with the ID of the page as a parameter.