Provide 24/7 affordable customer service with AI-powered chat.
Connect to learn more

Enforcing offline hours

However, there may be cases where you want to force Olark to display as unavailable even when you have available agents - for example, if you want to enforce particular off-hours in the evening.

Steps using our JavaScript API

  • You'll want to get the get the current time. The quickest way to do this is to get the visitor's browser time:
    Olark will automatically detect when you have agents available to chat.

    var now = new Date();
    var hourOfDayInUTC = now.getUTCHours();

    Be aware, however, that a visitor's browser time may not be accurate. For a more robust solution, you may wish to use your server time or find an alternative method.

  • In our case, we want to calculate the time relative to San Francisco.

    // PST is 8 hours behind GMT so we use -8. Change the -8 to
    // your timezones difference from GMT.
    var differenceFromUTC = -8;
    var currentHour = hourOfDayInUTC + differenceFromUTC;
  • Using some JavaScript if statements for our own particular use case, we can finally use the API call that forces the chat box offline in the visitor's browser:

    olark.configure("system.force_offline", true);

Important Notice: We’ll do our best to help with any questions you have. However, keep in mind that the API is intended to be self-serve for web developers, so we’re not able to write or debug your code. If you’re experiencing issues, please be sure to have your developer, designer or webmaster review code you’ve written.

Please provide the domain name where your Olark live chat is installed.
Include the relevant transcript URL, if possible. You can send us the specific URL from your Transcripts page.
If you see specific error messages, banners, warnings, notices, etc., please let us know here.
Max file size 10MB.
Upload failed. Max size for files is 10 MB.
Thank you! Your submission has been received and you'll hear from us shortly!
Oops! Something went wrong while submitting the form.