skip to Main Content

Javascript Persoo client is realized by function persoo() from the persoo.js library.

Either you load persoo.js synchronously, or you use Persoo js snippet to load it asynchronously. Snippet will create temporarily function is persoo() is available immediately and stores all commands in a queue until persoo.js library is asynchronously loaded from the CDN. After Persoo loading, all the commands from the queue processed and all future commands are processed immediately.

Javascript Client Methods

All methods are called in the format persoo('<commandName>', <arguments>).

send(eventName, params, callback) – report data to the server and get a RTP response

Each server call sends an event with the following parameters:

  • eventName – event name. Some events have special significance, other can be user-defined. If you don’t specify the event name, “pageview” will be filled in by default.
  • object with params/context – an object with the event parameters. It contains the event parameters as name-value pairs. This data will be accompanied by the data from dataLayer, that were changed since the last event (in the case more than 1 is sent).
  • callback – function called in the moment the data from the server arrive. This function has 1 argument called “data”, which is the data returned by the server.
The event response contains:

  • data – data related to the event. E.g. IDs of the recommended products for each scenario, or custom data from the visitor profile.
  • functionCalls – calling of JS functions. Generally involves something in the sense “render content X in location Y”, or “report custom dimension to Google Aanalytics”.
  • exceptions – exceptions that occurred when processing the event and it’s workflows (user-defined variables and functions are often the reason for an exception). It’s possible to use the templating language, which can also return an exception.
  • debug – debugging info if the debug mode is on

onLoad(callback) – calling the function after getting an RTP response

When the Persoo client receives a response, it can call your handler. This is equivalent to calling a callback in the event call. This onLoad allows for calling more than one callback.

Data given by the server is served as the first parameter of the handler. Calling onLoad is related with the previous “send” request. For example:

This will call “onLoadHandler1” when the response to “event1” comes, and then “onLoadHandler2” is called when the “event2” response arrives.

It is not strange that the onLoad is send after the “send” command, since it’s processed asynchronously.

onError(callback) – if the client fails to get a response from the server

Persoo client will call your handler if there is a problem with the communication with Persoo server (network problems, server timeout…)

Handler yourOnErrorFunction does not have a parameter.

onEachLoad(callback) – runs a function with each received RTP response

You can register this handler, so you don’t have to append a callback or onLoad for each “send” request:

This function will be run after each “event” response arrives.

on browser events callbacks

persoo(callback) – calling a function after the persoo.js is loaded

Persoo client calls yourFunction() when the persoo.js  is loaded and the command queue begins processing. Other methods become available at this moment (onDOMContentLoaded etc.)

onLocationsRendered(callback) – calling a function after all locations/Persoo boxes are rendered

Persoo client will run this function when:

  • A Persoo Server response arrives, stating that all personalized locations displayed their content (custom or default). This can happen even before DOM Content Loaded, if the personalized locations already exist in DOM.
  • If the Persoo Server response does not arrive and all locations are rendered with default content. The default timeout for this situation is 2,5s.

persoo.on(eventName, callback)

After persoo client is loaded, you can call some methods directly. Available eventNames are

  • DOMContentLoaded
  • firstRTPResponseArrived
  • locationsDone – see onLocationsRendered method

setEnvironment(envName, opt_date)

Setting the browser to a Test Environment. Information about the current environment is stored in a cookie “persooEnvironment”.


Switches the browser back to Production Environment.

Back To Top
×Close search