AB Paragraphs - Changelog

Performance Optimization for Suggestions

Problem

Tracking code suggestions were regenerating on every content change, causing noticeable lag during editing.

Optimizations Implemented

  1. Content Caching with Hash Comparison
    • Added simpleHash() function to compute content fingerprints
    • Skips regeneration when content hash matches cached value
    • Separate cache for variant A and B
  2. Debounce Delay Increased – Changed from 300ms to 500ms to reduce rapid recalculations
  3. Delayed Loader Display – Loader only shows after 150ms delay (prevents flash for fast operations)
  4. requestAnimationFrame Usage – Prevents blocking the main UI thread during suggestion rendering
  5. Event Delegation – Single click handler per container instead of per-button (reduces memory usage and improves responsiveness)
  6. User Feedback – Copy button shows β€œCopied!” confirmation for 1.5 seconds

Files Modified

  • js/trackingcode_suggestions.js – Performance optimizations

Loading Indicator for Suggestions

Changes

  • Added loading throbber when tracking code suggestions are being generated
  • Shows "Loading suggestions..." text with animated spinner
  • Improves UX by indicating that processing is happening

Files Modified

  • js/trackingcode_suggestions.js – Added showLoader() function
  • css/trackingcode_suggestions.css – Added throbber animation styles

Best Practices Fix

PHP Code Quality Improvements

AbParagraphsSettingsForm.php

  • Added dependency injection for ConfigFactoryInterface and ModuleHandlerInterface
  • Added create() method for proper service container integration
  • Added return type hints to all methods (: string, : array, : void, : static)
  • Added proper use statements for Url class
  • Removed unused $descriptions variable

ab_paragraphs.module

  • Added proper use statements (FieldConfig, Paragraph)
  • Added return type hints to all functions
  • Improved early return pattern in ab_paragraphs_preprocess_paragraph()
  • Simplified ab_paragraphs_form_alter() with early returns
  • Removed unused $key parameter in array_walk_recursive callback

ab_paragraphs.install

  • Added file-level docblock
  • Added return type hints (: void)
  • Translated Dutch comments to English
  • Added proper use statements
  • Improved code structure with early returns

JavaScript Improvements

ab_test.js

  • Removed all eval() usage (security improvement)
  • Replaced hardcoded console.log with debug mode flag (drupalSettings.abParagraphsSettings.debug)
  • Removed all emoji characters from output
  • Removed unused logAbEvent() function
  • Added 'use strict'; directive
  • Added proper JSDoc documentation for all functions
  • Added drupalSettings to IIFE parameters
  • Improved optional chaining compatibility for older browsers

trackingcode_suggestions.js

  • Added file-level @file docblock
  • Removed all console.log statements
  • Removed all emoji characters
  • Extracted generateTrackingCode() function for cleaner code
  • Added 'use strict'; directive
  • Added proper JSDoc documentation
  • Used Drupal.checkPlain() for XSS protection in suggestions output
  • Added drupalSettings to IIFE parameters

YAML/Configuration Improvements

ab_paragraphs.routing.yml

  • Translated Dutch _title to English ("A/B Paragraphs Settings")

config/schema/ab_paragraphs.schema.yml (NEW)

  • Added configuration schema for settings validation

CSS Improvements

trackingcode_suggestions.css

  • Added file-level docblock
  • Updated class names to match JavaScript
  • Improved flexbox layout for suggestions

Files Modified

  • src/Form/AbParagraphsSettingsForm.php
  • ab_paragraphs.module
  • ab_paragraphs.install
  • ab_paragraphs.routing.yml
  • js/ab_test.js
  • js/trackingcode_suggestions.js
  • css/trackingcode_suggestions.css

Files Added

  • config/schema/ab_paragraphs.schema.yml

Caching Fix

Problem

The module was using max-age = 0 and session cache context, which disabled page caching and caused server load.

Root Cause Analysis

  • Variant selection happens client-side via JavaScript
  • Both variants are always rendered server-side
  • JavaScript determines which variant to show/hide
  • The server output is deterministic and cacheable

Solution

Removed cache restrictions:


// Before
$variables['#cache']['max-age'] = 0;
$variables['#cache']['contexts'][] = 'session';

// After
// Add cache tag for invalidation on content changes only
$variables['#cache']['tags'][] = 'paragraph:' . $paragraph->id();
  

Benefits

  • Full page caching now works
  • Varnish/CDN can cache pages with A/B tests
  • Reduced server load
  • Cache invalidates correctly when paragraph content changes

Render Refactor - Fix Images and Background Colors

Issues Addressed

  1. Images not displayed in nested paragraphs
  2. Background colors not preserved
  3. Links in running text not getting tracking code

Technical Changes


// Before (problematic)
$html_a = \Drupal::service('renderer')->render($views_a);
$processed_html_a = ab_paragraphs_process_links($html_a, $tracking_code_a);
'#markup' => \Drupal\Core\Render\Markup::create($processed_html_a),

// After (fixed)
$render_a = [];
foreach ($ref_a as $entity) {
  $render_a[] = $builder->view($entity, 'default');
}
'content' => $render_a,
'data-tracking-code' => $tracking_code_a,
  

Benefits

  • Lazy loading works correctly
  • Responsive images preserved
  • Background colors preserved
  • All Drupal behaviors work
  • Event delegation tracks all links

Added Piwik Pro Support

Changes

  1. Added Piwik Pro as analytics provider option
  2. Settings form shows Matomo, Piwik Pro, and Google Analytics
  3. URL automatically retrieved from module configuration
  4. Multi-provider tracking support:
    • _paq (Matomo/Piwik Pro)
    • ppms (Piwik Pro Tag Manager)
    • gtag (Google Analytics)

Files Modified

  • src/Form/AbParagraphsSettingsForm.php
  • ab_paragraphs.module
  • js/ab_test.js
  • js/trackingcode_suggestions.js
VCS Label
1.0.0-beta1
Release type
Short description
Numerous fixes and enhancements
Packaged Git sha1
82322744fb567635591ecff5a49d09b2a9dd1e66
Release files