Server-Side Variables

Zaraz allows you to send variables from your server as additional metadata you can later use in your Events or Triggers. By using server side rendering, server variables can be exposed to Zaraz. To do this, create a zarazData dictionary object at the <head> of your HTML, before the Zaraz loading script, and inject it with your server side variables. For example:

<script>
  zarazData = {
    z_userID: <% session.user.id %>,
    z_pageLayout: "<% response.layout %>",
    z_experimentID: <% experiment_id %>,
  };
</script>

Make sure to use the z_ prefix for your key names, and replace the <% server_side_code %> with your server templating engine syntax. Zaraz will automatically process the object, and its properties will then be available to use at the Zaraz Dashboard.