Code samples

Hide the widget on certain pages

There may be a use case where you want to hide the widget on a certain page. You can simply not load the embed code at all, however this may result in odd situations for your vistors. For example, if a user starts a chat on a page where the widget is loaded and then navigates to a page where the widget is not loaded.

To prevent this situation you should set the render property to false, meaning the widget won't be initialized on page load by default. Next, you should programmatically render the widget (via window.Trengo.Api.Widget.render()) when the current visitor URL does not match a pattern OR when the chat visitor is already chatting.

window.Trengo = window.Trengo || {};
window.Trengo.key = '{key}';
window.Trengo.render = false; // extra

(function(d, script, t) {
  script = d.createElement('script');
  script.type = 'text/javascript';
  script.async = true;
  script.src = 'https://static.widget.trengo.eu/embed.js';
  d.getElementsByTagName('head')[0].appendChild(script);
}(document));

window.Trengo.on_ready = function() {
  if (window.location.pathname.indexOf('/page-without-widget') === -1 || window.Trengo.Api.Widget.is_chatting()) {
    window.Trengo.Api.Widget.render();
  }
}