Events

How to handle events in Clerk.js.

Events enable you to hook in to the rendering process of Clerk.js.

EventFired
after-callRight after the response has been returned from the Clerk.io API.
before-renderRight before the rendering process begins.
after-renderRight after the rendering process has occurred.
on-errorOn any error.

Example use of an event-handler:

<span class="clerk" data-template="@popular-products" data-after-render="logProducts"></span>

<script>
  function logProducts(data) {
  	console.log(data.response.result);
  }
</script>

Each event calls the event handler with an event object with the following form:

{
  api: "recommendations/popular",
  args: {
    key: "your_api_key",
    limit: 10,
  },
  template: "#clerk-product-template",
  target: "#popular-products",
  response: {
    "status": "ok",
    "result": [123, 456, ... 890],
    "product_data": [{"id":123,"name":"Lightsaber",... "price":22.00}],...
  }
}
{
  api: ... ,
  args: ... ,
  template: ... ,
  target: ... ,
  response: ...
}
EntryContent
apiThe API endpoint of the request.
argsThe parameters of the request.
templateThe template to be used.
targetThe target where the products will be rendered.
responseThe full response object from the API.