WordPress / PHP integration

1. Add the snippet to your layout

Use the async loader from the docs home.

2. Server-side user hash

<?php
$user_hash = hash_hmac('sha256', (string) $user_id, getenv('ROKOCHAT_IDENTITY_SECRET'));

3. Call identify() in the browser

Rokochat.identify({
  id: user.id,
  user_hash: userHash,
  email: user.email,
  name: user.name,
});
// In your theme header.php after wp_footer snippet
<script>
  <?php if (is_user_logged_in()) :
    $user = wp_get_current_user();
    $hash = hash_hmac('sha256', (string) $user->ID, getenv('ROKOCHAT_IDENTITY_SECRET'));
  ?>
  Rokochat.identify({
    id: '<?php echo esc_js((string) $user->ID); ?>',
    user_hash: '<?php echo esc_js($hash); ?>',
    email: '<?php echo esc_js($user->user_email); ?>',
    name: '<?php echo esc_js($user->display_name); ?>',
  });
  <?php endif; ?>
</script>

Always call Rokochat.logout() when the user signs out.