Looking to enhance your Drupal site with live chat? Chatway makes it easy to connect with visitors in real time, improving engagement and customer support. In this guide, we’ll show you how to integrate Chatway into your Drupal site using a custom module. Whether you’re a developer or a site owner, this step-by-step tutorial will ensure a smooth setup, so you can start chatting with your visitors right away.
We will add the Chatway script by creating a custom module. It is the easiest way and considered the best practice as there is no need to modify the core Drupal files.
Let’s start!
Step #1: Copy your Chatway unique identifier from your Chatway installation page.

Step #2: Using SSH, navigate to your custom modules directory (If the custom
folder doesn’t exist, create it).
cd modules/custom
Step #3: Create a new folder for the Chatway module.
mkdir chatway_integration
Step #4: Create the Chatway Module info file chatway_integration.info.yml and add the following content:
name: 'Chatway Integration'
type: module
description: 'Adds Chatway live chat script to the site.'
core_version_requirement: ^10 || ^11
package: Custom
dependencies: []
Step #5: Edit the code below and replace xxxxxxxxxxxx with the Chatway unique identifier you copied from Step #1. Then create the Chatway Module code file chatway_integration.module and add your updated content.
<?php
use Drupal\Core\Session\AccountInterface;
/**
* Implements hook_preprocess_HOOK() for HTML document templates.
*/
function chatway_integration_preprocess_html(array &$variables) {
$current_user = \Drupal::currentUser();
// Load Chatway only for non-admin users
if (!$current_user->hasPermission('administer site configuration')) {
$variables['#attached']['html_head'][] = [
[
'#type' => 'html_tag',
'#tag' => 'script',
'#attributes' => [
'id' => 'chatway',
'src' => 'https://cdn.chatway.app/widget.js?id=xxxxxxxxxxxx',
'async' => 'true',
],
],
'chatway_script',
];
}
}
Step #6: Log in to your Drupal admin panel to activate the Chatway module.

Step #7: Tick the checkbox for Chatway Integration and click Install.

Once installed, check your website and the Chatway widget should show right away. Please see below on how it looks depending on your customizations.
When the chat window is closed and preview text bubble is enabled

Chat window open
