Validate user access
To ensure that users have the necessary permissions to access the recommended pages, a script can be implemented to filter the recommendations. This script, hosted on a page on your website, processes all recommendations, filters out those the visitor doesn't have permission to access, and returns the remaining recommendations.
Rek.ai includes a built-in function that sends all recommendations to this page. However, it's important to configure the page's "endpoint" correctly for this to work.
Want this validation applied to search too? This same check can also be used for autocomplete search results, see Add to search (opens in a new tab).
Sitevision
The following is a guide to implementing this function in Sitevision. It can also serve as a reference for other content management systems (CMS) that need similar functionality.
Start by creating a hidden page on your website and adding a script module to it. In the script module, add the following code to the Javascript tab:
var rsLocator = require('ResourceLocatorUtil');
function start() {
var outputCheckedIds = '';
try {
// Array to return to front end with ids that user has access to
var idsWithAccess = [];
// Iterate parameters to find the array
var reqS = request.getParameterMap().keySet();
var itr = reqS.iterator();
while (itr.hasNext()) {
var key = itr.next();
// Correct parameter
if(key.indexOf('ids') > -1) {
var parsedKey = JSON.parse(key);
// Parsed array of ids to check acces for
for(var i = 0; i < parsedKey.ids.length; i++) {
var pageid = parsedKey.ids[i];
// Check this id
if (rsLocator.getNodeByIdentifier(pageid)) {
// User has access to page, so add to array
idsWithAccess.push(pageid);
}
}
}
}
// All parameters iterated. Transform array to string
outputCheckedIds = JSON.stringify(idsWithAccess);
}
catch(e) {
out.println(e);
}
out.println(outputCheckedIds);
}
start();Then find out which address the newly created module got. Right-click it and select Information under Properties.
Now you can specify, for each recommendation, that links should be checked before they're displayed. To do this, add data-verifyurl, using the URL but replacing ".html" with ".json":
<div class="rek-prediction" data-verifyurl="/2.219e24b4172a2493ff21/12.24639b92184b91ba68116d.json"></div>Validate when using the Sitevision module
Using the advanced field, you can add this parameter to control validation. All recommendations will then be validated before they're displayed.
Validate in search
If you want to use validation for keyword suggestions, you can't activate it via Global Settings- instead, do it with scripts (opens in a new tab). Then add the verification address as a parameter.
Example:
<script src="https://static.rekai.se/files/sv-autocomplete.min.js"></script>
<script>
svDocReady(function() {
$svjq(".sv-searchform-portlet input[name='query']").rekAutoComplete({ // ID for the search input field
params: {
verifyurl: '/2.219e24b4172a2493ff21/12.24639b92184b91ba68116d.json'
}
});
});
</script>