Custom features
Rek.ai has 30 custom features: features 1 to 20 are floats ranging from -1 to 1 (named f1 to f20), and 10 additional features can be strings (named csf1 to csf10). Any feature that isn't used gets the value 0 or "".
You set the value of a custom feature by adding it to the page's code. For example, if you want to store whether a visitor is logged in as a Customer or a Supplier, you can use a single feature with a different value for each case:
| Circumstance | Javascript |
|---|---|
| Not logged in | window.rek_customfeature['f1'] = 0; |
| Logged in customer | window.rek_customfeature['f1'] = -1; |
| Logged in supplier | window.rek_customfeature['f1'] = 1; |
Ways to store a custom feature
Save in the window object
Custom features are saved by adding an object to window. This works well when the feature doesn't need to persist between page views but should apply globally for example, whether the visitor is logged in.
<script>
window.rek_customfeature = [];
// Check if user is a logged in supplier
window.rek_customfeature['f1'] = 1;
</script>Save in session variable
You can also save features in a session variable, optionally scoped to the project ID the feature belongs to.
The session variable must follow one of these two naming standards:
rek + featurenamnExample for setting feature f14 to 1 for project 10021005:
sessionStorage.setItem('rekf14', 1);With variable:
var key = 'rek' + 'f1';
sessionStorage.setItem(key,'1');Save to local storage
You can also save features in local storage, either with or without a project ID:
Example for setting feature f14 to 1, without a project ID:
localStorage.setItem('rekf14', 1);Example for setting feature f14 to 1, scoped to project 10021005:
localStorage.setItem('rek10021005f14', 1);Save in a cookie
If the project allows cookies, you can save a feature in a cookie that's automatically used when the visitor returns to the website. The cookie name follows the same convention as the session variable above.
<script>
var iHaveBeenLoggedInBefore =1;
function setRekCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
// Set feature 1 to value for 30 days
setRekCookie('rekf1', iHaveBeenLoggedInBefore, 30);
</script>Using custom string features
String features work the same way as the numeric custom features above, but are named csf1 to csf10 and store strings instead of floats. rek.ai encodes all values before sending them to the backend, so they can be stored like this:
// Saving features in "window"
window.rek_customfeature = [];
window.rek_customfeature['rekcsf1'] = 'Test 1';
window.rek_customfeature['rekcsf2'] = 'Test 2';
// Using session storage
sessionStorage.setItem('rekcsf1', 'Test 1');
sessionStorage.setItem('rekcsf2', 'Test 2');
// Using local storage
localStorage.setItem('rekcsf1', 'Test 1');
localStorage.setItem('rekcsf2', 'Test 2');How do I see if my custom features are sent correctly?
Open your browser's network traffic panel when a page view is sent to our backend- you'll be able to see whether your custom features were included.
