Sitevision specific

Sitevision specific

How you can add page and user information on an intranet

By using the data fields available for users in the directory, we have the capability to enhance the AI model by integrating additional functionalities.

The process involves utilizing Velocity (or any other server side code) to retrieve the necessary values, followed by embedding these values within the JavaScript code. Should there be a requirement to incorporate additional strings, it is feasible to extend the range by including identifiers from 'rekcsf1' through to 'rekcsf10'.

<!-- This part sets custom features for recommendations -->
#set ($utils = $request.getAttribute('sitevision.utils'))
#set ($user = $utils.portletContextUtil.getCurrentUser())
#set ($pu = $utils.getPropertyUtil())
 
#set ($department = $pu.getString($user, 'department', ''))
#set ($title = $pu.getString($user, 'title', ''))
#set ($physicalDeliveryOfficeName = $pu.getString($user, 'physicalDeliveryOfficeName', ''))
 
<script>
  // Feature CSF1 is a string, here you can save "avdelning"
  localStorage.setItem('rekcsf1', '$department');
 
  // Feature CSF2 is a string, here you can save "title"
  localStorage.setItem('rekcsf2', '$title');
 
  // Feature CSF3 is a string, here you can save "physicalDeliveryOfficeName"
  localStorage.setItem('rekcsf3', '$physicalDeliveryOfficeName');
</script>

Also check out: Intranet tutorials

Iterate all user properties

In order to be able to add user parameters to your ai model on an intranet, you need to know which parameters exist on each user. In Sitevision, this can be listed with a script.

Create a page with a script module and enter the following in the Javascript window.

// Get utilities in the SiteVision Public API
var utils = request.getAttribute("sitevision.utils");
var propertyUtil = utils.getPropertyUtil();
var ctxUtil = utils.getPortletContextUtil();
 
// Get current user
var user = ctxUtil.getCurrentUser();
 
// HTML Output
out.println("<table style=\"border-collapse: collapse;\">");
out.println("<caption style=\"padding:10px;\">User Attributes</caption>");
out.println("<tbody>");
out.println("<tr><th style=\"padding:10px;\">Attribute</th><th style=\"padding:10px;\">Value</th></tr>");
 
 
// Iterate user properties
var allPropertiesIterator = user.getProperties();
while(allPropertiesIterator.hasNext())
{
  out.println("<tr>");
  try {
    var property = allPropertiesIterator.nextProperty();
    var pName = property.getName();
    var pValue = propertyUtil.getString(user, pName, "null");
    out.print("<td style=\"padding:10px;border:1px solid #cccccc;\"><b>" + pName + "</b></td>");
    out.print("<td style=\"padding:10px;border:1px solid #cccccc;\">" + pValue + "</td>");
  } catch (e) {
    out.println("Exception occurred: "+ e);
  }
  out.println("</tr>");
}
out.println("</tbody>");
out.println("</table>");
 
var userType="";
try {
  userType=propertyUtil.getString(user, "employeeType", "null");
} catch (e) {}
out.println("<h3>"+userType+"</h3>");

When you know what parameters that exists you can add them to custom features

Control whether a certain IP should not be saved as a page view

It may be that you want to avoid the employees' page views being included when saving page views.

You can do that by checking the IP in Velocity before running the script to save.

#set ($utils = $request.getAttribute('sitevision.utils'))
#set ($clientUtil = $utils.getClientUtil())
#set ($dontAddThisIP = '1.2.3.4')
 
#if ($clientUtil.getClientAddress() == $dontAddThisIP)
  <script>
    window.rek_blocksaveview = true;
  </script>
#end

Use IP number as a custom feature

If you want to be able to distinguish an employee and thus give them better recommendations, you can easily use your IP as a custom feature.

This means that you set custom feature 1 to the number 1 if the current visitor has the same IP as all employees.

#set ($utils = $request.getAttribute('sitevision.utils'))
#set ($clientUtil = $utils.getClientUtil())
#set ($employeeIP = '1.2.3.4')
 
#if ($clientUtil.getClientAddress() == $employeeIP)
  <script>
    window.rek_customfeature = [];
 
    // Custom feature 1 is for employee
    window.rek_customfeature['f1'] = 1;
  </script>
#end

How to use Cookie banner together with the rek.ai Sitevision module?

Info: Rek.ai does not use cookies unless you as a customer have made an active choice. Rek.ai uses local storage and session storage to save data.
Conditions:
You userek.ai modules from sitevision marketplace
You have installed the Cookie banner module from sitevision markeplace. (Read about how yougetting started with the Cookie banner module)

