Drupal Integration Guide

Complete guide to integrate CallMeBack with Drupal

Setup time: 10-15 minutes
Difficulty: Intermediate
Compatible versions: Drupal 8.x, 9.x, 10.x

Integrate CallMeBack with your Drupal website to capture leads from contact forms, webforms, and custom forms. Drupal powers over 1 million websites worldwide and offers powerful content management capabilities.

Prerequisites

  • A CallMeBack account - Sign up here
  • Your CallMeBack integration code from your dashboard
  • Drupal admin access (Administrator role)
  • Drupal 8.x, 9.x, or 10.x installation
  • Basic understanding of Drupal modules (for custom module method)

Integration Methods

Custom Module

15 minutes Intermediate

Create a custom Drupal module for CallMeBack integration. This is the most maintainable and Drupal-friendly approach.

1

Create Module Directory

Set up the basic module structure in your Drupal installation.
  1. Navigate to /modules/custom in your Drupal root directory
  2. Create a new directory called callmeback_integration
  3. Create the module info file callmeback_integration.info.yml
name: 'CallMeBack Integration'
type: module
description: 'Integrates CallMeBack lead capture widget with Drupal'
package: Custom
core_version_requirement: ^8 || ^9 || ^10
version: '1.0.0'
dependencies:
  - drupal:system
Important Note
The info.yml file defines your module and its dependencies. Make sure indentation is correct as YAML is sensitive to spacing.
2

Create Module Files

Add the main module files to handle CallMeBack integration.
  1. Create callmeback_integration.module file
  2. Create callmeback_integration.libraries.yml file
  3. Create js/callmeback.js file in your module directory
<?php

/**
 * @file
 * CallMeBack Integration module.
 */

use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function callmeback_integration_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.callmeback_integration':
      return '<p>' . t('CallMeBack integration for capturing leads.') . '</p>';
  }
}

/**
 * Implements hook_page_attachments().
 */
function callmeback_integration_page_attachments(array &$attachments) {
  $attachments['#attached']['library'][] = 'callmeback_integration/callmeback';
}
Important Note
The hook_page_attachments() function ensures the CallMeBack script loads on every page.
3

Create Library Definition

Define the JavaScript library that will load CallMeBack on your site.
callmeback:
  js:
    js/callmeback.js: {}
  dependencies:
    - core/drupal
    - core/jquery
Important Note
Libraries in Drupal handle JavaScript and CSS loading efficiently. This ensures proper loading order and caching.
4

Add JavaScript File

Create the JavaScript file that initializes CallMeBack.
(function ($, Drupal, drupalSettings) {
  'use strict';

  Drupal.behaviors.callmebackIntegration = {
    attach: function (context, settings) {
      // Use once() to ensure the script only runs once per element
      $(context).find('body').once('callmeback').each(function() {
        // Load CallMeBack script dynamically
        var script = document.createElement('script');
        script.src = 'https://widget.callmebackbutton.com/widget.js';
        script.setAttribute('data-account', 'YOUR_ACCOUNT_ID');
        script.setAttribute('data-drupal', 'true');
        document.head.appendChild(script);
      });
    }
  };

})(jQuery, Drupal, drupalSettings);
Important Note
Replace 'YOUR_ACCOUNT_ID' with your actual CallMeBack account ID. The data-drupal attribute helps optimize for Drupal-specific features.
5

Enable and Test Module

Activate the module and verify the integration works.
  1. Go to Extend in your Drupal admin
  2. Find 'CallMeBack Integration' and check the checkbox
  3. Click Install
  4. Clear cache via Configuration → Performance → Clear all caches
  5. Visit your site to verify the widget appears
Important Note
Always clear cache after enabling new modules. Check browser console for any JavaScript errors.

Troubleshooting

Still having issues?

Can't find the answer you're looking for? Our support team is here to help with your integration.

Contact Support

Next Steps

Configure CallMeBack

  • Set up your business hours and timezone
  • Configure callback phone numbers
  • Set up email notifications
  • Add team members to your account

Advanced Features

  • Set up custom form templates
  • Configure lead scoring rules
  • Integrate with your CRM
  • Set up automated workflows

Need Help?

Our support team is here to help you with your integration.

Contact Support
Cookie Policy %>