Acquia is an enterprise Drupal hosting and digital experience platform. Because Acquia runs Drupal at its core, analytics integration follows Drupal patterns -- but with additional layers for Acquia's CDN (Acquia Cloud Edge/Varnish), Acquia Lift personalization, and Acquia DAM. Understanding how these layers interact with tracking scripts is critical for accurate data collection.
Integration Architecture
Acquia sites use Drupal's module and theme system for analytics integration, but the Acquia platform adds several infrastructure considerations:
- Drupal Modules -- Install contributed modules like
google_tagvia Composer. Managed through Drupal's admin UI at/admin/config/system/google-tag. - Theme Templates -- Add scripts to
html.html.twigor create custom Twig templates in your theme's/templates/directory. - Acquia Lift -- Acquia's built-in personalization engine has its own JavaScript agent that can conflict with or duplicate analytics data collection.
- Acquia Cloud Hooks -- Deploy-time scripts in
/hooks/that can automate configuration changes across environments (dev/stage/prod).
Available Integrations
Analytics Platforms
- Drupal
google_tagmodule (handles GTM container and GA4 config) - Direct gtag.js via theme template (less maintainable)
- Acquia Lift integration for personalization-aware analytics
Tag Management
google_tagDrupal module (admin-configurable, recommended)- Theme-level injection in
html.html.twig - Acquia Cloud environment-specific containers (dev vs prod)
Marketing Pixels
- Via GTM container (recommended)
- Drupal module for server-side Conversions API integration
- Theme template injection for base pixel
Recommended Method: google_tag Module
The google_tag module is the standard approach for Acquia/Drupal sites. Install via Composer in your Acquia Cloud environment:
# In your Acquia Cloud codebase
composer require 'drupal/google_tag:^2.0'
drush en google_tag -y
drush cr
Configure at Admin > Configuration > System > Google Tag Manager (/admin/config/system/google-tag). The module supports:
- Multiple GTM containers (useful for dev/staging/production separation)
- Role-based exclusions (exclude admin users from tracking)
- Path-based conditions (exclude
/admin/*paths) - Environment-specific container IDs using Drupal's configuration split
Data Layer with Drupal/Acquia
Build a data layer using Drupal's hook_page_attachments() in a custom module or use the dataLayer contributed module:
/**
* Implements hook_page_attachments().
*/
function mymodule_page_attachments(array &$attachments) {
$user = \Drupal::currentUser();
$node = \Drupal::routeMatch()->getParameter('node');
$data_layer = [
'userRole' => $user->isAuthenticated() ? 'authenticated' : 'anonymous',
'pageType' => $node ? $node->getType() : 'other',
'language' => \Drupal::languageManager()->getCurrentLanguage()->getId(),
];
if ($node) {
$data_layer['contentTitle'] = $node->getTitle();
$data_layer['contentId'] = $node->id();
}
$attachments['#attached']['html_head'][] = [
[
'#type' => 'html_tag',
'#tag' => 'script',
'#value' => 'window.dataLayer = window.dataLayer || [];
window.dataLayer.push(' . json_encode($data_layer) . ');',
'#weight' => -100,
],
'mymodule_datalayer',
];
}
Platform Limitations
Varnish/CDN caching. Acquia Cloud uses Varnish caching by default. Pages served from Varnish cache will have identical HTML, including any server-rendered data layer values. If your data layer includes user-specific data (role, session ID), those values will be cached and served to all users. Use client-side JavaScript to populate user-specific data layer variables, or configure Varnish to vary on relevant cookies.
Acquia Lift conflicts. If Acquia Lift is enabled, its JavaScript agent (/acquia_lift/acquia_lift.js) fires its own page view and event tracking. This can create duplicate analytics events if GA4 is also configured. Coordinate Acquia Lift decision events with your GTM configuration to avoid double-counting.
Configuration management across environments. Acquia uses Drupal's config split system. The GTM container ID in development (GTM-DEV) should differ from production (GTM-PROD). Use config split or environment-specific settings in settings.php:
// sites/default/settings.php
if (isset($_ENV['AH_SITE_ENVIRONMENT'])) {
switch ($_ENV['AH_SITE_ENVIRONMENT']) {
case 'prod':
$config['google_tag.container.primary']['container_id'] = 'GTM-PROD';
break;
default:
$config['google_tag.container.primary']['container_id'] = 'GTM-DEV';
}
}
Module update cadence. Acquia locks Drupal core and contrib module updates behind their testing pipeline. Security updates are fast, but feature updates to analytics modules may lag behind drupal.org releases by days or weeks.
Performance Considerations
- Acquia Cloud Edge CDN. Static assets are served from Acquia's CDN. Third-party tracking scripts bypass this CDN, adding external DNS lookups. Use GTM's built-in tag sequencing to control load order.
- Drupal's asset aggregation. Enable CSS/JS aggregation at
/admin/config/development/performance. This does not affect inline scripts from thegoogle_tagmodule, but it reduces the total number of HTTP requests competing with tracking scripts. - Server-side rendering cost.
hook_page_attachments()runs on every uncached page request. Keep data layer logic lightweight to avoid adding latency to Drupal's render pipeline. - Acquia Search and tracking. If using Acquia Search (Solr), search result pages may have different caching behavior. Ensure search tracking events fire correctly on both cached and uncached search results.
Recommended Integration Priority
- Install
google_tagmodule -- Configure GTM container with environment-specific IDs via config split - Build server-side data layer -- Use
hook_page_attachments()for page-level data, client-side JS for user-specific data - Configure GA4 in GTM -- Map Drupal content types and taxonomy terms to GA4 content groups
- Add Meta Pixel via GTM -- Use GTM's consent mode integration for GDPR compliance
Next Steps
For general integration concepts, see the integrations overview.