Step 1

Open the Cookies panel which you will find under Website Settings

step 2

Select "Add cookie" under the category "Analytical cookies"

Step 3

Fill in the form with the following information

  • Name:rek.ai
  • Identifier: rekai
  • Description:Optional descriptive text

Step 4

Save & publish.

Now rek.ai will automatically wait to save information in localstorage and session storage until the user has approved cookies.

Proxy code for SiteVision

You can create your own proxy in SiteVision.

You do this by creating a new public page with a Script module. In the Javascript part of the module, you can paste the code below. Then follow this example but cut in the url for your newly created page.

You then tells the Javascript to comunicate with the proxy.

Feel free to contact us if you want to get started with proxy functionallity. info@rek.ai

window.rek_customsettings.proxypredict = '/page.html';
window.rek_customsettings.proxyview = '/page.html';

Code to clip into your proxy module:

// SiteVision Utils
var utils = require('Utils');
var endecUtil = utils.getEndecUtil();
var requester = require('JsonRequester');
var logUtil =require('LogUtil');
var origin = 'https://YOURURL.se';
 
var addGeo = true;
 
// The url:s in our system for prediction and saving data
// Be sure this url is not blocked by firewall
var predicturl = 'https://predict.rek.ai/predict';
var viewurl = 'https://view.rek.ai/view';
 
 
var reqOptions = {
  dataType: 'json',
  contentType: 'application/json',
  headers: {
    'content-type': 'application/json',
    'User-Agent': '',
    'origin': origin
  },
};
 
// Debugg function
function pr(s){out.println(s + "<br>");}
 
// Gets the json body from request
function getBody() {
  return Packages.org.apache.commons.io.IOUtils.toString(request.servletRequest.getInputStream(),Packages.org.apache.commons.io.Charsets.UTF_8);
}
 
// Gets the json body from request in JSON-format
function getBodyAsJSON() {
  var body = getBody();
  return JSON.parse(body);
}
 
// Get a request parameter
function getQueryParam(name, defVal) {
  var p = request.getParameter(name);
  if (p) {
    return p;
  }
  if (defVal !== 'undefined') {
    return defVal;
  }
  return null;
}
 
// Get alla parameters from querystring
function getAllGETParameters() {
  var query = '?';
  var enu = request.getParameterNames();
 
  while(enu.hasMoreElements()){
    var paramName = enu.nextElement();
    query += paramName +'='  + encodeURIComponent(request.getParameter(paramName)) + '&';
  }
  // Remove last '&'
  query = query.substring(0, query.length - 1);
  return query;
}
 
// Function addGeoTo JSON
function addGeoToBody(body) {
  if(addGeo) {
    body.co = 'TEST';
    body.ci = 'TESTCITY';
    body.di = 0;
  }
  return body;
}
 
// Function add geo Parameters
function addGeoToParameters(parameters) {
  parameters +='&co=TEST&ci=TESTCITY&di=0';
  return parameters;
}
 
// Function secretUuid JSON
function addUuidToBody(body) {
  if(addGeo) {
    body.uuid = secretUuid;
  }
  return body;
}
 
// Function secretUuid Parameters
function addUuidToParameters(parameters) {
  if(addGeo) {
    parameters +='&uuid' + secretUuid;
  }
  return parameters;
}
 
// Start
function start() {
  // Check if there is a 'p' parameter in the request, then it is a predict
  // Predict by GET
  if(getQueryParam('p', '') != '') {
    var parameters = getAllGETParameters();
 
    if(addGeo) {
      parameters = addGeoToParameters(parameters);
    }
 
    predicturl += parameters;
 
    requester.get(predicturl, reqOptions)
    .done(function(result, statusCode) {
      out.println( JSON.stringify( result ) );
      logUtil.debug('rek.ai prediction returned');
    })
    .fail(function(message, status) {
      logUtil.error('rek.ai prediction failed');
    });
  }
  // Send view as POST
  else {
    try {
      var inputBody = getBodyAsJSON();
 
      if(addGeo) {
        inputBody = addGeoToBody(inputBody);
      }
 
      // Add body
      reqOptions.data = JSON.stringify(inputBody);
 
      requester.post(viewurl, reqOptions)
      .done(function(result, statusCode) {
        out.println( JSON.stringify(result) + ' ' + statusCode);
        logUtil.debug('rek.ai view saved');
      })
      .fail(function(message, status) {
        logUtil.error('rek.ai view failed');
      });
    }
    catch(It is) {
      logUtil.error('rek.ai catch 1 e:' + e);
    }
  }
}
 
start();