Add the Allinaa chatbot to a Drupal website
Written by the Allinaa team · Updated
Drupal sites add site-wide scripts in one of two ways: an edit to the theme's page template, or a small custom module that attaches the script to every page through Drupal's page attachments hook. The first is a one-line change; the second is the developer's way and survives theme updates. The Allinaa assistant is one script tag either way, and nothing else is needed on the server.
Template or module
If you maintain a custom theme or a sub-theme, the template edit is the quickest: the line goes just before the closing body tag of the page-level template. If the site uses a contributed theme that gets updated, a module is safer, because a theme update overwrites edited templates while a module is untouched. Drupal's API documents the hook for this, hook_page_attachments, which lets a module attach assets to every page.
Get your code
The line comes from your Allinaa cabinet. After you sign up at bot.allinaa.com/start and approve the knowledge the wizard drafts from your public pages, step 5 of the wizard shows it, and the Overview keeps it under "Website installation":
<script src="https://bot.allinaa.com/widget.js" data-bot-id="your-bot-id" defer></script>Route 1: the theme template
- In your theme (ideally a sub-theme, so the edit is yours), open the page-level template; for the file name in your theme, check in Drupal's documentation.
- Paste the line just before the closing body tag and save.
- Clear Drupal's cache so the rendered pages pick up the change.
Route 2: a module with hook_page_attachments
- A developer creates a small custom module that defines the Allinaa script as an external library and attaches it on every page in
hook_page_attachments, with your bot id as thedata-bot-idattribute anddeferset. - Enable the module and clear the cache.
There is no Allinaa module on drupal.org today; a site's own small module is the route. If you would rather hand this to your developer, send them the code from your cabinet with these instructions.
Keep it off the administration pages
Attach the script to the front-end theme only. A module can check the active theme or route and skip administration pages; a template edit in the front-end theme never touches the admin theme anyway. The widget also skips addresses with private segments such as /login/ or /admin/ when reading page text, but the button should not be there in the first place.
Check the installation
Open the live site in a private window and look for the button; then click Check my site in your cabinet, which reads the homepage and up to two pages it links to. If the button is there but the check says not found, the pages it read are probably cached or the code sits on pages it did not open; the status turns to installed anyway once the assistant loads on any page of your site.
More on caching and theme updates on the troubleshooting page.
Frequently asked questions
Is there an Allinaa module for Drupal?
Not on drupal.org today. A site's own small module with hook_page_attachments, or a template edit, is the route.
Which route survives theme updates?
The module. An edited template in a contributed theme is overwritten by an update; a sub-theme's template is not.
Do I need to clear the cache?
Yes, after either route.
Should the script run on admin pages?
No. Attach it in the front-end theme only, or let the module skip administration routes.