Acquia is an enterprise Drupal hosting platform with multiple caching layers (Varnish, Memcached, Drupal page cache) and its own CDN. Analytics issues on Acquia almost always trace back to aggressive caching, Content Security Policy headers from Acquia Shield, or Drupal module conflicts during deployment.
Acquia-Specific Debugging Approach
Acquia's architecture means your analytics snippet passes through three caching layers before reaching a visitor. The most effective debugging workflow starts from the edge and works inward.
Check Varnish Cache Status First
Before debugging JavaScript, confirm your pages are actually serving fresh HTML with the tracking code:
# Check Varnish headers on a specific page
curl -sI https://your-site.acquia.com/ | grep -iE "x-cache|age|x-varnish|x-acquia"
# X-Cache: HIT means Varnish served a cached copy
# Age: 3600 means the page is 1 hour old
# If Age is very high and your tracking code was recently added, the cache is stale
Verify Through Acquia Cloud UI
- Log into Acquia Cloud Console > Environments > select your environment
- Go to Logs > Varnish to see cache hit/miss ratios
- Check Performance > Caching to confirm cache lifetimes
- If Varnish hit rate is 95%+, most visitors never trigger Drupal — your tracking code must be in the cached response
Drush-Based Diagnostics
# SSH into Acquia environment
ssh site.env@server.acquia.com
# Check if your analytics module is active
drush pm:list --status=enabled | grep -i "analytics\|gtm\|tag"
# Clear all Drupal caches (does NOT clear Varnish)
drush cr
# Check for conflicting modules
drush pm:list --status=enabled | grep -i "advagg\|js_optimizer\|asset"
Most Common Acquia Analytics Issues
1. Varnish Serving Stale HTML Without Tracking Code
Symptoms: Analytics tag visible in Drupal admin preview but not on the live site. View-source shows old HTML.
Root cause: Acquia Varnish caches full HTML responses. After adding a tracking snippet via a Drupal module or theme, the Varnish cache still serves the old version.
Fix:
# Purge Varnish cache via Acquia CLI
acli api:environments:domain-clear-varnish [env-id] [domain]
# Or purge all via Acquia Cloud UI:
# Cloud Console > Environments > [env] > Clear Caches > Varnish
Prevention: Set cache tags on your analytics block so Drupal's purge module invalidates Varnish automatically.
2. Acquia CDN Stripping or Rewriting Script Tags
Symptoms: Tracking code present in origin HTML but missing or malformed when served through Acquia CDN.
Diagnosis:
# Compare origin vs CDN response
curl -s https://your-site.acquia.com/ | grep "gtag\|gtm\|analytics" > origin.txt
curl -s https://your-site.com/ | grep "gtag\|gtm\|analytics" > cdn.txt
diff origin.txt cdn.txt
Fix: Check Acquia CDN settings for HTML minification or optimization that may be rewriting inline scripts. Disable "JavaScript optimization" at the CDN level if it conflicts.
3. Content Security Policy from Acquia Shield
Symptoms: Console errors like Refused to load the script 'https://www.googletagmanager.com/...' because it violates the Content-Security-Policy.
Fix: Update the CSP headers in your Acquia Shield configuration:
// In settings.php or via Acquia Shield configuration
// Add required analytics domains to script-src
$config['shield.settings']['script_src'] = "script-src 'self' 'unsafe-inline' https://www.googletagmanager.com https://www.google-analytics.com https://connect.facebook.net";
4. AdvAgg Module Breaking Tag Manager
Symptoms: GTM container loads but triggers fail. Console shows Uncaught TypeError in aggregated JS bundles.
Diagnosis: Acquia recommends the AdvAgg (Advanced CSS/JS Aggregation) module for performance, but it can mangle GTM's inline scripts.
Fix:
// In your theme's .info.yml or via hook
// Exclude GTM scripts from AdvAgg processing
function mytheme_advagg_js_alter(&$js) {
foreach ($js as $key => &$value) {
if (strpos($key, 'googletagmanager') !== false) {
$value['preprocess'] = FALSE;
}
}
}
5. Acquia Content Hub Duplicating Pageviews
Symptoms: Pageview counts are 2x expected on sites using Acquia Content Hub for multi-site content syndication.
Root cause: Content Hub's webhook-triggered content sync can fire preview renders that execute analytics code.
Fix: Wrap your analytics initialization in an environment check:
// Only fire analytics on production Acquia environment
if (!window.location.hostname.includes('.acquia.com') &&
!document.querySelector('meta[name="acquia-content-hub-preview"]')) {
// Initialize analytics here
}
Environment Considerations
- Acquia Dev/Stage/Prod: Each environment has separate Varnish instances. A tag working on Dev may not appear on Prod until Varnish is purged there specifically
- Acquia Cloud IDE: Testing in Cloud IDE uses a different URL structure — analytics filters may exclude it unintentionally
- Memcached: Drupal's render cache in Memcached is separate from Varnish. You may need to clear both (
drush cr+ Varnish purge) - Acquia Search (Solr): Search result pages are often excluded from Varnish cache, so tracking may work on search pages but not cached landing pages
Performance Issues
Slow page loads and degraded Core Web Vitals on Acquia sites often stem from the interaction between Drupal's render pipeline and Acquia's caching layers.
- LCP Issues - Large Contentful Paint problems specific to Acquia's Varnish + CDN stack
- CLS Issues - Layout shift from lazy-loaded Drupal blocks and deferred analytics scripts
Tracking Issues
- Events Not Firing - Debug analytics events lost to Varnish caching, module conflicts, or CSP blocks
Related Resources
- Acquia Cloud caching documentation
- Global Issues Hub for platform-agnostic solutions