Table of Content

    Introduction to JavaScript API

    • July 22, 2025
    • 1 mins read

    Table of Content

      REVE Chat’s API allows you to customize the visitor experience dynamically by setting attributes like the visitor’s name, email, or other details before starting a chat.

      Basic API Setup

      Before you can use any ReveChat API methods, you’ll need to include and initialize the ReveChat widget on your website.

      Here’s the basic snippet you should add to your webpage before the closing </body> tag:

      <script type="text/javascript">
        window.$_REVECHAT_API || (function(d, w) {
          var r = $_REVECHAT_API = function(c) { r._.push(c); };
          w.__revechat_account = "3577764"; // Replace with your ReveChat account ID
          w.__revechat_version = 2;
          r._ = [];
          var rc = d.createElement("script");
          rc.type = "text/javascript";
          rc.async = true;
          rc.setAttribute('charset', 'utf-8');
          rc.src = (document.location.protocol === 'https:' ? 'https://' : 'http://') +
            'static.revechat.com/widget/scripts/new-livechat.js?' + new Date().getTime();
          var s = d.getElementsByTagName('script')[0];
          s.parentNode.insertBefore(rc, s);
        })(document, window);
      </script>

      This snippet loads the REVE Chat widget and makes the API available through $_REVECHAT_API.

      Example: Set Visitor Name

      Once the widget has loaded, you can set the visitor’s name using the following code:

      <script type="text/javascript">
        $_REVECHAT_API(function() {
          $_REVECHAT_API.Form.Online.setName("John");
        });
      </script>

      Make sure this script runs after the initialization snippet above.

      Complete Example

      Here’s the full example with both the widget loader and the API call together: html Copy Edit

      <script type="text/javascript">
        window.$_REVECHAT_API || (function(d, w) {
          var r = $_REVECHAT_API = function(c) { r._.push(c); };
          w.__revechat_account = "3577764"; // Replace with your ReveChat account ID
          w.__revechat_version = 2;
          r._ = [];
          var rc = d.createElement("script");
          rc.type = "text/javascript";
          rc.async = true;
          rc.setAttribute('charset', 'utf-8');
          rc.src = (document.location.protocol === 'https:' ? 'https://' : 'http://') +
            'static.revechat.com/widget/scripts/new-livechat.js?' + new Date().getTime();
          var s = d.getElementsByTagName('script')[0];
          s.parentNode.insertBefore(rc, s);
        })(document, window);
      
      
        $_REVECHAT_API(function() {
          $_REVECHAT_API.Form.Online.setName("John");
        });
      </script>
      

      Replace "John" with the dynamic name of your visitor if you want to set it programmatically (e.g., from your logged-in user’s name).

      If you need further assistance or have any questions about using the API, our support team is here to help. Email us at: [email protected]

      AUTHOR’S BIO

      Mohaimin Talha is a seasoned Product Manager, known for his ability to combine creativity with analytical thinking. His strategic vision and customer-centric approach make him a key driver of product success and business growth.

      0:00 / 0:00