Server-side in Sitevision
Here’s an example of how you can render the questions server-side so they automatically get the correct schema and HTML structure. This ensures that your Questions and Answers can be picked up by ChatGPT and similar services.
These features are still relatively new, so we’re happy to share tips and tricks with you. In that case, email us at support@rek.ai.
Add a script module in a template where you want the questions to appear. In the JavaScript section, add the following:
// SiteVision Utils
var requester = require('Requester'); // <-- use Requester for plain text/HTML
var origin = 'YOUR DOMAIN HERE'; // <-- set your domain here
var projectID = '12341333'; // <-- set your project ID here
var secret = 'ABCDEF'; // <-- set your secret here
var predictionurl = 'https://predict.rek.ai/';
predictionurl += 'predict?p=' + projectID + '&secret=' + secret + '&nr=5&rt=html&entitytype=rekai-qna';
function start() {
try {
var reqOptions = {
dataType: 'text',
headers: {
'accept': 'text/html',
'user-agent': 'sitevision-backend-proxy',
'origin': origin
}
};
requester.get(predictionurl, reqOptions)
.done(function (body, statusCode) {
try {
out.println(body);
} catch (e) {}
})
.fail(function (message, status) {
out.println('rek.ai view failed: ' + status + ' - ' + message);
});
} catch (e) {
out.println('rek.ai catch e:' + e);
}
}
start();
In the Velocity part of the module, add the following:
<script>
$svjq(function() {
var options = {};
var questionOptions = window.__rekai.getQuestionsOptions();
questionOptions.serversideRendering = true;
window.__rekai.addCssStylesForQuestions(questionOptions);
window.__rekai.addEventListenersForQuestions(options, questionOptions);
});
</script>
Set cache for the script module
You can set the cache time for the script module to something like 5 minutes. This way, you don’t hit the rek.ai API on every page load, but still get updated questions regularly. Sitevision Cache (opens in a new tab)