Drupal
Install the Yaplet chat widget on a Drupal 10 or 11 site with the free Asset Injector module. For site administrators and developers.
Overview
Drupal core has no setting for adding a script to every page. The free contributed module Asset Injector adds one: paste the Yaplet code into a JS injector and the chat widget appears on the whole site. Asset Injector works with Drupal 10.3 and newer, including Drupal 11, and its stable releases are covered by Drupal's security advisory policy.
Installation Steps
Install the Asset Injector module
In your Drupal project on the server, run the Composer command from the module's page:
composer require 'drupal/asset_injector:^2.21'
Then go to Extend, check Asset Injector and click Install. Give the Administer JS Assets permission only to roles you fully trust: anyone who has it can add JavaScript to every page.
Copy your Yaplet code
In your Yaplet dashboard, go to Brand → Chat widget and open the Install tab. If the tab asks where your website runs, choose Other website and switch off Include the <script> and </script> lines. Copy the code with the copy button on the code block.
The code must be plain JavaScript that starts with !function (Yaplet, with no <script> tags around it. If what you copied starts with a <script> line, leave out that first line and the last </script> line. Asset Injector wants the code without these tags and refuses to save it with them.
Add a JS injector
Go to Configuration → Development → Asset Injector → JS Injector and click Add JS Injector.
Type a Label you will recognize later (for example Yaplet chat), paste the code into the Code field, make sure Enabled is checked, leave the conditions empty so the code loads on every page, and click Save.
The advanced options can stay as they are: the chat doesn't need jQuery, and loading the script in the footer (Drupal's default) works fine. With no conditions, the chat also appears on admin pages. To show it only on the public site, set the Current Theme condition to the site's front-end theme.
Check your site
Asset Injector clears Drupal's caches when you save. Open your site in a new browser tab and reload it. The Yaplet chat button appears in the bottom-right corner. Click it to check that the chat opens.
Troubleshooting
- Drupal says there must be no leading or trailing
<script>tags — remove the first<script>line and the last</script>line, so the code starts with!function (Yaplet. - The injector is switched off — edit it, check Enabled and save.
- A condition hides the chat — conditions limit the pages the code loads on. If you set the Current Theme condition, check that it names the theme the public site uses.
- The browser shows an old copy of the page — reload, or open the site in a private window.