Ver em português
Setup guide

Hay.chat on WordPress with caching and consent plugins

WP Rocket, LiteSpeed Cache, Autoptimize, Complianz, CookieYes and the WP Consent API, with what we have and haven't tested

6 min read WordPress and WooCommerce store owners

Published

Most WordPress stores run a caching plugin and a cookie banner. This guide covers how the Hay.chat chat widget behaves with the common ones, and what to change if something looks wrong.

Read this first: none of the plugins below has been tested with Hay.chat yet. Every section is marked "Not yet tested". The advice comes from how the widget loads and from each plugin's own documentation. When we have tested a plugin on a real site, we'll mark it here with the date and the version. If you hit a problem before then, write to us and tell us which plugin and which setting.

How the widget loads#

The plugin adds two things to each page where the widget is on: a short inline script with your settings (window.HayChat.config) and widget.js from your Hay.chat server (https://eu.hay.chat unless you self-host). From plugin version 1.0.1, the script loads deferred in the footer and there is no separate stylesheet to block rendering.

widget.js is small. It draws the chat button, then downloads the rest of the chat once the page has finished loading and the browser is idle, or earlier if the visitor reaches for the button. Nothing is stored on the visitor's device before they send a first message.

Two things follow from this:

  • The inline settings must run before widget.js. Optimisation plugins that keep scripts in order (delaying or deferring them all together) are fine. Plugins that move or merge only some of them can break the widget.
  • Your caching plugin can cache the page as usual. The widget's settings are the same for every visitor, and each visitor's chat is loaded from Hay.chat, not from your page.

Hide the widget on some pages (plugin 1.1.0)#

Version 1.1.0 of the plugin adds a Hide on section to its settings page: Cart, Checkout, My account, and a list of other paths (one per line, * matches anything, so /members/* hides it under /members/). All of them are off by default.

The rule is checked on your server when WordPress builds the page. With a page cache, each URL is cached with or without the widget, which is what you want. WooCommerce already tells caching plugins not to cache the cart, checkout and account pages.

Caching and optimisation plugins#

WP Rocket: Not yet tested#

WP Rocket's Delay JavaScript execution holds every script back until the visitor moves the mouse, scrolls, taps or presses a key. The Hay.chat settings script and widget.js stay in order, so the widget should simply appear on the first interaction. This is the setup we recommend if page speed scores matter most to you.

If you want the button visible as soon as the page loads, exclude the widget from the delay: in WP Rocket, go to File Optimization → Delay JavaScript execution → Excluded JavaScript Files and add these two lines:

/v1/webchat/widget.js
HayChat

The first matches the widget script, the second the inline settings. WP Rocket also skips any script tag that carries a nowprocket attribute. The plugin doesn't add it, so use the exclusion list above.

LiteSpeed Cache: Not yet tested#

Page caching needs no change. Under Page Optimization → JS Settings, Load JS Deferred set to Deferred should be fine. Set to Delayed, it works like WP Rocket's delay: the widget appears on the first interaction. To keep it eager, add widget.js and HayChat to JS Deferred / Delayed Excludes (in the Tuning tab).

If you turn on JS Combine, also add both to JS Excludes, so the settings are not moved away from the script that reads them.

Autoptimize: Not yet tested#

Autoptimize leaves scripts from other domains alone, so widget.js is not touched. Inline scripts are only merged if you switch on Also aggregate inline JS. If you do, add HayChat to Exclude scripts from Autoptimize so the settings stay in place.

The widget stores nothing on the device until the visitor sends a message. After that it keeps the chat for the current tab, so a page change doesn't lose it. To find the same chat on a later visit, it also keeps the conversation in the browser's local storage. By default it does that once the visitor has sent a message, unless your site withdraws consent.

Your site can drive this with two calls:

  • window.HayChat.grantConsent() lets the widget keep the chat between visits.
  • window.HayChat.revokeConsent() deletes what it stored between visits. The chat open in the tab keeps working.

Both work as soon as widget.js has run, before the rest of the chat has loaded. With consent: 'strict' in the widget settings, nothing is kept between visits until grantConsent() is called.

From version 1.1.0, when the WP Consent API plugin is active, the Hay.chat plugin:

  • sets the widget to strict, so nothing is kept between visits until the visitor agrees;
  • calls grantConsent() when the visitor allows the functional category, and revokeConsent() when they withdraw it;
  • registers itself with the WP Consent API, so your consent plugin doesn't list it as unknown.

Keeping the chat between visits is filed under functional, not statistics or marketing: it only serves the visitor's own conversation.

Without the WP Consent API (or before 1.1.0), call the two functions from your consent tool's own events.

Complianz: Not yet tested#

Complianz supports the WP Consent API. Install the WP Consent API plugin next to it and update Hay.chat to 1.1.0. Accepting the Functional category in the Complianz banner should then let the widget keep the chat between visits.

CookieYes: Not yet tested#

CookieYes supports the WP Consent API too. As with Complianz, install the WP Consent API plugin, update Hay.chat to 1.1.0, and check that CookieYes maps its Functional category to the WP Consent API's functional category.

If your tool doesn't support the WP Consent API, call window.HayChat.grantConsent() from its "accepted" event and window.HayChat.revokeConsent() from its "withdrawn" event, for the category that covers functional storage.

What we test next#

For each plugin above, we'll check on a WooCommerce test site that the button shows (or shows on first interaction, when delayed), that a chat opens and survives a page change, and, for the consent plugins, that nothing is kept between visits before consent and that withdrawing consent deletes it. Results will appear here, dated, as "Tested".

Add Hay.chat to your WordPress site

Install the free plugin from wordpress.org and try Hay.chat for 30 days, no credit card needed.

See the WordPress plugin